]> pd.if.org Git - zpackage/blob - zpm-rmpackage
fixup
[zpackage] / zpm-rmpackage
1 #!/bin/sh
2
3 pkgfile=${ZPM_PACKAGE_FILE:-${ZPMDB:-/var/lib/zpm/local.db}}
4
5 verbose=0
6
7 # newpackage -f pkgfile $pkgid
8 while getopts :f:vm: opt; do
9         case $opt in
10                 f) pkgfile="$OPTARG" ;;
11                 v) verbose=1 ;;
12                 m) message="$OPTARG" ;;
13         esac
14 done
15 shift $(( OPTIND - 1))
16
17 if [ -z "$message" ]; then
18         message=null
19 else
20         message=$(zpm quote -q "$message")
21 fi
22
23 die() {
24         echo $* 1>&2
25         exit 1
26 }
27
28 warn() {
29         echo $* 1>&2
30 }
31
32 if [ ! -f "$pkgfile" ]; then
33         die $pkgfile does not exist
34 fi
35
36 {
37         printf ".bail on\n"
38         printf "begin;\n"
39         for pkgstr in "$@"; do
40                 pkgid=$(zpm findpkg -f $pkgfile "$pkgstr")
41                 if [ $verbose -gt 0 ]; then
42                         if [ -z "$pkgid" ]; then
43                                 warn "$pkgstr not found"
44                                 continue;
45                         fi
46                         if [ $verbose -gt 1 ]; then
47                                 warn "found %s -> %s\n" "$pkgstr", "$pkgid"
48                         fi
49                 fi
50                 pkgid=$(zpm quote "$pkgid")
51                 printf "delete from packages_pkgid where pkgid = '$pkgid';\n"
52                 printf "insert into zpmlog (action, target, info) values ('rmpackage','%s',%s);\n" "$pkgid" "$message"
53         done
54         printf "commit;\n"
55 } | zpm shell $pkgfile