Thanos K - aka DJ Art
a humble webspace about linux and technology
system-backup
Bash Script for updating a Slackware-current box
#!/bin/bash
VERSION=0.60
PWD=`pwd`
EXTRAPWD=$PWD/extra
CHANGELOG=ChangeLog.txt
CHECKSUM=CHECKSUMS.md5
PACKAGES=packages.txt
EXTRAPAC=packs-extra.txt
COMPLETED=completed.txt
COMPLEXTR=compl-extra.txt
BLACKLIST=blacklist
PASTURE=pasture
log=log.txt
FTPPATH=ftp://ftp.slackware.at/slackware-current
TGZPATH=ftp://ftp.slackware.at/slackware-current/slackware
ALTFTPPATH=ftp://ftp.ntua.gr/pub/linux/slackware/slackware-current
ALTTGZPATH=ftp://ftp.ntua.gr/pub/linux/slackware/slackware-current/slackware
until [ -z "$1" ]
do
if [ $1 == "-c" -o $1 == "--changelog" ]; then
GETCHANGELOG=1
fi
if [ $1 == "-e" -o $1 == "--extra" ]; then
GETEXTRAPACKAGES=1
fi
if [ $1 == "-g" -o $1 == "--getpackages" ]; then
GETPACKAGES=1
fi
if [ $1 == "-h" -o $1 == "--help" ]; then
SHOWHELP=1
fi
if [ $1 == "-l" ]; then
LIMIT="--limit-rate=$2"
shift
fi
if [ $1 == "-t" -o $1 == "--alt" ]; then
FTPPATH=$ALTFTPPATH
TGZPATH=$ALTTGZPATH
fi
if [ $1 == "-v" -o $1 == "--version" ]; then
echo "$0 version: $VERSION"
exit 0
fi
if [ $1 == "-a" -o $1 == "--all" ]; then
GETASTERISK=1
fi
shift
done
if [ -n "$SHOWHELP" ]; then
echo "Usage: $0 [options]"
echo "Options:"
echo " -a --all Parse the Changelog.txt even for *.tgz entries"
echo " -c --changelog Download the newest ChangeLog.txt and CHECKSUMS.md5 for -current branch"
echo " -e --extra Download the fresh extra Slackware-current Packages"
echo " -g --getpackages Download the fresh Slackware-current Packages"
echo " -h --help Display this information"
echo " -l <amount> Limit download speed to <amount> bytes/sec"
echo " -t --alt Use Alternative Slackware mirror"
echo " -v --version Display this script's version"
echo
exit 0
fi
# Download the changelog
if [ -n "$GETCHANGELOG" ]; then
echo "Getting" $CHANGELOG "and" $CHECKSUM "..."
wget -N $LIMIT $FTPPATH/$CHANGELOG $FTPPATH/$CHECKSUM
fi
# Generate packages.txt containing all packages
if [ -e $PWD/$CHANGELOG ]; then
echo "Generating" $PACKAGES "..."
grep "^.*/.*tgz" $PWD/$CHANGELOG | grep -v "*" | grep -v "^testing/" | grep -v "^extra/" | grep -v "^pasture/" | grep -v "zipslack" | grep -v "koffice-i18n" | grep -v "kde-i18n" | gawk -F" " '{printf ("%s\n", $1)}' | gawk -F: '{printf ("%s\n", $1)}' | grep "tgz" > $PWD/$PACKAGES
echo "Generating" $EXTRAPAC "..."
grep "^extra/.*tgz" $PWD/$CHANGELOG | grep -v "*" | gawk -F" " '{printf ("%s\n", $1)}' | gawk -F: '{printf ("%s\n", $1)}' | grep "tgz" > $PWD/$EXTRAPAC
if [ -n "$GETASTERISK" ]; then
for j in `grep "*.tgz:" $PWD/$CHANGELOG | gawk -F/ '{print $1}'`
do
wget $TGZPATH/$j/
grep ".tgz" $PWD/index.html |gawk -F\" '{print $2}' |egrep ".tgz$" | gawk -F/ '{print $(NF-1)"/"$NF}' >> $PWD/$PACKAGES
rm -rf $PWD/index.html
done
fi
fi
# Download the packages
if [ -n "$GETPACKAGES" ]; then
echo "Getting packages ..."
CUTDIRS=`echo $TGZPATH | gawk -F/ '{printf ("%s\n", NF-3)}'`
for i in `cat $PWD/$PACKAGES`
do
# get package filename without the leading directory path
pkgname=`echo $i| gawk -F/ '{print $NF}'`
# if this filename exists in our completed list
# then it means that this package is either old and replaced
# or we just downloaded it
if [ -z "`grep $pkgname $PWD/$COMPLETED`" -a -z "`echo $pkgname | grep -f $PWD/$BLACKLIST`" ]; then
txt=`echo $i | sed s/.tgz$/.txt/`
wget -c -r -N -nH --cut-dirs=$CUTDIRS $LIMIT $TGZPATH/$i $TGZPATH/$i.asc $TGZPATH/$txt
echo $pkgname >> $PWD/$COMPLETED
# Now we do the checksum
grep $pkgname $PWD/$CHECKSUM | sed "s/\.\/slackware/\./" | md5sum -c - >> $PWD/$log
grep $txt $PWD/$CHECKSUM | sed "s/\.\/slackware/\./" | md5sum -c - >> $PWD/$log
# Move older duplicate packages to pasture folder
if [ -s $PWD/$i ]; then
# check for pasture folder
if [ ! -d $PWD/$PASTURE ]; then
mkdir $PWD/$PASTURE
fi
# remove version and just keep the only the real package name
realname=`echo $pkgname | gawk -F- '{for (i=1;i<=(NF-3);i++) {printf ($i"-")} printf("\n")}'`
# get package's path
path=`echo $i| gawk -F/ '{print $1}'`
# remove extension
noext=`echo $pkgname | sed s/.tgz$//`
for tobemoved in `ls $PWD/$path | egrep "^$realname[^-]*-[^-]*-[^-]*\.(tgz|txt)" |grep -v $noext `
do
mv -fv $PWD/$path/$tobemoved $PWD/$PASTURE
done
fi
fi
done
fi
# Download the extra packages
if [ -n "$GETEXTRAPACKAGES" ]; then
echo "Getting extra packages ..."
CUTDIRS=`echo $FTPPATH | gawk -F/ '{printf ("%s\n", NF-3)}'`
for i in `cat $PWD/$EXTRAPAC`
do
# get package filename without the leading directory path
pkgname=`echo $i| gawk -F/ '{print $NF}'`
# if this filename exists in our completed list
# then it means that this package is either old and replaced
# or we just downloaded it
if [ -z "`grep $pkgname $PWD/$COMPLEXTR`" -a -z "`echo $pkgname | grep -f $PWD/$BLACKLIST`" ]; then
txt=`echo $i | sed s/.tgz$/.txt/`
echo
echo -n "Download $i ? (y/n/C [mark as complete]): "
read answer
if [ "$answer" = "y" -o "$answer" = "Y" ]; then
wget -c -r -N -nH --cut-dirs=$CUTDIRS $LIMIT $FTPPATH/$i $FTPPATH/$i.asc $FTPPATH/$txt
echo $pkgname >> $PWD/$COMPLEXTR
# Now we do the checksum
grep $pkgname $PWD/$CHECKSUM | sed "s/\.\/slackware/\./" | md5sum -c - >> $PWD/$log
grep $txt $PWD/$CHECKSUM | sed "s/\.\/slackware/\./" | md5sum -c - >> $PWD/$log
elif [ "$answer" = "n" -o "$answer" = "N" ]; then
echo Skipping ...
else
echo $pkgname >> $PWD/$COMPLEXTR
fi
# Move older duplicate packages to pasture folder
if [ -s $PWD/$i ]; then
# check for pasture folder
if [ ! -d $PWD/$PASTURE ]; then
mkdir $PWD/$PASTURE
fi
# remove version and just keep the only the real package name
realname=`echo $pkgname | gawk -F- '{for (i=1;i<=(NF-3);i++) {printf ($i"-")} printf("\n")}'`
# get package's path
path=`echo $i| gawk -F/ '{print $1"/"$2}'`
# remove extension
noext=`echo $pkgname | sed s/.tgz$//`
for tobemoved in `ls $PWD/$path | egrep "^$realname[^-]*-[^-]*-[^-]*\.(tgz|txt)" |grep -v $noext `
do
mv -fv $PWD/$path/$tobemoved $PWD/$PASTURE
done
fi
fi
done
fi
echo "Done!"
exit 0