#!/bin/sh
# slackware-upgrade-system - full upgrade of a Slackware installation
# Copyright (C) 2019 Sergey Poznyakoff.
#
# Slackware-upgrade-system is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# Slackware-upgrade-system is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with slackware-upgrade-system. If not, see
# .
set -e
# Slackware root directory
rootdir=/root/slackware
# Log file name
logfile=
# 'y', if dry-run mode is requested
dry_run=
# If 'y', don't ask anything, assume "y" as answer to all quieries
assume_y=
# Output verbosity: '' - normal, 'v' - verbose, 'q' - quiet
verbosity=
# If 'y', install all packages
install_all=
# Names of the series that should be installed in addition to already installed
# packages. Ignored, if install_all is set.
install_series=
# Name of the keep-list file.
keep_file=
function usage() {
cat <> $logfile
fi
}
while getopts "ad:hknq:s:vy" OPTION
do
case $OPTION in
a) install_all=y;;
d) rootdir=$OPTARG;;
h) usage
exit 0;;
k) keep_file=$OPTARG;;
n) dry_run=y;;
q) verbosity=q;;
v) verbosity=v;;
s) install_series="$install_series $OPTARG";;
y) assume_y=y;;
*) usage >&2
exit 1
esac
done
shift $(($OPTIND - 1))
if [ $# -gt 0 ]; then
echo >&2 "$0: unexpected arguments"
usage >&2
exit 1
fi
if [ $(id -u) != "0" ]; then
echo >&2 "$0: must be root"
exit 1
fi
# Sanity check
if [ ! -s /etc/os-release ]; then
echo >&2 "$0: /etc/os-release doesn't exist"
exit 1
fi
. /etc/os-release
if [ "$ID" != "slackware" ]; then
echo >&2 "$0: this doesn't seem to be a Slackware installation"
exit 1
fi
# Check if rootdir exists and contains the necessary files and directories
if [ ! -d $rootdir ]; then
echo >&2 "$0: $rootdir does not exist"
exit 1
fi
newversion=$(ls $rootdir/ANNOUNCE.* |\
sed -e 's|.*/||' -e 's/ANNOUNCE\.//' -e 's/_/./g')
if [ -z "$newversion" ]; then
echo >&2 "$0: cannot determine new version"
exit 1
fi
logstem=/var/log/slackware-upgrade-system-$VERSION-$newversion
logfile=$logstem.log
# Check if pkgdir exists and contains the necessary files and directories
pkgdir=$rootdir/slackware64
if [ ! -d $pkgdir ]; then
echo >&2 "$0: $pkgdir does not exist"
exit 1
fi
tmplist=/tmp/$$
cat > $tmplist <&2 "$0: The following required files are missing in $pkgdir:"
echo >&2 "$missing"
exit 1
fi
cat > $tmplist <&2 "$0: The following required directories are missing in $pkgdir:"
echo >&2 "$missing"
exit 1
fi
# Prepare a list of packages that should be removed after install
installed_list=/tmp/installed.list.$$
avail_list=/tmp/avail.list.$$
candidates=
remove_list=$logstem.removed
ls /var/log/packages |\
sed -r -e 's/-[^-]+-(i386|x86(_64)?|arm|noarch|fw)-[[:digit:]]+(_.*)?//' |\
sort > $installed_list
find $pkgdir \
-depth \
-mindepth 2 -maxdepth 2 \
-type f \
-name '*.t?z' | \
grep -v '/kde*/' | \
sed -r \
-e 's|.*/||' \
-e 's/-[^-]+-(i386|x86(_64)?|arm|noarch|fw)-[[:digit:]]+((_.*)?\.t.z)?//' | \
sort > $avail_list
comm -2 -3 $installed_list $avail_list > $remove_list.$$
if [ -s "$keep_file" ]; then
grep -v '^#' $keep_file | \
tr -s '\n' | sort | comm -2 -3 $remove_list.$$ - > $remove_list
rm $remove_list.$$
else
mv $remove_list.$$ $remove_list
fi
if [ -z "$install_all" ]; then
candidates=$(comm -1 -2 $installed_list $avail_list)
fi
rm -f $installed_list $avail_list
# Disable interrupts during critical section
trap '' HUP INT QUIT ABRT
if [ -s $remove_list -a "$verbosity" != 'q' ]; then
(cat <&2 "$0: no such series: $s"
fi
done
else
find . -depth -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort |
while read dir
do
case $dir in
kde*) ;;
*) echo "$0: installing packages from series $dir"
upgrade_package --install-new $dir/*.t?z
;;
esac
done
fi
if [ -s $remove_list ]; then
echo "$0: removing packages"
if [ -n "$dry_run" ]; then
:
elif [ "$verbosity" = 'v' ]; then
removepkg $(cat $remove_list) | tee -a $logfile | grep '^Removing package'
else
removepkg $(cat $remove_list) >> $logfile
fi
echo "$0: see $remove_list for the list of packages that have been removed"
fi
echo "$0: upgrade finished; see $logfile for details"
conffiles=$logstem.conffiles
find /etc /usr/lib*/ /usr/share/vim -name "*.new" 2>/dev/null | \
sort > $conffiles
if [ ! -s "$conffiles" ]; then
rm $conffiles
fi
if [ "$verbosity" != 'q' ]; then
echo "IMPORTANT!"
if [ -s "$conffiles" ]; then
cat <