update anonftpsync
Hi Everyone,
Consider updating anonftpsync with some selection of the changes
below (the patch is incomplete and untested; don't apply as is).
: ${TO:=}
That (POSIX) assigns the given value for TO unless it's specified in
the environment.
== is not posix; that's a bashtalk for regex.
! [
I think that's also not posix, but it might just be discouraged in
favour of [ ! for increased portability.
--delay-updates --delete-after
I don't know if either of these are strictly necessary. AFAICT think
the 2nd rsync invocation can just use --del.
Justin
--- anonftpsync 2007-09-12 13:25:06.000000000 -0400
+++ anonftpsync1 2008-02-21 10:59:25.000000000 -0500
@@ -19,24 +19,24 @@
# (the dir that holds dists/ and ls-lR).
# (mandatory)
-TO=
+: ${TO:=}
# RSYNC_HOST is the site you have chosen from the mirrors file.
# (http://www.debian.org/mirror/list-full)
# (mandatory)
-RSYNC_HOST=
+: ${RSYNC_HOST:=}
# RSYNC_DIR is the directory given in the "Packages over rsync:" line of
# the mirrors file for the site you have chosen to mirror.
# (mandatory)
-RSYNC_DIR=debian/
+: ${RSYNC_DIR:=debian/}
# LOGDIR is the directory where the logs will be written to
# (mandatory)
-LOGDIR=
+: ${LOGDIR:=}
# ARCH_EXCLUDE can be used to exclude a complete architecture from
# mirrorring. Please use as space seperated list.
@@ -52,7 +52,7 @@
# With a blank ARCH_EXCLUDE you will mirror all available architectures
# (optional)
-ARCH_EXCLUDE=
+: ${ARCH_EXCLUDE:=}
# EXCLUDE is a list of parameters listing patterns that rsync will exclude, in
# addition to the architectures excluded by ARCH_EXCLUDE.
@@ -74,13 +74,13 @@
# architectures excluded by ARCH_EXCLUDE.
# (optional)
-EXCLUDE=
+: ${EXCLUDE:=}
# MAILTO is the address to send logfiles to;
# if it is not defined, no mail will be sent
# (optional)
-MAILTO=
+: ${MAILTO:=}
# LOCK_TIMEOUT is a timeout in minutes. Defaults to 360 (6 hours).
# This program creates a lock to ensure that only one copy
@@ -88,13 +88,14 @@
# Locks held for longer than the timeout are broken, unless
# a running rsync process appears to be connected to $RSYNC_HOST.
-LOCK_TIMEOUT=360
+: ${LOCK_TIMEOUT:=360}
# There should be no need to edit anything below this point, unless there
# are problems.
#-----------------------------------------------------------------------------#
+# XXX: on some systems, environment variables are visible to all users
# If you are accessing a rsync server/module which is password-protected,
# uncomment the following lines (and edit the other file).
@@ -105,13 +106,13 @@
#-----------------------------------------------------------------------------#
# Check for some environment variables
-if [ -z $TO ] || [ -z $RSYNC_HOST ] || [ -z $RSYNC_DIR ] || [ -z $LOGDIR ]; then
- echo "One of the following variables seems to be empty:"
- echo "TO, RSYNC_HOST, RSYNC_DIR or LOGDIR"
- exit 2
-fi
+for a in TO RSYNC_HOST RSYNC_DIR LOGDIR
+do
+ eval : '$'{$a:?}
+done
-if ! [ -d ${TO}/project/trace/ ]; then
+if [ ! -d "${TO}/project/trace" ]
+then
# we are running mirror script for the first time
umask 002
mkdir -p ${TO}/project/trace
@@ -136,7 +137,7 @@
# Exclude architectures defined in $ARCH_EXCLUDE
for ARCH in $ARCH_EXCLUDE; do
- EXCLUDE=$EXCLUDE"\
+ EXCLUDE=$EXCLUDE" \
--exclude binary-$ARCH/ \
--exclude disks-$ARCH/ \
--exclude installer-$ARCH/ \
@@ -146,7 +147,8 @@
--exclude arch-$ARCH.list.gz \
--exclude *_$ARCH.deb \
--exclude *_$ARCH.udeb "
- if [ "$ARCH" == "source" ]; then
+ if [ "$ARCH" = "source" ]
+ then
SOURCE_EXCLUDE="\
--exclude source/ \
--exclude *.tar.gz \
@@ -166,7 +168,8 @@
# Check to see if another sync is in progress
if [ -f "$LOCK" ]; then
# Note: this requires the findutils find; for other finds, adjust as necessary
- if [ "`find $LOCK -maxdepth 1 -amin -$LOCK_TIMEOUT`" = "" ]; then
+ if [ "`find $LOCK -maxdepth 0 -amin -$LOCK_TIMEOUT`" = "" ]
+ then
# Note: this requires the procps ps; for other ps', adjust as necessary
if ps ax | grep '[r]'sync | grep -q $RSYNC_HOST; then
echo "stale lock found, but a rsync is still running, aiee!"
@@ -186,17 +189,17 @@
# specification. If that's the case on your system, try using "0".
trap "rm -f $LOCK" exit
-set +e
-
# First sync /pool
-rsync --recursive --links --hard-links --times --verbose \
- $TMP_EXCLUDE $EXCLUDE $SOURCE_EXCLUDE \
- $RSYNC_HOST::$RSYNC_DIR/pool/ $TO/pool/ >> $LOGFILE 2>&1
-result=$?
+rsync='rsync --recursive --links --hard-links --times --verbose'
+ret=0
+$rsync \
+ $TMP_EXCLUDE $EXCLUDE $SOURCE_EXCLUDE \
+ $RSYNC_HOST::$RSYNC_DIR/pool/ $TO/pool/ >> $LOGFILE 2>&1 || ret=$?
-if [ 0 = $result ]; then
+if [ "$ret" -eq 0 ]
+then
# Now sync the remaining stuff
- rsync --recursive --links --hard-links --times --verbose --delay-updates --delete-after \
+ $rsync --del \
--exclude "Archive-Update-in-Progress-${HOSTNAME}" \
--exclude "project/trace/${HOSTNAME}" \
$TMP_EXCLUDE $EXCLUDE $SOURCE_EXCLUDE \
@@ -208,10 +211,8 @@
echo "mirroring /pool exited with exitcode" $result | tee -a $LOGFILE
fi
-
-if ! [ -z $MAILTO ]; then
+[ -n "$MAILTO" ] &&
mail -s "debian archive synced" $MAILTO < $LOGFILE
-fi
savelog $LOGFILE >/dev/null
Reply to: