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
|
#!/bin/sh
# This script updates leafnode installations < 1.6
if [ $# -ne 5 ]
then
echo usage: $0 spooldir libdir lockfile news_user news_group
echo This script should preferentially be called from the Makefile only.
exit 1
fi
SPOOLDIR=$1
LIBDIR=$2
LOCKFILE=$3
SRCDIR=`pwd`
USER=$4
GROUP=$5
if [ `id | cut -c5` -ne 0 ]
then
echo This command must be run as root.
exit 1
fi
if [ ! -d ${SPOOLDIR}/leaf.node ]
then
echo To update your old news installation, you must first run "make install".
exit 1
fi
if [ -f ${LOCKFILE} ]
then
echo Lockfile ${LOCKFILE} exists - re-run \"make update\" later
exit 1;
fi
rm -f ${LOCKFILE}.$$
echo $$ >${LOCKFILE}.$$
hostname >>${LOCKFILE}.$$ || :
ln ${LOCKFILE}.$$ ${LOCKFILE} || { rm -f ${LOCKFILE}.$$ ; exit 1 ; }
rm ${LOCKFILE}.$$
trap "rm ${LOCKFILE}" 0
if [ -f ${LIBDIR}/groupinfo ]
then
if [ -f ${SPOOLDIR}/leaf.node/groupinfo ]
then
echo Re-sorting groupinfo file...
mv ${SPOOLDIR}/leaf.node/groupinfo ${SPOOLDIR}/leaf.node/groupinfo.old
sort -f < ${SPOOLDIR}/leaf.node/groupinfo.old > ${SPOOLDIR}/leaf.node/groupinfo
echo Done.
exit 0;
fi
echo Creating new file for main server ...
server=`awk '{ if ($1 == "server") printf("%s\n", substr($0,index($0,"=")+1)); }' < ${LIBDIR}/config | tr -d ' '`
cd ${SPOOLDIR}/interesting.groups
ls -c1 | xargs -i@@ grep @@\ ${LIBDIR}/groupinfo | \
cut -d\ -f 1,4 > ${SPOOLDIR}/leaf.node/$server
echo Converting groupinfo file ... your old groupinfo file will be in ${SPOOLDIR}/leaf.node/groupinfo.old
awk '{ printf("%s %d %d 0", $1, $2, $3); for (i = 5; i <= NF; i++) printf(" %s", $i); printf("\n"); }' < ${LIBDIR}/groupinfo | sort -f > ${SPOOLDIR}/leaf.node/groupinfo
mv ${SPOOLDIR}/leaf.node/groupinfo ${SPOOLDIR}/leaf.node/groupinfo.old
${SRCDIR}/lsort > ${SPOOLDIR}/leaf.node/groupinfo || { mv ${SPOOLDIR}/leaf.node/groupinfo.old ${SPOOLDIR}/leaf.node/groupinfo ; exit 1 ; }
mv ${LIBDIR}/groupinfo ${SPOOLDIR}/leaf.node/groupinfo.old
echo Moving other files ...
find ${LIBDIR} -type f -not -name 'config*' -exec mv '{}' ${SPOOLDIR}/leaf.node/ \;
chown ${USER}:${GROUP} ${SPOOLDIR}/leaf.node/*
chmod 664 ${SPOOLDIR}/leaf.node/*
echo Done.
exit 0
fi
echo Re-sorting groupinfo file...
mv ${SPOOLDIR}/leaf.node/groupinfo ${SPOOLDIR}/leaf.node/groupinfo.old
${SRCDIR}/lsort > ${SPOOLDIR}/leaf.node/groupinfo || { mv ${SPOOLDIR}/leaf.node/groupinfo.old ${SPOOLDIR}/leaf.node/groupinfo ; exit 1 ; }
echo "Done. If leafnode works fine, remove ${SPOOLDIR}/leaf.node/groupinfo.old"
chown ${USER}:${GROUP} ${SPOOLDIR}/leaf.node/groupinfo
chmod 0664 ${SPOOLDIR}/leaf.node/groupinfo
exit 0
|