ports/net/cvsup-mirror/files/update.sh
John Polstra 7fc792b6a6 Fix two bugs in scripts.
1. If update.sh failed to determine the PREFIX, it didn't realize it
had failed.  This is arguably caused by a shell bug in processing
the statement

    export PREFIX=$(expr $0 : "\(/.*\)/etc/cvsup/update\.sh\$")

This statement always succeeds even if the "expr" command fails.
Moving the "export" to a separate statement makes it work.

2. If the system had no "/home" directory, the pkg-install script
would create it with mode 0700, making ~cvsupin inaccessible to its
owner.  A user ran into this bug when installing cvsup-mirror into a
jail.
2004-08-05 23:37:47 +00:00

75 lines
1.5 KiB
Bash

#! /bin/sh
if ! PREFIX=$(expr $0 : "\(/.*\)/etc/cvsup/update\.sh\$"); then
echo "$0: Cannot determine the PREFIX" >&2
exit 1
fi
export PREFIX
export CVSUP_ARGS="$*"
export PATH=/bin:/usr/bin:${PREFIX}/bin
lock=/var/spool/lock/cvsup.lock
log=/var/log/cvsup.log
num_logs=8
use_gzip=0
if [ ${use_gzip} != 0 ]
then
gz_ext=.gz
fi
# Rotate the log files
umask 22
for i in $(/usr/bin/jot ${num_logs} $((${num_logs}-1)) 0)
do
test -f ${log}.$i${gz_ext} && mv -f ${log}.$i${gz_ext} ${log}.$(($i+1))${gz_ext}
done
test -f ${log} && mv -f ${log} ${log}.0 && [ ${use_gzip} != 0 ] && /usr/bin/gzip -9 ${log}.0
exec >${log} 2>&1
# Do the update
date "+CVSup update begins at %Y-%m-%d %T"
# The rest of this is executed while holding the lock file, to ensure that
# multiple instances won't collide with one another.
lockf -t 0 ${lock} /bin/sh << 'E*O*F'
base=${PREFIX}/etc/cvsup
rundir=/var/tmp
cd ${rundir} || exit
. ${base}/config.sh || exit
colldir=sup.client
startup=${PREFIX}/etc/rc.d
eval chome=~${cuser}
cmd="exec env HOME=${chome} cvsup"
options="-1gL 1 -b ${base} -c ${colldir} ${CVSUP_ARGS}"
umask 2
ok=yes
echo "Updating from ${host}"
su -f -m ${cuser} -c \
"${cmd} ${options} -h ${host} ${base}/supfile" || ok=no
if [ ${ok} = yes ]; then
if [ -f ${base}/.start_server ]; then
if [ -x ${startup}/cvsupd.sh ]; then
echo -n "Starting the server:"
/bin/sh ${startup}/cvsupd.sh start
echo "."
fi
rm -f ${base}/.start_server
fi
fi
E*O*F
date "+CVSup update ends at %Y-%m-%d %T"