]> pd.if.org Git - zpackage/blob - zpm-rmpackage
add support for notes
[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:v opt; do
9         case $opt in
10                 f) pkgfile="$OPTARG" ;;
11                 v) verbose=1 ;;
12         esac
13 done
14 shift $(( OPTIND - 1))
15
16 die() {
17         echo $* 1>&2
18         exit 1
19 }
20
21 warn() {
22         echo $* 1>&2
23 }
24
25 if [ ! -f "$pkgfile" ]; then
26         die $pkgfile does not exist
27 fi
28
29 {
30         printf ".bail on\n"
31         printf "begin;\n"
32         for pkgstr in "$@"; do
33                 pkgid=$(zpm findpkg -f $pkgfile "$pkgstr")
34                 if [ $verbose -gt 0 ]; then
35                         if [ -z "$pkgid" ]; then
36                                 warn "$pkgstr not found"
37                                 continue;
38                         fi
39                         if [ $verbose -gt 1 ]; then
40                                 warn "found %s -> %s\n" "$pkgstr", "$pkgid"
41                         fi
42                 fi
43                 pkgid=$(zpm quote "$pkgid")
44                 printf "delete from packages_pkgid where pkgid = '$pkgid';\n"
45         done
46         printf "commit;\n"
47 } | zpm shell $pkgfile