[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 |
|
---|
| 7 | set -o errexit -o nounset
|
---|
| 8 |
|
---|
[1228] | 9 | REPOSYNC_FAILED=""
|
---|
| 10 |
|
---|
[1215] | 11 | if [ -r /etc/dass-it/reposync.conf ]; then
|
---|
| 12 | source /etc/dass-it/reposync.conf
|
---|
[1214] | 13 | fi
|
---|
| 14 |
|
---|
| 15 | usage()
|
---|
| 16 | {
|
---|
| 17 | printf "
|
---|
| 18 | usage: $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 |
|
---|
| 28 | check_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 |
|
---|
| 38 | STARTDIR=${1:-.}
|
---|
| 39 |
|
---|
| 40 | if ! [ -d $STARTDIR ]; then
|
---|
| 41 | echo "FAILED: $STARTDIR is not a valid directory"
|
---|
| 42 | usage
|
---|
| 43 | exit 1
|
---|
| 44 | fi
|
---|
| 45 |
|
---|
| 46 | cd $STARTDIR
|
---|
| 47 |
|
---|
| 48 | ME=reposync-mirror-update
|
---|
| 49 | TMPDIR=/tmp/reposync.cache/
|
---|
[1267] | 50 | mkdir -p $TMPDIR
|
---|
[1214] | 51 |
|
---|
| 52 | REPO_FILES=`find -name "*.repo" ! -name "vermkv-*" | sort`
|
---|
| 53 |
|
---|
| 54 | mkdir -p $TMPDIR
|
---|
| 55 | for 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
|
---|
| 127 | done
|
---|
| 128 |
|
---|
| 129 | rm -r $TMPDIR
|
---|
| 130 |
|
---|
[1228] | 131 | printf "\n\n"
|
---|
| 132 |
|
---|
| 133 | if [ "$REPOSYNC_FAILED" ]; then
|
---|
| 134 | printf "$ME failed on:\n%s\n" "$REPOSYNC_FAILED"
|
---|
| 135 | exit 1
|
---|
| 136 | fi
|
---|
| 137 |
|
---|
| 138 | printf "$ME: done\n"
|
---|