From: Nathan Wagner Date: Sun, 30 Sep 2018 14:48:53 +0000 (+0000) Subject: add verbose option to pathmod X-Git-Tag: v0.1.7~1 X-Git-Url: https://pd.if.org/git/?p=zpackage;a=commitdiff_plain;h=2d5fa477f3f74705a7c8657166cd1424b5b17544 add verbose option to pathmod The -v option will add in the owner, type, and permissions columns to the output. Changed the output delimiter to a space. --- diff --git a/zpm-pathmod b/zpm-pathmod new file mode 100755 index 0000000..0a699fd --- /dev/null +++ b/zpm-pathmod @@ -0,0 +1,132 @@ +#!/bin/sh + +# edit package metadata + +#zpm pkg -s packager=foo zpm + +# zpm pkg -f zpm path packager=xyz +# zpm pkg zpm packager zyz +# zpm pkg zpm packager + +warn() { + printf '%s:' "$0" 1>&2 + printf ' %s' $* 1>&2 + printf '\n' 1>&2 + rv=1 +} + +die() { + printf '%s:' "$0" 1>&2 + printf ' %s' $* 1>&2 + printf '\n' 1>&2 + exit 1 +} + +pkgfile=${ZPMDB:-/var/lib/zpm/db.zpm} + +while getopts f: opt; do + case $opt in + f) pkgfile="$OPTARG" ;; + esac +done +shift $((OPTIND - 1)) + +set -e + +if [ ! -f $pkgfile ]; then + echo cannot find $pkgfile + exit 1 +fi + +item=$1 +shift +#printf "pkg: %s\n" $pkg +pkgid=$(zpm findpkg -f $pkgfile "$item") + +if [ -z "$pkgid" ]; then + die "can't find pkgid for $item in $pkgfile" +fi + +path=$1 +shift +path=$(zpm quote "$path") + +( +rv=0 + +{ +printf "begin;\n" +while [ $# -gt 0 ]; do + item=$1 + shift + show=0 + case "$item" in + :*) + pkgid=$(zpm findpkg -f $pkgfile "${item#:}") + continue + ;; + +*) + path="${item#+}" + path=$(zpm quote "$path") + continue + ;; + *=*) + field=${item%%=*} + value=${item#*=} + ;; + *=) + field=${item%%=*} + value= + ;; + *) + field=$item + show=1 + ;; + esac + + # TODO if field = pkgid, parse and set + # TODO if changing pkgid, and it doesn't exist, better error + # message + + if [ -z "$pkgid" ]; then + warn "can't find pkgid for $item in $pkgfile" + break; + fi + + if [ $field = delete ]; then + printf "delete from packagefiles_pkgid where pkgid = '%s' and path = '%s';\n" "$pkgid" "$path" + else + vfield=$(zpm quote "$field") + + hasfield=$(zpm shell $pkgfile "select name from pragma_table_info('packagefiles') where name = '$vfield';") + if [ -z "$hasfield" ]; then + warn "$field is not a valid packagefile field" + break + fi + + field=$(zpm quote -i "$field") + + if [ $show -eq 1 ]; then + printf "select %s from packagefiles_pkgid where pkgid = '%s' and path='$path';\n" "$field" "$pkgid" + continue + fi + + if [ -z "$value" ]; then + value=NULL + else + value=$(zpm quote -q "$value") + fi + + printf "update packagefiles_pkgid set %s = %s where pkgid = '$pkgid' and path='$path';\n" $field $value + fi +done + +if [ $rv -eq 0 ]; then + printf "commit;\n" +else + printf "rollback;\n" +fi + +} | zpm shell $pkgfile +exit $rv +)