source: dass-tools/usr/bin/reposync-mirror-update.sh@ 1269

Last change on this file since 1269 was 1267, checked in by joergs, on Sep 19, 2022 at 5:02:28 PM

Implement fallback from download.opensuse.org to ftp.gwdg.de/pub/opensuse

In some cases, this helps.

  • Property svn:executable set to *
File size: 3.8 KB
RevLine 
[1214]1#!/bin/bash
2
3# because the normal mirroring tools often can't access current data
4# this scripts updates the local repositories using:
5# reposync + createrepo
6
7set -o errexit -o nounset
8
[1228]9REPOSYNC_FAILED=""
10
[1215]11if [ -r /etc/dass-it/reposync.conf ]; then
12 source /etc/dass-it/reposync.conf
[1214]13fi
14
15usage()
16{
17 printf "
18usage: $0 [directory]
19
20 $0 will scan all subdirectories for repository (*.repo files),
21 download the missing packages,
22 recreate a repository
23 and sign it.
24
25"
26}
27
28check_url()
29{
30 local URL="$1"
31 [ -z "$1" ] && return 1
32 local CODE=`curl --location --write-out %{http_code} --silent --output /dev/null "$URL"`
33 printf " %s: %s\n" "$URL" "$CODE"
34 test "$CODE" = "200"
35 return $?
36}
37
38STARTDIR=${1:-.}
39
40if ! [ -d $STARTDIR ]; then
41 echo "FAILED: $STARTDIR is not a valid directory"
42 usage
43 exit 1
44fi
45
46cd $STARTDIR
47
48ME=reposync-mirror-update
49TMPDIR=/tmp/reposync.cache/
[1267]50mkdir -p $TMPDIR
[1214]51
52REPO_FILES=`find -name "*.repo" ! -name "vermkv-*" | sort`
53
54mkdir -p $TMPDIR
55for REPO_FILE in $REPO_FILES; do
56 NAME=`sed --quiet -r 's/^\[(.*)\]/\1/p' $REPO_FILE`
57 URL=`sed --quiet -r 's/^baseurl=(.*)/\1/ip' $REPO_FILE`
58 DIR=`dirname $REPO_FILE`
59
60 echo
61 echo
62 echo "$ME: $NAME: reposync of $DIR"
63 echo
64
65 if ! check_url "$URL"; then
66 echo " SKIPPED: url not accessable"
67 else
68
[1267]69 # reposync stores in a directory named identical as the name of the repo
70 test -L $NAME && rm $NAME
71 if test -x $NAME; then
72 echo "FAILED: remove $NAME and try again"
73 exit 1
74 fi
[1214]75
[1267]76 ln -s $DIR $NAME
77 CACHEDIR=`mktemp --directory --tmpdir=$TMPDIR`
78
79 SYNCED=""
80 # exit on errors
81 if LOG=$(reposync --config $REPO_FILE --cachedir=$CACHEDIR --delete); then
82 SYNCED="$NAME"
83 else
84 printf "FAILED: reposync of %s failed:\n%s\n\n" "$URL" "$LOG" >&2
85 #printf "CACHEDIR=%s\n" "$CACHEDIR"
86 #ls -la "$CACHEDIR"
87 #find ${CACHEDIR}
88
89 CACHEDIR=`mktemp --directory --tmpdir=$TMPDIR`
90 REPO_FILE_FALLBACK="${REPO_FILE}-fallback"
91 sed 's|download.opensuse.org|ftp.gwdg.de/pub/opensuse|' < $REPO_FILE > $REPO_FILE_FALLBACK
92 #sed 's|download.opensuse.org|ftp1.nluug.nl/os/Linux/distr/opensuse|' < $REPO_FILE > $REPO_FILE_FALLBACK
93 URL=`sed --quiet -r 's/^baseurl=(.*)/\1/ip' $REPO_FILE_FALLBACK`
94 printf "Trying fallback %s ...\n" "$URL" >&2
95 LOG=""
96
97 if LOG=$(reposync --config "${REPO_FILE_FALLBACK}" --cachedir=$CACHEDIR); then
98 SYNCED="$NAME"
99 #printf "%s\n" "$LOG"
100 else
101 printf "FAILED: reposync of %s failed:\n%s\n\n" "$URL" "$LOG" >&2
102 REPOSYNC_FAILED="${REPOSYNC_FAILED}${DIR} "
103 fi
104 fi
[1214]105
[1267]106 if [ "$SYNCED" ]; then
107 if grep "Downloading\|Removing" <<< "$LOG"; then
[1228]108
[1267]109 test -L $NAME && rm $NAME
[1228]110
[1267]111 echo
112 echo "$ME: $NAME: createrepo"
113 createrepo --cachedir .repocache/ $DIR
[1214]114
[1267]115 echo
116 echo "$ME: $NAME: signing"
117 rm -f $DIR/repodata/repomd.xml.asc $DIR/repodata/repomd.xml.key
118 if [ "$REPOSYNC_GPG_KEY" -a "$REPOSYNC_GPG_PASSPHRASE" ]; then
119 gpg --batch --passphrase "$REPOSYNC_GPG_PASSPHRASE" -a --detach-sign --default-key "$REPOSYNC_GPG_KEY" $DIR/repodata/repomd.xml
120 gpg --batch --passphrase "$REPOSYNC_GPG_KEY" -a --export "$REPOSYNC_GPG_KEY" > $DIR/repodata/repomd.xml.key
121 fi
122 fi
123 fi
124 test -L $NAME && rm $NAME
125 sleep 1
[1214]126 fi
127done
128
129rm -r $TMPDIR
130
[1228]131printf "\n\n"
132
133if [ "$REPOSYNC_FAILED" ]; then
134 printf "$ME failed on:\n%s\n" "$REPOSYNC_FAILED"
135 exit 1
136fi
137
138printf "$ME: done\n"
Note: See TracBrowser for help on using the repository browser.