From: Nathan Wagner Date: Mon, 24 Sep 2018 08:11:45 +0000 (+0000) Subject: add verbose option to add and install X-Git-Tag: v0.1.6~1 X-Git-Url: https://pd.if.org/git/?p=zpackage;a=commitdiff_plain;h=c0c274bfcf9710c279c8438e55f33ebeed3a3f9b add verbose option to add and install --- diff --git a/zpm-add b/zpm-add index 4025bde..5d84d54 100755 --- a/zpm-add +++ b/zpm-add @@ -29,12 +29,13 @@ cleanpath() { printf "%s" "$clean" } +verbose=0 tags= isconfig=0 # 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 -while getopts :f:v:r:l:P:S:cu:g: opt; do +while getopts :f:vr:l:P:S:cu:g: opt; do case $opt in f) pkgfile="$OPTARG" ;; P) prefix="$OPTARG" ;; @@ -43,7 +44,8 @@ while getopts :f:v:r:l:P:S:cu:g: opt; do c) isconfig=1 ;; u) username="$OPTARG" ;; g) groupname="$OPTARG" ;; - *) echo 'unknown option' $opt; exit 1 ;; + v) verbose=1 ;; + *) echo 'unknown option' $OPTARG; exit 1 ;; esac done shift $((OPTIND - 1)) @@ -52,6 +54,10 @@ if [ $isconfig -eq 1 ]; then tags="$tags configuration" fi +if [ $verbose -gt 1 ]; then + set -x +fi + pkgid="$1" shift eval $(zpm parse -E $pkgid) @@ -83,15 +89,19 @@ if [ -z "$pkgfile" ]; then die "cannot determine package file" fi -set -e - # check for package file if [ ! -f "$pkgfile" ]; then echo $pkgfile does not exist exit 1 fi +set -e zpm test -v $pkgfile +set +e + +if [ $verbose -gt 0 ]; then + echo adding to $pkgfile $pkgid +fi package=$(zpm quote "$name") pkgver=$(zpm quote "$version") diff --git a/zpm-install b/zpm-install old mode 100644 new mode 100755 index 13a8dcf..994ed19 --- a/zpm-install +++ b/zpm-install @@ -6,19 +6,22 @@ die() { } dryrun=0 +verbose=0 runscripts=1 runconfigure=1 localdb=/var/lib/zpm/local.db # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ... -while getopts :f:d:R:nSC opt; do +while getopts f:d:R:nSCv opt; do case $opt in f) pkgfile="$OPTARG" ;; d) localdb="$OPTARG" ;; R) rootdir="$OPTARG" ;; S) runscripts=0 ;; C) runconfigure=0 ;; - n) dryrun=1 + n) dryrun=1 ;; + v) verbose=1 ;; + *) die "usage ..." ;; esac done shift $(( OPTIND - 1)) @@ -44,6 +47,7 @@ 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 @@ -68,8 +72,6 @@ if [ ! -f "$pkgfile" ]; then fi fi -set -e - if [ "$idempotent" = 1 ]; then idempotent='or ignore' fi @@ -81,20 +83,30 @@ 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 -ge 0 ]; then - die 'already installing' +if [ $var -gt 0 ]; then + zpm list -v -f $localdb -s installing + die "already ($localdb) installing $var package(s)" fi -if [ -n "$rootdir" ]; +if [ -n "$rootdir" ]; then ZPM_ROOT_DIR="$rootdir" export ZPM_ROOT_DIR fi # TODO mark already installed packages as updating? for pkgstr in "$@"; do - pkgid=$(zpm findpkg -f $pkgfile $pkgstr) + pkgid=$(zpm findpkg $pkgfile $pkgstr) if [ $? -ne 0 ]; then # TODO log die "can't find package $pkgstr in $pkgfile" @@ -110,7 +122,7 @@ for pkgstr in "$@"; do current=$(zpm list -s installed "$package") if [ $runscripts -gt 0 ]; then - zpm runscript -f $packagefile -p pre-install $pkgid $current + zpm runscript -f $pkgfile -p pre-install $pkgid $current if [ $? -ne 0 ]; then # TODO log die "pre-install script for $pkgid failed" @@ -126,13 +138,30 @@ for pkgstr in "$@"; do fi fi + if [ $dryrun -gt 0 ]; then + #zpm list -v + #zpm shell $ZPMDB 'select * from install_status' + zpm pkgfiles -nv -f $pkgfile $pkgid + zpm pkg $pkgid status=dryrun + continue + fi + zpm pkgfiles -f $pkgfile $pkgid + + if [ $? -ne 0 ]; then + die 'zpm-pkgfiles failed'; + fi + if [ $runscripts -gt 0 ]; then zpm runscript -f $pkgfile -p post-install $pkgid $current fi - # need a way to update multiple statuses all in one - # zpm pkgstatus $pkgid installed $pkgid updated - zpm pkg $pkgid status installed + + if [ -n "$current" ]; then + zpm pkg $pkgid status=installed :$current status=updated + else + zpm pkg $pkgid status=installed + fi + if [ $runconfigure -gt 0 ]; then zpm runscript -f $pkgfile -p configure $pkgid $current fi