| 1 | #! /bin/sh |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | ## Make sure we're running as the right user. |
| 6 | case $(id -un) in |
| 7 | mirror) ;; |
| 8 | *) exec userv -fstdin=/dev/null mirror run ;; |
| 9 | esac |
| 10 | |
| 11 | ## Set up a plausible environment. |
| 12 | HOME=/mnt/ftp/mirror-admin; export HOME; cd |
| 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 | |
| 22 | ## Before we start, rotate the logs. (Doing things this way means that we |
| 23 | ## can be sure we don't lose new logs, even if the log rotation goes |
| 24 | ## completely mental. |
| 25 | logrotate -s var/logrotate.state etc/logrotate.conf |
| 26 | |
| 27 | ## Let SIGINT take out the children only. |
| 28 | trap "" INT |
| 29 | |
| 30 | ## Now do the various mirroring things. |
| 31 | for file in $(run-parts --list etc/mirrors.d); do |
| 32 | [ -x "$file" ] || continue |
| 33 | base=${file##*/}; base=${base#[0-9]*-} |
| 34 | ( |
| 35 | echo |
| 36 | echo "***--------------------------------------------------" |
| 37 | echo "*** Running $base at $(date +%Y-%m-%dT%H:%M:%S)" |
| 38 | echo |
| 39 | set +e; (trap - INT; exec "$file"); rc=$?; set -e |
| 40 | echo |
| 41 | echo "*** Finished $(date +%Y-%m-%dT%H:%M:%S); rc = $rc" |
| 42 | ) >>log/$base.log 2>&1 |
| 43 | done |