]> pd.if.org Git - zpackage/blob - zpm-pkg
fix bug in aging view, add man pages
[zpackage] / zpm-pkg
1 #!/bin/sh
2
3 # edit package metadata
4
5 #zpm pkg -s packager=foo zpm
6
7 # zpm pkg -f <pkgfile> zpm packager=xyz
8 # zpm pkg zpm packager
9
10 warn() {
11         printf '%s:' "$0" 1>&2
12         printf ' %s' $* 1>&2
13         printf '\n' 1>&2
14         rv=1
15 }
16
17 die() {
18         printf '%s:' "$0" 1>&2
19         printf ' %s' $* 1>&2
20         printf '\n' 1>&2
21         exit 1
22 }
23
24 pkgfile=${ZPMDB:-/var/lib/zpm/local.db}
25
26 while getopts f: opt; do
27         case $opt in
28                 f) pkgfile="$OPTARG" ;;
29         esac
30 done
31 shift $((OPTIND - 1))
32
33 set -e
34
35 if [ ! -f $pkgfile ]; then
36         echo cannot find $pkgfile
37         exit 1
38 fi
39
40 item=$1
41 shift
42 #printf "pkg: %s\n" $pkg
43 pkgid=$(zpm findpkg -f $pkgfile "$item")
44
45 if [ -z "$pkgid" ]; then
46         die "can't find pkgid for $item in $pkgfile"
47 fi
48
49 (
50 rv=0
51
52 {
53 printf "begin;\n"
54 while [ $# -gt 0 ]; do
55         item=$1
56         shift
57         show=0
58         case "$item" in
59                 :*)
60                         pkgid=$(zpm findpkg -f $pkgfile "${item#:}")
61                         continue
62                         ;;
63                 *=*)
64                         field=${item%%=*}
65                         value=${item#*=}
66                         ;;
67                 *=)
68                         field=${item%%=*}
69                         value=
70                         ;;
71                 *)
72                 field=$item
73                 show=1
74                 ;;
75         esac
76
77         if [ -z "$pkgid" ]; then
78                 warn "can't find pkgid for $item in $pkgfile"
79                 break;
80         fi
81
82         vfield=$(zpm quote "$field")
83
84         hasfield=$(zpm shell $pkgfile "select name from pragma_table_info('packages') where name = '$vfield';")
85         if [ -z "$hasfield" ]; then
86                 warn "$field is not a valid package field"
87                 break
88         fi
89
90         field=$(zpm quote -i "$field")
91
92         if [ $show -eq 1 ]; then
93                 printf "select %s from packages_pkgid where pkgid = '%s';\n" "$field" "$pkgid"
94                 continue
95         fi
96
97         if [ -z "$value" ]; then
98                 value=NULL
99         else
100                 value=$(zpm quote -q "$value")
101         fi
102
103         printf "update packages_pkgid set %s = %s where pkgid = '$pkgid';\n" $field "$value"
104 done
105
106 if [ $rv -eq 0 ]; then
107         printf "commit;\n"
108 else
109         printf "rollback;\n"
110 fi
111
112 } | zpm shell $pkgfile
113 exit $rv
114 )