]> pd.if.org Git - zpackage/commitdiff
add option to simplify uninstalls
authorNathan Wagner <nw@hydaspes.if.org>
Mon, 3 Dec 2018 11:30:32 +0000 (11:30 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 3 Dec 2018 11:30:32 +0000 (11:30 +0000)
zpm-update takes -U to treat unadorned packages listed
as packages to uninstall.  Explicitly tagged packages (with '+')
are still installs, the -U option just adjusts how barewords
are treated.

zpm-uninstall is now a (very) thin wrapper around zpm-update -U

zpm-uninstall
zpm-update

index 17ce69bb29749c3801ff2da71f5724d4e047d858..4b3efa1c81175feb7b6dffe3b840dac414bbd921 100755 (executable)
@@ -1,147 +1,5 @@
 #!/bin/sh
 
-die() {
-       echo $* 1>&2
-       exit 1
-}
+# just a wrapper
 
-dryrun=0
-verbose=0
-runscripts=1
-runconfigure=1
-localdb=/var/lib/zpm/local.db
-absorb=0
-
-# zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
-while getopts f:d:R:nSCvA opt; do
-       case $opt in
-               A) absorb=1 ;;
-               f) pkgfile="$OPTARG" ;;
-               d) localdb="$OPTARG" ;;
-               R) rootdir="$OPTARG" ;;
-               S) runscripts=0 ;;
-               C) runconfigure=0 ;;
-               n) dryrun=1 ;;
-               v) verbose=1 ;;
-               *) die "usage ..." ;;
-       esac
-done
-shift $(( OPTIND - 1))
-
-pkgid=$1
-
-if [ -z "$pkgid" ]; then
-       die "must specify pkgid"
-fi
-
-eval "$(zpm parse -E $pkgid)"
-
-if [ -z "$pkgfile" ]; then
-       pkgfile=$ZPM_PACKAGE_FILE
-fi
-
-# cases C = create ok, R = full package id, F = specified package file
-
-# immediate error
-# C-- 100 error, must specify something
-# --- 000 error, must specify something
-if [ -z "$release" ] && [ -z "$pkgfile" ]; then
-       die must specify package file or complete package id
-fi
-
-# TODO look in package file
-# --F 001 error, wouldn't know which pkgid to create, could derive from file?
-# C-F 101 error, since package wouldn't exist in file to find
-if [ -z "$release" ]; then
-       die must specify complete package id
-fi
-
-# set file from pkgid
-# CR- 110 set file from pkgid, create if needed
-# -R- 010 set file from pkgid, create in file, error if no file
-if [ -z "$pkgfile" ]; then
-       pkgfile="$pkgid.zpm"
-fi
-
-# will now be one of these
-# CRF 111 create package in file given, create file if needed
-# -RF 011 create package in file, error if file doesn't exist
-if [ ! -f "$pkgfile" ]; then
-       if [ $create -eq 1 ]; then
-               zpm init $pkgfile
-       else
-               die $pkgfile does not exist
-       fi
-fi
-
-if [ "$idempotent" = 1 ]; then
-       idempotent='or ignore'
-fi
-
-package=$(zpm quote "$name")
-pkgver=$(zpm quote "$version")
-pkgrel=$(zpm quote "$release")
-
-ZPMDB=$localdb
-export ZPMDB
-
-if [ -z "$ZPMDB" ]; then
-       die "no local db"
-else
-       #echo "localdb = $ZPMDB"
-       true
-fi
-
-zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
-
-# check if we're installing something already
-var=$(zpm list -f $localdb -s installing | wc -l)
-if [ $var -gt 0 ]; then
-       zpm list -v -f $localdb -s installing 
-       die "already ($localdb) installing $var package(s)"
-fi
-
-if [ -n "$rootdir" ]; then
-       ZPM_ROOT_DIR="$rootdir"
-       export ZPM_ROOT_DIR
-fi
-
-for pkgstr in "$@"; do
-       echo removing $pkgstr from $ZPMDB
-       pkgid=$(zpm findpkg -s installed -f $ZPMDB $pkgstr)
-       if [ $? -ne 0 ]; then
-               die "$pkgid is not installed"
-       fi
-
-       eval $(zpm parse -E $pkgid)
-       echo found $name $version $release
-
-       if [ $runscripts -gt 0 ]; then
-               zpm script -r -f $pkgfile -p pre-uninstall $pkgid $current
-               if [ $? -ne 0 ]; then
-                       # TODO log
-                       die "pre-uninstall script for $pkgid failed"
-               fi
-       fi
-
-       zpm pkg $pkgid status=removing
-
-       #zpm shell $ZPMDB 'select * from install_status' 1>&2
-       if [ $dryrun -gt 0 ]; then
-               zpm syncfs -nv
-               zpm pkg $pkgid status=dryrun
-               continue
-       fi
-
-       zpm syncfs
-
-       if [ $? -ne 0 ]; then
-               die 'zpm-pkgfiles failed';
-       fi
-
-       zpm pkg $pkgid status=removed
-
-       if [ $runscripts -gt 0 ]; then
-               zpm script -r -p post-uninstall $pkgid
-       fi
-done
+zpm update -U "$@"
index c85b0edf9fc7e9944015da2659cd6c160008ae5a..44529783408c1c195c4524ae071d53e574c3622a 100755 (executable)
@@ -103,9 +103,12 @@ backup=0
 ignorelibdeps=0
 justlist=0
 
+# treat un-adorned packages as uninstalls
+uninstall=0
+
 # TODO option to attempt to resume an ongoing install
 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
-while getopts f:d:R:nSCvAObBL opt; do
+while getopts f:d:R:nSCvAObBLU opt; do
        case $opt in
                f) pkgfile="$OPTARG" ;;
                d) localdb="$OPTARG" ;;
@@ -122,6 +125,7 @@ while getopts f:d:R:nSCvAObBL opt; do
                B) backup=0 ;;
                L) ignorelibdeps=1 ;;
                l) justlist=1 ;;
+               U) uninstall=1 ;;
                *) die "usage ..." ;;
        esac
 done
@@ -141,8 +145,9 @@ for op in "$@"; do
                -*) pkgid=$(zpm findpkg -I "${op#-}")
                        if [ -n "$pkgid" ]; then
                                to_remove="$to_remove $pkgid"
+                       else
+                               die "$op not installed"
                        fi
-                       # else warn not installed
                        ;;
                +*) pkg=${op#+}
                        search="$search $pkg"
@@ -156,7 +161,17 @@ for op in "$@"; do
                                die "can't find $pkg in $file"
                        fi
                        ;;
-               *) search="$search $op"
+               *)
+                       if [ $uninstall -eq 0 ]; then
+                               search="$search $op"
+                       else
+                               pkgid=$(zpm findpkg -I "${op}")
+                               if [ -n "$pkgid" ]; then
+                                       to_remove="$to_remove $pkgid"
+                               else
+                                       die "$op not installed"
+                               fi
+                       fi
                        ;;
        esac
 done