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