[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 |
|
---|
[1215] | 9 | if [ -r /etc/dass-it/reposync.conf ]; then
|
---|
| 10 | source /etc/dass-it/reposync.conf
|
---|
[1214] | 11 | fi
|
---|
| 12 |
|
---|
| 13 | usage()
|
---|
| 14 | {
|
---|
| 15 | printf "
|
---|
| 16 | usage: $0 [directory]
|
---|
| 17 |
|
---|
| 18 | $0 will scan all subdirectories for repository (*.repo files),
|
---|
| 19 | download the missing packages,
|
---|
| 20 | recreate a repository
|
---|
| 21 | and sign it.
|
---|
| 22 |
|
---|
| 23 | "
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | check_url()
|
---|
| 27 | {
|
---|
| 28 | local URL="$1"
|
---|
| 29 | [ -z "$1" ] && return 1
|
---|
| 30 | local CODE=`curl --location --write-out %{http_code} --silent --output /dev/null "$URL"`
|
---|
| 31 | printf " %s: %s\n" "$URL" "$CODE"
|
---|
| 32 | test "$CODE" = "200"
|
---|
| 33 | return $?
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | STARTDIR=${1:-.}
|
---|
| 37 |
|
---|
| 38 | if ! [ -d $STARTDIR ]; then
|
---|
| 39 | echo "FAILED: $STARTDIR is not a valid directory"
|
---|
| 40 | usage
|
---|
| 41 | exit 1
|
---|
| 42 | fi
|
---|
| 43 |
|
---|
| 44 | cd $STARTDIR
|
---|
| 45 |
|
---|
| 46 | ME=reposync-mirror-update
|
---|
| 47 | TMPDIR=/tmp/reposync.cache/
|
---|
| 48 |
|
---|
| 49 | REPO_FILES=`find -name "*.repo" ! -name "vermkv-*" | sort`
|
---|
| 50 |
|
---|
| 51 | mkdir -p $TMPDIR
|
---|
| 52 | for REPO_FILE in $REPO_FILES; do
|
---|
| 53 | NAME=`sed --quiet -r 's/^\[(.*)\]/\1/p' $REPO_FILE`
|
---|
| 54 | URL=`sed --quiet -r 's/^baseurl=(.*)/\1/ip' $REPO_FILE`
|
---|
| 55 | DIR=`dirname $REPO_FILE`
|
---|
| 56 |
|
---|
| 57 | echo
|
---|
| 58 | echo
|
---|
| 59 | echo "$ME: $NAME: reposync of $DIR"
|
---|
| 60 | echo
|
---|
| 61 |
|
---|
| 62 | if ! check_url "$URL"; then
|
---|
| 63 | echo " SKIPPED: url not accessable"
|
---|
| 64 | else
|
---|
| 65 |
|
---|
| 66 | # reposync stores in a directory named identical as the name of the repo
|
---|
| 67 | test -L $NAME && rm $NAME
|
---|
| 68 | if test -x $NAME; then
|
---|
| 69 | echo "FAILED: remove $NAME and try again"
|
---|
| 70 | exit 1
|
---|
| 71 | fi
|
---|
| 72 |
|
---|
| 73 | ln -s $DIR $NAME
|
---|
| 74 | CACHEDIR=`mktemp --directory --tmpdir=$TMPDIR`
|
---|
| 75 | if reposync --config $REPO_FILE --cachedir=$CACHEDIR --delete | grep "Downloading\|Removing"; then
|
---|
| 76 |
|
---|
| 77 | test -L $NAME && rm $NAME
|
---|
| 78 |
|
---|
| 79 | echo
|
---|
| 80 | echo "$ME: $NAME: createrepo"
|
---|
| 81 | createrepo --cachedir .repocache/ $DIR
|
---|
| 82 |
|
---|
| 83 | echo
|
---|
| 84 | echo "$ME: $NAME: signing"
|
---|
| 85 | rm -f $DIR/repodata/repomd.xml.asc $DIR/repodata/repomd.xml.key
|
---|
| 86 | if [ "$REPOSYNC_GPG_KEY" -a "$REPOSYNC_GPG_PASSPHRASE" ]; then
|
---|
| 87 | gpg --batch --passphrase "$REPOSYNC_GPG_PASSPHRASE" -a --detach-sign --default-key "$REPOSYNC_GPG_KEY" $DIR/repodata/repomd.xml
|
---|
| 88 | gpg --batch --passphrase "$REPOSYNC_GPG_KEY" -a --export "$REPOSYNC_GPG_KEY" > $DIR/repodata/repomd.xml.key
|
---|
| 89 | fi
|
---|
| 90 | fi
|
---|
| 91 | test -L $NAME && rm $NAME
|
---|
| 92 | sleep 1
|
---|
| 93 |
|
---|
| 94 | fi
|
---|
| 95 |
|
---|
| 96 | done
|
---|
| 97 |
|
---|
| 98 | rm -r $TMPDIR
|
---|
| 99 |
|
---|
| 100 | echo
|
---|
| 101 | echo "$ME: done"
|
---|