]> asedeno.scripts.mit.edu Git - sipb-mirrors.git/blob - fetch
fedora-buffet: exit with status from quick-fedora-mirror
[sipb-mirrors.git] / fetch
1 #!/bin/bash
2
3 set -e
4
5 . ./OPTIONS.sh
6
7 scriptname=$1
8 shift
9
10 if [ -z "$scriptname" ]; then
11     echo "Run with a fetch script as an argument:"
12     (cd fetch-scripts && ls)
13     exit 1
14 fi
15
16 if ! [ -e fetch-scripts/"$scriptname" ]; then
17     echo "Unknown fetch script $scriptname"
18     exit 1
19 fi
20
21 mkdir -p "$MIRRORDIR/.locks"
22
23 # Save a copy of stdout on FD 3, so we can get it back again
24 exec 3>&1
25
26 logname="$MIRRORDIR/.logs/$scriptname-$(date +"%F-%R:%S").log"
27
28 exec >> "$logname" 2>&1
29 date +"Starting $scriptname: %c"
30
31 #NB: -r is number of retries, at 8 second intervals
32 if lockfile -r 900 "$MIRRORDIR/.locks/$scriptname"; then
33     date +"Received lock: %c"
34     (. fetch-scripts/"$scriptname")
35     exitstatus=$?
36     rm -f "$MIRRORDIR/.locks/$scriptname"
37 fi
38
39 date +"Done: %c"
40 if [ $exitstatus -ne 0 ]; then
41     exec 1>&3 # Restore stdout
42     echo "Synchronization of $scriptname failed:"
43     echo "(last 100 lines)"
44     echo
45     tail -n 100 "$logname"
46 fi
47 exit $exitstatus