diff options
-rw-r--r-- | slackupgrade | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/slackupgrade b/slackupgrade index 9be3e98..f00e20b 100644 --- a/slackupgrade +++ b/slackupgrade @@ -411,25 +411,40 @@ function download_all() { if [ $progressbar -eq 1 ]; then s=$(printf "%${width}s" ' '|sed 's/./=/g') printf "\r% 3d%% %s|\n" 100 $s fi } +function abspath() { + local name=$1 + local val + eval val=\$$name + case $val in + /*) ;; + *) local dir=$(dirname $val) + dir=$(cd $dir 2>/dev/null && pwd) || abend "can't canonicalize $val" + val=$dir/$(basename $val) + eval $name=$val + ;; + esac +} + # ########## # Main # ########## -while getopts "ahIknp:qSs:vy" OPTION +while getopts "ahIk:np:qSs:vy" OPTION do case $OPTION in I) opmode=INCR;; S) opmode=SAFE;; a) install_all=y;; h) usage exit 0;; - k) keep_file=$OPTARG;; + k) keep_file=$OPTARG + abspath keep_file;; n) dry_run=y;; p) install_packages="$install_packages $OPTARG";; q) verbosity=q;; v) verbosity=v;; s) install_series="$install_series $OPTARG";; y) assume_y=y;; @@ -448,12 +463,16 @@ case $# in esac if [ $(id -u) != "0" ]; then abend "must be root" fi +if [ -n "$keep_file" ] && [ ! -f "$keep_file" ]; then + abend "keep file \"$keep_file\" doesn't exist or is unreadable" +fi + # Sanity check if [ ! -s /etc/os-release ]; then abend "/etc/os-release doesn't exist" fi . /etc/os-release @@ -593,13 +612,13 @@ if [ -n "$install_packages" ]; then echo $install_packages fi) | sort -u > candidates.$$ # Build a list of packages that should be removed after install comm -2 -3 $installed_list candidates.$$ > remove.list.$$ -if [ -s "$keep_file" ]; then +if [ -n "$keep_file" ] && [ -s "$keep_file" ]; then grep -v '^#' $keep_file | \ tr -s '\n' | sort -u | comm -2 -3 remove.list.$$ - > remove.list rm remove.list.$$ else mv remove.list.$$ remove.list fi |