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