-
Notifications
You must be signed in to change notification settings - Fork 1
/
ubuports
executable file
·114 lines (90 loc) · 3.54 KB
/
ubuports
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
#
# ubuports - provides an easy way to sync packages from an Ubuntu
# ports mirror.
#
# Copyright (C) 2009 Jonathan Davies <jpds@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -e
if [ ! -f /etc/ubumirror.conf ]; then
echo "Configuration file /etc/ubumirror.conf not found."
exit 2
fi
. /etc/ubumirror.conf
LOGFILE="$LOGDIR/ubuports.log"
# Log all activity to file.
exec >> $LOGFILE 2>&1
if [ -z "$UBUPOR_DIR" ]; then
echo -n "No Ubuntu ports target directory (UBUPOR_DIR) set in "
echo "/etc/ubumirror.conf."
exit 2
fi
LOCK="${UBUPOR_DIR}/Archive-Update-in-Progress-${HOSTNAME}"
trap 'rm -f $LOCK > /dev/null 2>&1; savelog -c 28 -n $LOGFILE > /dev/null' EXIT
# Get in the right directory and set the umask
cd $HOME
umask 022
echo "$(date -R): Initiating Ubuntu ports mirror operations..."
# Check to see if another sync is in progress
if ! ( set -o noclobber; echo "$$" > "${LOCK}") 2> /dev/null; then
if ! $(kill -0 $(cat ${LOCK}) 2>/dev/null); then
# Process does either not exist or is not owned by us.
echo "$$" > "${LOCK}"
else
echo "$(date -R): Unable to proceed with operations; lock file still exists for PID $(cat ${LOCK})."
exit 1
fi
fi
echo "$(date -R): Lock established for process $(cat $LOCK)."
set +e
echo "$(date -R): Initiating Ubuntu ports pool sync..."
rsync -av --partial --delete --delete-after \
--timeout=$IO_TIMEOUT \
--bwlimit=$SPEED \
--exclude "indices/" --exclude "dists/" \
--exclude "project/trace/${HOSTNAME}" \
--exclude "Archive-Update-in-Progress-${HOSTNAME}" \
$UBUPOR_EXCLUDE \
$UBUPOR_MIRROR $UBUPOR_DIR
if [ $? -ne 0 ]; then
( echo "Ubuntu ports pool sync failed. Please check logs."; \
egrep '^write failed|@ERROR' $LOGFILE ) | mail -s "Ubuntu ports sync failed" $EMAIL
echo "$(date -R): Ubuntu ports pool sync failed."
exit 1
fi
echo "$(date -R): Ubuntu ports pool sync completed."
echo "$(date -R): Initiating Ubuntu ports dists and indices sync..."
rsync -av --timeout=600 --partial --delete --delete-after \
--bwlimit=$SPEED \
--exclude "pool/" \
--exclude "project/trace/${HOSTNAME}" \
--exclude "Archive-Update-in-Progress-${HOSTNAME}" \
$UBUPOR_EXCLUDE \
$UBUPOR_MIRROR $UBUPOR_DIR
if [ $? -ne 0 ]; then
( echo "Ubuntu ports dists and indices sync failed. Please check logs."; \
grep '@ERROR' $LOGFILE ) | mail -s "Ubuntu ports sync failed" $EMAIL
echo "$(date -R): Ubuntu ports dists and indices sync failed."
exit 2
fi
echo "$(date -R): Ubuntu ports dists and indices sync completed."
echo "$(date -R): Removing soft-links from mirror..."
find $UBUPOR_DIR -type l -xtype l | xargs -r rm
echo "$(date -R): Releasing lock file..."
rm -f $LOCK > /dev/null 2>&1
echo "$(date -R): Time-stamping trace file..."
date -u > "${UBUPOR_DIR}/project/trace/${HOSTNAME}"
echo "$(date -R): Ubuntu ports mirror operations completed."