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

Last change on this file since 1244 was 1228, checked in by joergs, on Dec 5, 2016 at 4:31:09 PM

reposync-mirror-update.sh: continue on error, but show summary at the
end and exit with exitcode.

  • Property svn:executable set to *
File size: 2.6 KB
Line 
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
9REPOSYNC_FAILED=""
10
11if [ -r /etc/dass-it/reposync.conf ]; then
12 source /etc/dass-it/reposync.conf
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/
50
51REPO_FILES=`find -name "*.repo" ! -name "vermkv-*" | sort`
52
53mkdir -p $TMPDIR
54for 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
105done
106
107rm -r $TMPDIR
108
109printf "\n\n"
110
111if [ "$REPOSYNC_FAILED" ]; then
112 printf "$ME failed on:\n%s\n" "$REPOSYNC_FAILED"
113 exit 1
114fi
115
116printf "$ME: done\n"
Note: See TracBrowser for help on using the repository browser.