3 # edit package metadata
5 #zpm pkg -s packager=foo zpm
7 # zpm pkg -f <pkgfile> zpm path packager=xyz
8 # zpm pkg zpm packager zyz
12 printf '%s:' "$0" 1>&2
19 printf '%s:' "$0" 1>&2
25 pkgfile=${ZPMDB:-/var/lib/zpm/db.zpm}
27 while getopts f: opt; do
29 f) pkgfile="$OPTARG" ;;
36 if [ ! -f $pkgfile ]; then
37 echo cannot find $pkgfile
43 #printf "pkg: %s\n" $pkg
44 pkgid=$(zpm findpkg -f $pkgfile "$item")
46 if [ -z "$pkgid" ]; then
47 die "can't find pkgid for $item in $pkgfile"
52 path=$(zpm quote "$path")
59 while [ $# -gt 0 ]; do
65 pkgid=$(zpm findpkg -f $pkgfile "${item#:}")
70 path=$(zpm quote "$path")
87 # TODO if field = pkgid, parse and set
88 # TODO if changing pkgid, and it doesn't exist, better error
91 if [ -z "$pkgid" ]; then
92 warn "can't find pkgid for $item in $pkgfile"
96 if [ $field = delete ]; then
97 printf "delete from packagefiles_pkgid where pkgid = '%s' and path = '%s';\n" "$pkgid" "$path"
99 vfield=$(zpm quote "$field")
101 hasfield=$(zpm shell $pkgfile "select name from pragma_table_info('packagefiles') where name = '$vfield';")
102 if [ -z "$hasfield" ]; then
103 warn "$field is not a valid packagefile field"
107 field=$(zpm quote -i "$field")
109 if [ $show -eq 1 ]; then
110 printf "select %s from packagefiles_pkgid where pkgid = '%s' and path='$path';\n" "$field" "$pkgid"
114 if [ -z "$value" ]; then
117 value=$(zpm quote -q "$value")
120 printf "update packagefiles_pkgid set %s = %s where pkgid = '$pkgid' and path='$path';\n" $field $value
124 if [ $rv -eq 0 ]; then
130 } | zpm shell $pkgfile