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