Commit | Line | Data |
---|---|---|
db2c5b8b MW |
1 | #! /bin/sh |
2 | ||
3 | set -e | |
4 | ||
5 | ## Make sure we're running as the right user. | |
fb775fef | 6 | case $(id -un) in |
db2c5b8b | 7 | mirror) ;; |
6a18cc83 | 8 | *) exec sudo -umirror "$0" "$@" ;; |
db2c5b8b MW |
9 | esac |
10 | ||
11 | ## Set up a plausible environment. | |
f7b14ed0 | 12 | HOME=/var/lib/mirror-admin; export HOME; cd |
db2c5b8b MW |
13 | PATH=$HOME/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin |
14 | export PATH | |
15 | umask 002 | |
16 | ||
17 | ## Make sure we're running with a lock file. | |
18 | case "${MIRROR_LOCKED-nil}" in | |
19 | nil) exec env MIRROR_LOCKED=t locking -f var/mirror.lock "$0" "$@" ;; | |
20 | esac | |
21 | ||
93e6eb8e MW |
22 | ## Hack for mad Kerberized NFS. |
23 | if [ -r etc/krb5.keytab ]; then | |
24 | kinit -k -t etc/krb5.keytab mirror | |
25 | fi | |
26 | ||
db2c5b8b MW |
27 | ## Before we start, rotate the logs. (Doing things this way means that we |
28 | ## can be sure we don't lose new logs, even if the log rotation goes | |
29 | ## completely mental. | |
30 | logrotate -s var/logrotate.state etc/logrotate.conf | |
31 | ||
32 | ## Let SIGINT take out the children only. | |
33 | trap "" INT | |
34 | ||
35 | ## Now do the various mirroring things. | |
36 | for file in $(run-parts --list etc/mirrors.d); do | |
37 | [ -x "$file" ] || continue | |
38 | base=${file##*/}; base=${base#[0-9]*-} | |
39 | ( | |
40 | echo | |
41 | echo "***--------------------------------------------------" | |
42 | echo "*** Running $base at $(date +%Y-%m-%dT%H:%M:%S)" | |
43 | echo | |
44 | set +e; (trap - INT; exec "$file"); rc=$?; set -e | |
45 | echo | |
46 | echo "*** Finished $(date +%Y-%m-%dT%H:%M:%S); rc = $rc" | |
47 | ) >>log/$base.log 2>&1 | |
48 | done |