]> pd.if.org Git - zpackage/commitdiff
change calls to zpm runscript to zpm script
authorNathan Wagner <nw@hydaspes.if.org>
Sun, 28 Oct 2018 12:47:24 +0000 (12:47 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sat, 3 Nov 2018 12:39:53 +0000 (12:39 +0000)
t/install.t
zpm-add
zpm-getlibs [deleted file]
zpm-uninstall [new file with mode: 0755]

index bd9f2d5b3087f3549942aa16c4aa477525f15948..31fa2657c9492b062935afeb80370a08f66c6d1f 100755 (executable)
@@ -182,7 +182,7 @@ pkgid=third-1.0-1
 PF=$pkgid.zpm
 newpkg $pkgid /bin/echo
 skiponfail 3 "can't create $pkgid" || {
-       zpm setscript -f $PF $pkgid pre-install /bin/true
+       zpm script -s -f $PF -p pre-install $pkgid /bin/true
        okexit "add true pre-install script to $pkgid"
        skiponfail 2 "can't set $pkgid pre-install script" || {
                tryrun zpm install -v -R. -d local.db -f $PF $pkgid
@@ -196,9 +196,9 @@ skiponfail 3 "can't create $pkgid" || {
 #
 pkgid=fourth-1.0-1
 PF=$pkgid.zpm
-newpkg $pkgid /bin/printf
+newpkg $pkgid /bin/head
 skiponfail 3 "can't create $pkgid" || {
-       zpm setscript -f $PF $pkgid pre-install /bin/false
+       zpm script -s -f $PF -p pre-install $pkgid /bin/false
        okexit "add false pre-install script to $pkgid"
        skiponfail 1 "can't set $pkgid pre-install script" || {
                zpm install -R. -d local.db -f $PF $pkgid 2>/dev/null
diff --git a/zpm-add b/zpm-add
index 68c986dbfc05a365a3dadce4c2804296efd683fe..28c12f96fef2cd82f6af30b67e79a227f689b788 100755 (executable)
--- a/zpm-add
+++ b/zpm-add
@@ -34,12 +34,16 @@ tags=
 isconfig=0
 addcontent=1
 complete=0
-mode=
 # option for "multipackage" just to let the system know that's what you meant
 # option to take filenames from stdin
 # parse package, version, release from file if not given
 # TODO -l follow symlinks, -L follow symlinks, adding all, links and targets
-while getopts :f:vr:l:P:S:cu:g:NC opt; do
+# -T set link target
+# -M set mtime
+# -m set mode
+# -H set hash, will be overridden for regular files unless -N is set
+# -F set filetype, regular, symlink, directory
+while getopts :f:vr:l:P:S:cu:g:NCm:M:T:H:F: opt; do
        case $opt in
                N) addcontent=0 ;;
                f) pkgfile="$OPTARG" ;;
@@ -47,9 +51,13 @@ while getopts :f:vr:l:P:S:cu:g:NC opt; do
                S) strip=$(cleanpath "$OPTARG"); ;;
                t) tags="$tags $OPTARG" ;;
                c) isconfig=1 ;;
-               u) username="$OPTARG" ;;
-               g) groupname="$OPTARG" ;;
-               m) mode="$OPTARG" ;;
+               u) cluser="$OPTARG" ;;
+               g) clgroup="$OPTARG" ;;
+               m) clmode="$OPTARG" ;;
+               M) clmtime="$OPTARG" ;;
+               T) cltarget="$OPTARG" ;;
+               F) cltype="$OPTARG" ;;
+               H) clhash="$OPTARG" ;;
                v) verbose=$((verbose + 1)) ;;
                C) complete=1 ;;
                *) echo 'unknown option' $OPTARG; exit 1 ;;
@@ -117,18 +125,13 @@ pkgrel=$(zpm quote "$release")
 #strip=$(cleanpath "$strip")
 for path in $*; do
        #echo adding $path
-       mtime=$(zpm stat -f '%y' $path)
-       uid=$(zpm stat -f '%u' $path)
-       gid=$(zpm stat -f '%g' $path)
 
-       if [ -z "$mode" ]; then
-               mode=$(zpm stat -f '%a' $path)
-       fi
-
-       # only stat the file for the user and group name if not set on the
-       # command line
-       : ${username:=$(zpm stat -f '%U' $path)}
-       : ${groupname:=$(zpm stat -f '%G' $path)}
+       # only stat the file for items not set on the command line
+       mode=${clmode:-$(zpm stat -f '%a' $path)}
+       username=${cluser:-$(zpm stat -f '%U' $path)}
+       groupname=${clgroup:-$(zpm stat -f '%G' $path)}
+       mtime=${clmtime:-$(zpm stat -f '%y' $path)}
+       filetype=${cltype:-$(zpm stat -l -f '%t' "$path")}
 
        rpath="$path"
 
@@ -158,7 +161,6 @@ for path in $*; do
        # ensure all paths are absolute
        rpath=/${rpath#/}
 
-       filetype=$(zpm stat -l -f '%t' "$path")
        hash='NULL'
        target='NULL'
        case "$filetype" in
@@ -170,7 +172,11 @@ for path in $*; do
                                        die "zpm addfile failed ($?): $pkgfile $path" 
                                fi
                        else
-                               hash=$(zpm hash "$path")
+                               if [ -z "$clhash" ]; then
+                                       hash=$(zpm hash "$path")
+                               else
+                                       hash=$clhash
+                               fi
                        fi
                        hash="'$hash'"
                        ;;
@@ -179,8 +185,15 @@ for path in $*; do
                        ;;
                symlink)
                        filetype=l
-                       target=$(readlink $path)
-                       target="'$target'"
+                       if [ -n "$cltarget" ]; then
+                               target=$cltarget
+                       else 
+                               target=$(readlink $path)
+                               target=$(zpm quote -q "$target")
+                       fi
+                       ;;
+               *)
+                       die "filetype $filetype not supported"
                        ;;
        esac
 
diff --git a/zpm-getlibs b/zpm-getlibs
deleted file mode 100755 (executable)
index 1e7fefc..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/bin/sh
-
-# list a files libraries
-
-LD_TRACE_LOADED_OBJECTS=1  /lib/ld-linux-x86-64.so.2 
-
-verbose=0
-all=0
-script=0
-check=0
-
-while getopts avs arg; do
-       case $arg in
-               a) all=1;;
-               v) verbose=1;;
-       c) check=1;;
-       s) script=1;;
-       ?) printf 'usage: zpm-preserve [-av] <pkgname>\n'
-               exit 1
-               ;;
-       esac
-done
-
-pkgname="$1"
-
-pacman -Qlq "$pkgname" | while read file; do
-       if [ ! -f "$file" ]; then continue; fi
-       base=$(basename "$file")
-       if [ $all -eq 0 ] && [ "$base" = "${base#lib}" ]; then continue; fi
-
-       if [ $check -eq 1 ]; then
-               elftype -e "$file"
-               rv=$?
-               if [ $rv -ne 0 ]; then continue; fi
-               for lib in $(zpm getlibs $file | grep preserve); do
-                       echo $pkgname $file $lib
-               done
-               continue
-       fi
-
-       soname=$(soname $file)
-       if [ $? -eq 0 ] && [ -n "$soname" ]; then
-               dir=$(dirname "$file")
-               if [ "$script" -ne 0 ]; then
-                       printf 'mkdir -p "%s"\n' "$dir/preserve"
-                       printf 'ln -f "%s" "%s"\n' "$file" "$dir/preserve/"
-               else
-                       mkdir -p "$dir/preserve"
-                       if [ "$verbose" -gt 0 ]; then
-                               printf '# preserving %s\n' "$file"
-                       fi
-                       ln -f "$file" "$dir/preserve/"
-               fi
-       fi
-done
diff --git a/zpm-uninstall b/zpm-uninstall
new file mode 100755 (executable)
index 0000000..17ce69b
--- /dev/null
@@ -0,0 +1,147 @@
+#!/bin/sh
+
+die() {
+       echo $* 1>&2
+       exit 1
+}
+
+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