diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | slackupgrade | 102 | ||||
-rw-r--r-- | slackupgrade.8 | 26 |
4 files changed, 105 insertions, 27 deletions
@@ -16,7 +16,7 @@ # <http://www.gnu.org/licenses/>. PACKAGE = slackupgrade -VERSION = 0.2 +VERSION = 1.0 SBINDIR = /sbin MANDIR = /usr/man @@ -73,7 +73,7 @@ number (the version you upgraded to): not always be desirable, and you may reinstall some of them afterward. -/var/log/slackupgrade-<P>-<N>.conffiles +/var/log/slackupgrade-<P>-<N>.new A list of configuration file replacements created during the upgrade. These are configuration files provided by the upgraded packages that are left in the filesystem along with your current file versions. diff --git a/slackupgrade b/slackupgrade index 7296e18..d29d0ad 100644 --- a/slackupgrade +++ b/slackupgrade @@ -39,6 +39,8 @@ install_series= install_packages= # Name of the keep-list file. keep_file= +# Max. count of backup files to keep +max_backup=4 # Internal variables remote= @@ -99,14 +101,16 @@ function getyn() { else local dfl=$1 shift - case "$dfl" in - [yY]) dfl_s=" [Y/n]";; - [nN]) dfl_s=" [y/N]";; - *) dfl_s=""; dlf="";; - esac - - printf "%s$dfl_s? " "$*" - read REPLY </dev/tty + if [ -t 0 ]; then + case "$dfl" in + [yY]) dfl_s=" [Y/n]";; + [nN]) dfl_s=" [y/N]";; + *) dfl_s=""; dlf="";; + esac + + printf "%s$dfl_s? " "$*" + read REPLY </dev/tty + fi case "${REPLY:-$dfl}" in [yY]*) /bin/true;; *) /bin/false;; @@ -114,10 +118,17 @@ function getyn() { fi } +function info() { + echo "$0: $*" + if [ -n "$logfile" ]; then + echo >>$logfile "$0: $(date): $*" + fi +} + function error() { echo >&2 "$0: $*" if [ -n "$logfile" ]; then - echo >$logfile "$0: $*" + echo >>$logfile "$0: $(date): $*" fi } @@ -256,6 +267,45 @@ function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1" } +# backup FILE [DRY_RUN] +# Create a backup copy of FILE, named FILE~ +# Before, rename each file matching the pattern FILE~<N>, where <N> is a +# decimal digit, to FILE~<N+1>. Rename FILE~ to FILE~1. +# +# Second argument, if prresent, enables the dry-run mode +# +function backup() { + local dir=$(dirname $1) + local stem=$(basename $1) + local p + if [ -n "$2" ]; then + p=echo + else + p= + fi + if [ -r "$1" ]; then + if [ -r "$1~" ]; then + find $dir -name "$stem*" -printf '%f\n' |\ + sed -n -r -e 's/(.+)~([[:digit:]]+)$/\2 \1/p' |\ + sort +0 -1 -n -r |\ + while read n stem + do + if [ -n "$max_backup" ] && [ $n -ge $max_backup ]; then + $p rm $dir/${stem}~$n + else + $p mv $dir/${stem}~$n $dir/${stem}~$((n + 1)) + fi + done + $p mv "$1~" "$1~1" + fi + $p mv "$1" "$1~" + fi +} + +# ########## +# Main +# ########## + while getopts "ahknp:qs:vy" OPTION do case $OPTION in @@ -322,7 +372,7 @@ if [ -z "$rooturl" ]; then sed -n -e "/$version_rx/{" -en -ep -e '}' ) if [ -n "$new_version" ]; then rooturl="$mirrors_url/slackware$ARCH-$new_version" - error "info: using $rooturl as distribution top-level URL" + info "using $rooturl as distribution top-level URL" else abend "can't find distribution newer than $VERSION; please supply URL if you have any" fi @@ -347,7 +397,7 @@ if [ -z "$remote" ]; then fi # Check if rooturl contains all we need -error "info: verifying distribution..." +info "verifying distribution" # # Download CHECKSUMS.md5. So far it is the only file that is gpg-checked. @@ -381,9 +431,13 @@ tail +13 $checksums | \ tee $avail_index | awk '{print $1}' | sort > $avail_list # Initialize log file name -logstem=/var/log/slackupgrade-$VERSION-$newversion +logstem=/var/log/slackupgrade-$VERSION-$newversion${dry_run:+.dry_run} logfile=$logstem.log +backup $logfile +info "planning upgrade of Slackware $VERSION to $newversion${dry_run:+ (DRY RUN MODE)}" + remove_report=$logstem.removed +backup $remove_report # Check if pkgdir exists and contains the necessary files and directories for series in $series_names @@ -431,7 +485,7 @@ fi # Create $remove_report and the list of installation candidates. if [ -f "$SLACKUPGRADE_CONFDIR/$VERSION-$newversion.repl" ]; then - error "info: reading $SLACKUPGRADE_CONFDIR/$VERSION-$newversion.repl" + info "reading $SLACKUPGRADE_CONFDIR/$VERSION-$newversion.repl" # Update candidates and save the replacement map in a temporary. awk '{ sub(/#.*$/,""); sub(/[[:space:]]+$/,"") } /\\$/ { sub(/\\$/,""); p = p $0; next } @@ -471,17 +525,19 @@ fi if ! version_gt $newversion $VERSION; then if ! getyn n "Distribution version $newversion is same or lower than current version $VERSION. Downgrade"; then tempdir_remove - echo Exiting + error "upgrade canceled" exit 0 fi fi if ! getyn n "Ready for upgrade from $VERSION to $newversion. Continue"; then tempdir_remove - echo "Exiting" + error "upgrade canceled" exit 0 fi +info "starting upgrade of Slackware $VERSION to $newversion${dry_run:+ (DRY RUN MODE)}" + pkg_names="glibc-solibs pkgtools tar xz findutils" if [ -n "$remote" ]; then # If using the remote repository, add wget and the libraries it @@ -492,7 +548,7 @@ fi pkg_re='^('$(echo "$pkg_names" | sed -r -e 's/ +/|/g')')$' pkg_files= -echo "$0: Downloading essential packages" +info "downloading essential packages" for pkg in $pkg_names do file=$(getfile $(package_file_name $pkg)) @@ -502,7 +558,7 @@ do pkg_files="$pkg_files${pkg_files:+ }$file" done -echo "$0: Installing essential packages" +info "installing essential packages" upgrade_local $pkg_files if [ -n "$remote" ]; then @@ -521,14 +577,14 @@ while read pkg do s=$(basename ${pkg%/*}) if [ "$prev" != "$s" ]; then - echo "$0: installing selected files from series $s" + info "installing selected files from series $s" prev=$s fi upgrade_package $pkg --install-new done if [ -s remove.list ]; then - echo "$0: removing packages" + info "removing packages" if [ -n "$dry_run" ]; then : elif [ "$verbosity" = 'v' ]; then @@ -536,14 +592,15 @@ if [ -s remove.list ]; then else removepkg $(cat remove.list) >> $logfile fi - echo "$0: see $remove_report for the list of packages that have been removed" + info "see $remove_report for the list of packages that have been removed" fi -echo "$0: upgrade finished; see $logfile for details" +info "upgrade finished; see $logfile for details" tempdir_remove -conffiles=$logstem.conffiles +conffiles=$logstem.new +backup $conffiles find /etc /usr/lib*/ /usr/share/vim -name "*.new" 2>/dev/null | \ sort > $conffiles if [ ! -s "$conffiles" ]; then @@ -573,3 +630,4 @@ bootloader has been updated for the new kernel! Good luck! EOF fi + diff --git a/slackupgrade.8 b/slackupgrade.8 index b962db5..724e592 100644 --- a/slackupgrade.8 +++ b/slackupgrade.8 @@ -130,7 +130,7 @@ If any configuration files were created during the upgrade that conflict with the existing files, they will be stored alongside the original files, with the \fB.new\fR extension. The list of these files will be stored in file -\fB/var/log/slackupgrade\-\fIOLD\fB\-\fINEW\fB.conffiles\fR. +\fB/var/log/slackupgrade\-\fIOLD\fB\-\fINEW\fB.new\fR. .SH OPTIONS .TP .B \-a @@ -151,7 +151,7 @@ To obtain initial list of packages that will be removed, run the program with the \fB\-n\fR option. At the end of the run, the list will be stored in file .nh -\fB/var/log/slackupgrade-\fIOLD\fR-\fINEW\fB.removed\fR. +\fB/var/log/slackupgrade-\fIOLD\fR-\fINEW\fB.dry_run.removed\fR. .hy At a pinch (not really recommended), you can move it elsewhere and use as argument to that option. This way all packages will be preserved. @@ -159,6 +159,9 @@ as argument to that option. This way all packages will be preserved. .B \-n Dry-run mode: do nothing, print what would have been done. In spite of the name, the list of packages for removal will still be created. +.sp +In this mode, log files are created with the additional +\fB\.dry_run\fR suffix (see the section \fBFILES\fR). .TP \fB\-p \fIPACKAGE\fR Install additional package. @@ -220,7 +223,7 @@ Replacement map for upgrades from version \fIOLD\fR to \fINEW\fR. Detailed log of operations performed during the upgrade from version \fIOLD\fR to \fINEW\fR. .TP -\fB/var/log/slackupgrade\-\fIOLD\fB\-\fINEW\fB.conffiles\fR +\fB/var/log/slackupgrade\-\fIOLD\fB\-\fINEW\fB.new\fR List of the new incoming config files on your system with the \fB.new\fR extension. You may need to merge them with your actual files, or move them over, or simply remove them. In any case, it is @@ -230,6 +233,23 @@ good idea to carefully consider each of them. The list of packages that were removed from the system. Examine it. You may need to re-install some or all of them from third-party servers or from slackbuilds. +.PP +When running in dry run mode (see the \fB\-n\fR option), names of the +three log files above contain an additional \fB.dry_run\fR suffix: +.TP +\fB/var/log/slackupgrade\-\fIOLD\fB\-\fINEW\fB.dry_run.log\fR +.TP +\fB/var/log/slackupgrade\-\fIOLD\fB\-\fINEW\fB.dry_run.new\fR +.TP +\fB/var/log/slackupgrade-\fIOLD\fR-\fINEW\fB.dry_run.removed\fR +.SS Backups +At the start of each run, existing log files are backed up. The name +of each backup is created by adding a tilde to the end of the log file +name. E.g. \fBslackupgrade-14.1-14.2.log\fR is renamed to +\fBslackupgrade-14.1-14.2.log~\fR. Existing backup copies are renamed +using the following pattern: \fBX~\fR becomes \fBX~1\fR, \fBX~1\fR +becomes \fBX~2\fR and so on. At most five backup copies are kept +(from \fBX~\fR up to \fBX~4\fR). .SH "SEE ALSO" The \fBUPGRADE.TXT\fR document, outlining the procedure as a whole: .nh |