Update new version from upstream
This commit is contained in:
parent
6068802824
commit
c54d26a9f9
1 changed files with 68 additions and 22 deletions
|
@ -1,33 +1,79 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
MOD=$1
|
# Note: this is only an example of how you'd call create-filelist. Edit to fit
|
||||||
[ -z "$MOD" ] && {
|
# your requirements.
|
||||||
echo "usage: $0 <module>"
|
|
||||||
|
# Takes a list of module names. Generates file lists for all of them and them
|
||||||
|
# moves them into place at once. If you are creating hardlinks between rsync
|
||||||
|
# modules, it is required that you update the file lists of both mirrors at the
|
||||||
|
# same time. Otherwise the clients may make separate copies of the files.
|
||||||
|
|
||||||
|
mods=$*
|
||||||
|
|
||||||
|
if [[ -z $mods ]]; then
|
||||||
|
echo "usage: $0 <module> [<module> ...]"
|
||||||
exit 2
|
exit 2
|
||||||
}
|
fi
|
||||||
|
|
||||||
TOPD=/srv/pub/
|
|
||||||
FILELIST=fullfilelist
|
|
||||||
TIMELIST=fullfiletimelist-$MOD
|
|
||||||
LOCKFILE=.lock.$TIMELIST
|
|
||||||
CREATE=/usr/local/bin/create-filelist
|
CREATE=/usr/local/bin/create-filelist
|
||||||
|
|
||||||
|
# A single lockfile for everything we're modifying
|
||||||
|
LOCKFILE=.lock.create-filelist
|
||||||
|
|
||||||
|
# The directory where all of the modules live
|
||||||
|
TOPD=/srv/mirror/pub
|
||||||
|
|
||||||
|
# These strings will be eval'ed later with $mod replaced by its value in
|
||||||
|
# context.
|
||||||
|
FILELIST=fullfilelist
|
||||||
|
TIMELIST='fullfiletimelist-$mod'
|
||||||
|
|
||||||
(
|
(
|
||||||
flock -n 9 || exit 1
|
# We want to wait forever until we can do what we're asked
|
||||||
|
flock -x 9
|
||||||
|
|
||||||
TMPD=$(mktemp -d -t create-filelist.XXXXXXXXXX)
|
# If you don't want to wait forever, try one of the following:
|
||||||
trap "rm -rf $TMPD" EXIT
|
# flock -n 9 || exit 1 - Gives up immediately
|
||||||
cd $TMPD
|
# flock -w 120 9 || exit 1 - Waits 120 seconds and then gives up
|
||||||
|
# Don't change the '9', unless you change the last line of this script.
|
||||||
|
|
||||||
$CREATE -c -s -d $TOPD/$MOD -f $FILELIST -t $TIMELIST
|
tmpd=$(mktemp -d -t create-filelist.XXXXXXXXXX)
|
||||||
if diff -q $FILELIST $TOPD/$MOD/$FILELIST > /dev/null; then
|
trap "rm -rf $tmpd" EXIT
|
||||||
mv $FILELIST $TOPD/$MOD/$FILELIST
|
cd $tmpd
|
||||||
chmod 0644 $TOPD/$MOD/$FILELIST
|
|
||||||
|
# Create all of the filelists
|
||||||
|
for mod in $mods; do
|
||||||
|
$CREATE -c -s -d $TOPD/$mod-f fl-$mod -t tl-$mod
|
||||||
|
done
|
||||||
|
|
||||||
|
# Now diff the file lists and delete the ones which didn't change
|
||||||
|
for mod in $mods; do
|
||||||
|
currentfl=$TOPD/$mod/${FILELIST/'$mod'/$mod}
|
||||||
|
currenttl=$TOPD/$mod/${TIMELIST/'$mod'/$mod}
|
||||||
|
|
||||||
|
# If a file list exsts and doesn't differ from what we just generated,
|
||||||
|
# delete the latter.
|
||||||
|
if [[ -f $currentfl ]] && diff -q fl-$mod $currentfl > /dev/null; then
|
||||||
|
rm -f $fl
|
||||||
fi
|
fi
|
||||||
|
if [[ -f $currenttl ]] && diff -q tl-$mod $currenttl > /dev/null; then
|
||||||
if diff -q $TIMELIST $TOPD/$MOD/$TIMELIST > /dev/null; then
|
rm -f $fl
|
||||||
mv $TIMELIST $TOPD/$MOD/$TIMELIST
|
|
||||||
chmod 0644 $TOPD/$MOD/$TIMELIST
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# And finally, move all of the files which need updating into place
|
||||||
|
for mod in $mods; do
|
||||||
|
currentfl=$TOPD/$mod/${FILELIST/'$mod'/$mod}
|
||||||
|
currenttl=$TOPD/$mod/${TIMELIST/'$mod'/$mod}
|
||||||
|
|
||||||
|
if [[ -f fl-$mod ]]; then
|
||||||
|
chmod 644 fl-$mod
|
||||||
|
cp -p fl-$mod $currentfl
|
||||||
|
fi
|
||||||
|
if [[ -f tl-$mod ]]; then
|
||||||
|
chmod 644 tl-$mod
|
||||||
|
cp -p tl-$mod $currenttl
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
) 9>$LOCKFILE
|
) 9>$LOCKFILE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue