-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathubuntu-mirror.sh
executable file
·67 lines (56 loc) · 2.64 KB
/
ubuntu-mirror.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
## Mirror Synchronization Script /usr/local/bin/ubuntu-mirror-sync.sh
## Version 1.01 Updated 13 Feb 2007 by Peter Noble
## Where do we want to have our files
SYNC_HOME="/limbus/centos/ubuntu"
log="/limbus/centos/logs/ubuntu_sync.log"
UPDATE_FILE=/limbus/centos/status/UBUNTU.LAST_UPDATE
#email to report on out of date
EMAIL="[email protected]"
## Setup the server to mirror
#remote=rsync://archive.ubuntu.com/ubuntu
#remote=rsync://mirrors.rit.edu/ubuntu
remote=rsync://us.archive.ubuntu.com/ubuntu
## Setup the local directory / Our mirror
local=$SYNC_HOME
## Initialize some other variables
complete="false"
failures=0
status=1
pid=$$
echo "`date +%x-%R` - $pid - Started Ubuntu Mirror Sync" > $log
while [[ "$complete" != "true" ]]; do
if [[ $1 == "debug" ]]; then
echo "Working on attempt number $failures"
rsync --progress --recursive --times --links --hard-links --stats --exclude "Packages*" --exclude "Sources*" --exclude "Release*" $remote $local 2>&1 >> $log && \
rsync --progress --recursive --times --links --hard-links --stats --delete --delete-after $remote $local 2>&1 >> $log
status=$?
else
rsync --progress --recursive --times --links --hard-links --stats --exclude "Packages*" --exclude "Sources*" --exclude "Release*" $remote $local 2>&1 >> $log && \
rsync --progress --recursive --times --links --hard-links --stats --delete --delete-after $remote $local 2>&1 >> $log
status=$?
fi
if [[ $status -ne "0" ]]; then
complete="true"
(( failures += 1 ))
#if our rsync failed, log it and email us
logger -p cron.err -t $0 `tail -n 5 $log` #write log to syslog on failure
# Mon Aug 5 2013: This used to search for "ARCHLINUX" instead of "UBUNTU"
OUTOFDATE=`find /limbus/centos/status -mtime -1 -name 'UBUNTU*' | wc -l`
if [ "$OUTOFDATE" -eq 0 ]
then
echo "sync out of date\n";
echo "Warning: Ubuntu mirror out of date by 24 hours, please check logs at http://centos.rutgers.edu/mirror/status " | mail -s "UBUNTU MIRROR 24 Hours out of date" $EMAIL
fi
else
echo "`date +%x-%R` - $pid - Finished Ubuntu Mirror Sync" >> $log
DATENICE=`date \`\`+%a\ -\ %b\ %d,\ %Y\ -\ %H:%M''`
echo $DATENICE > $UPDATE_FILE
#LATEST_REPO_FILE=`find $SYNC_HOME/dists/ -name Packages.gz -print0 | xargs -r -0 ls -t | head -1`
LATEST_REPO_FILE=`ls -t $(find $SYNC_HOME/dists/ -name Packages.gz -print0 | xargs -0 echo) | head -1`
REPODATA_DIR_DATE=`date -r $LATEST_REPO_FILE \`\`+%a\ -\ %b\ %d,\ %Y\ -\ %H:%M''`
echo $REPODATA_DIR_DATE >> $UPDATE_FILE
complete="true"
fi
done
exit 0