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 |
|
---|
9 | REPOSYNC_FAILED=""
|
---|
10 |
|
---|
11 | if [ -r /etc/dass-it/reposync.conf ]; then
|
---|
12 | source /etc/dass-it/reposync.conf
|
---|
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/
|
---|
50 |
|
---|
51 | REPO_FILES=`find -name "*.repo" ! -name "vermkv-*" | sort`
|
---|
52 |
|
---|
53 | mkdir -p $TMPDIR
|
---|
54 | for REPO_FILE in $REPO_FILES; do
|
---|
55 | NAME=`sed --quiet -r 's/^\[(.*)\]/\1/p' $REPO_FILE`
|
---|
56 | URL=`sed --quiet -r 's/^baseurl=(.*)/\1/ip' $REPO_FILE`
|
---|
57 | DIR=`dirname $REPO_FILE`
|
---|
58 |
|
---|
59 | echo
|
---|
60 | echo
|
---|
61 | echo "$ME: $NAME: reposync of $DIR"
|
---|
62 | echo
|
---|
63 |
|
---|
64 | if ! check_url "$URL"; then
|
---|
65 | echo " SKIPPED: url not accessable"
|
---|
66 | else
|
---|
67 |
|
---|
68 | # reposync stores in a directory named identical as the name of the repo
|
---|
69 | test -L $NAME && rm $NAME
|
---|
70 | if test -x $NAME; then
|
---|
71 | echo "FAILED: remove $NAME and try again"
|
---|
72 | exit 1
|
---|
73 | fi
|
---|
74 |
|
---|
75 | ln -s $DIR $NAME
|
---|
76 | CACHEDIR=`mktemp --directory --tmpdir=$TMPDIR`
|
---|
77 |
|
---|
78 | # exit on errors
|
---|
79 | if ! LOG=$(reposync --config $REPO_FILE --cachedir=$CACHEDIR --delete); then
|
---|
80 |
|
---|
81 | printf "FAILED: reposync failed:\n%s" "$LOG" >&2
|
---|
82 | REPOSYNC_FAILED="${REPOSYNC_FAILED}${DIR} "
|
---|
83 |
|
---|
84 | elif grep "Downloading\|Removing" <<< "$LOG"; then
|
---|
85 |
|
---|
86 | test -L $NAME && rm $NAME
|
---|
87 |
|
---|
88 | echo
|
---|
89 | echo "$ME: $NAME: createrepo"
|
---|
90 | createrepo --cachedir .repocache/ $DIR
|
---|
91 |
|
---|
92 | echo
|
---|
93 | echo "$ME: $NAME: signing"
|
---|
94 | rm -f $DIR/repodata/repomd.xml.asc $DIR/repodata/repomd.xml.key
|
---|
95 | if [ "$REPOSYNC_GPG_KEY" -a "$REPOSYNC_GPG_PASSPHRASE" ]; then
|
---|
96 | gpg --batch --passphrase "$REPOSYNC_GPG_PASSPHRASE" -a --detach-sign --default-key "$REPOSYNC_GPG_KEY" $DIR/repodata/repomd.xml
|
---|
97 | gpg --batch --passphrase "$REPOSYNC_GPG_KEY" -a --export "$REPOSYNC_GPG_KEY" > $DIR/repodata/repomd.xml.key
|
---|
98 | fi
|
---|
99 | fi
|
---|
100 | test -L $NAME && rm $NAME
|
---|
101 | sleep 1
|
---|
102 |
|
---|
103 | fi
|
---|
104 |
|
---|
105 | done
|
---|
106 |
|
---|
107 | rm -r $TMPDIR
|
---|
108 |
|
---|
109 | printf "\n\n"
|
---|
110 |
|
---|
111 | if [ "$REPOSYNC_FAILED" ]; then
|
---|
112 | printf "$ME failed on:\n%s\n" "$REPOSYNC_FAILED"
|
---|
113 | exit 1
|
---|
114 | fi
|
---|
115 |
|
---|
116 | printf "$ME: done\n"
|
---|