]> pd.if.org Git - zpackage/blob - zpm-uninstall
add man page shell
[zpackage] / zpm-uninstall
1 #!/bin/sh
2
3 die() {
4         echo $* 1>&2
5         exit 1
6 }
7
8 dryrun=0
9 verbose=0
10 runscripts=1
11 runconfigure=1
12 localdb=/var/lib/zpm/local.db
13 absorb=0
14
15 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
16 while getopts f:d:R:nSCvA opt; do
17         case $opt in
18                 A) absorb=1 ;;
19                 f) pkgfile="$OPTARG" ;;
20                 d) localdb="$OPTARG" ;;
21                 R) rootdir="$OPTARG" ;;
22                 S) runscripts=0 ;;
23                 C) runconfigure=0 ;;
24                 n) dryrun=1 ;;
25                 v) verbose=1 ;;
26                 *) die "usage ..." ;;
27         esac
28 done
29 shift $(( OPTIND - 1))
30
31 pkgid=$1
32
33 if [ -z "$pkgid" ]; then
34         die "must specify pkgid"
35 fi
36
37 eval "$(zpm parse -E $pkgid)"
38
39 if [ -z "$pkgfile" ]; then
40         pkgfile=$ZPM_PACKAGE_FILE
41 fi
42
43 # cases C = create ok, R = full package id, F = specified package file
44
45 # immediate error
46 # C-- 100 error, must specify something
47 # --- 000 error, must specify something
48 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
49         die must specify package file or complete package id
50 fi
51
52 # TODO look in package file
53 # --F 001 error, wouldn't know which pkgid to create, could derive from file?
54 # C-F 101 error, since package wouldn't exist in file to find
55 if [ -z "$release" ]; then
56         die must specify complete package id
57 fi
58
59 # set file from pkgid
60 # CR- 110 set file from pkgid, create if needed
61 # -R- 010 set file from pkgid, create in file, error if no file
62 if [ -z "$pkgfile" ]; then
63         pkgfile="$pkgid.zpm"
64 fi
65
66 # will now be one of these
67 # CRF 111 create package in file given, create file if needed
68 # -RF 011 create package in file, error if file doesn't exist
69 if [ ! -f "$pkgfile" ]; then
70         if [ $create -eq 1 ]; then
71                 zpm init $pkgfile
72         else
73                 die $pkgfile does not exist
74         fi
75 fi
76
77 if [ "$idempotent" = 1 ]; then
78         idempotent='or ignore'
79 fi
80
81 package=$(zpm quote "$name")
82 pkgver=$(zpm quote "$version")
83 pkgrel=$(zpm quote "$release")
84
85 ZPMDB=$localdb
86 export ZPMDB
87
88 if [ -z "$ZPMDB" ]; then
89         die "no local db"
90 else
91         #echo "localdb = $ZPMDB"
92         true
93 fi
94
95 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
96
97 # check if we're installing something already
98 var=$(zpm list -f $localdb -s installing | wc -l)
99 if [ $var -gt 0 ]; then
100         zpm list -v -f $localdb -s installing 
101         die "already ($localdb) installing $var package(s)"
102 fi
103
104 if [ -n "$rootdir" ]; then
105         ZPM_ROOT_DIR="$rootdir"
106         export ZPM_ROOT_DIR
107 fi
108
109 for pkgstr in "$@"; do
110         echo removing $pkgstr from $ZPMDB
111         pkgid=$(zpm findpkg -s installed -f $ZPMDB $pkgstr)
112         if [ $? -ne 0 ]; then
113                 die "$pkgid is not installed"
114         fi
115
116         eval $(zpm parse -E $pkgid)
117         echo found $name $version $release
118
119         if [ $runscripts -gt 0 ]; then
120                 zpm script -r -f $pkgfile -p pre-uninstall $pkgid $current
121                 if [ $? -ne 0 ]; then
122                         # TODO log
123                         die "pre-uninstall script for $pkgid failed"
124                 fi
125         fi
126
127         zpm pkg $pkgid status=removing
128
129         #zpm shell $ZPMDB 'select * from install_status' 1>&2
130         if [ $dryrun -gt 0 ]; then
131                 zpm syncfs -nv
132                 zpm pkg $pkgid status=dryrun
133                 continue
134         fi
135
136         zpm syncfs
137
138         if [ $? -ne 0 ]; then
139                 die 'zpm-pkgfiles failed';
140         fi
141
142         zpm pkg $pkgid status=removed
143
144         if [ $runscripts -gt 0 ]; then
145                 zpm script -r -p post-uninstall $pkgid
146         fi
147 done