]> pd.if.org Git - zpackage/blob - zpm-install
rename pkgfiles to syncfs
[zpackage] / zpm-install
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
14 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
15 while getopts f:d:R:nSCv opt; do
16         case $opt in
17                 f) pkgfile="$OPTARG" ;;
18                 d) localdb="$OPTARG" ;;
19                 R) rootdir="$OPTARG" ;;
20                 S) runscripts=0 ;;
21                 C) runconfigure=0 ;;
22                 n) dryrun=1 ;;
23                 v) verbose=1 ;;
24                 *) die "usage ..." ;;
25         esac
26 done
27 shift $(( OPTIND - 1))
28
29 pkgid=$1
30
31 if [ -z "$pkgid" ]; then
32         die "must specify pkgid"
33 fi
34
35 eval "$(zpm parse -E $pkgid)"
36
37 if [ -z "$pkgfile" ]; then
38         pkgfile=$ZPM_PACKAGE_FILE
39 fi
40
41 # cases C = create ok, R = full package id, F = specified package file
42
43 # immediate error
44 # C-- 100 error, must specify something
45 # --- 000 error, must specify something
46 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
47         die must specify package file or complete package id
48 fi
49
50 # TODO look in package file
51 # --F 001 error, wouldn't know which pkgid to create, could derive from file?
52 # C-F 101 error, since package wouldn't exist in file to find
53 if [ -z "$release" ]; then
54         die must specify complete package id
55 fi
56
57 # set file from pkgid
58 # CR- 110 set file from pkgid, create if needed
59 # -R- 010 set file from pkgid, create in file, error if no file
60 if [ -z "$pkgfile" ]; then
61         pkgfile="$pkgid.zpm"
62 fi
63
64 # will now be one of these
65 # CRF 111 create package in file given, create file if needed
66 # -RF 011 create package in file, error if file doesn't exist
67 if [ ! -f "$pkgfile" ]; then
68         if [ $create -eq 1 ]; then
69                 zpm init $pkgfile
70         else
71                 die $pkgfile does not exist
72         fi
73 fi
74
75 if [ "$idempotent" = 1 ]; then
76         idempotent='or ignore'
77 fi
78
79 package=$(zpm quote "$name")
80 pkgver=$(zpm quote "$version")
81 pkgrel=$(zpm quote "$release")
82
83 ZPMDB=$localdb
84 export ZPMDB
85
86 if [ -z "$ZPMDB" ]; then
87         die "no local db"
88 else
89         #echo "localdb = $ZPMDB"
90         true
91 fi
92
93 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
94
95 # check if we're installing something already
96 var=$(zpm list -f $localdb -s installing | wc -l)
97 if [ $var -gt 0 ]; then
98         zpm list -v -f $localdb -s installing 
99         die "already ($localdb) installing $var package(s)"
100 fi
101
102 if [ -n "$rootdir" ]; then
103         ZPM_ROOT_DIR="$rootdir"
104         export ZPM_ROOT_DIR
105 fi
106
107 # TODO mark already installed packages as updating?
108 for pkgstr in "$@"; do
109         pkgid=$(zpm findpkg $pkgfile $pkgstr)
110         if [ $? -ne 0 ]; then
111                 # TODO log
112                 die "can't find package $pkgstr in $pkgfile"
113         fi
114
115         curstatus=$(zpm pkg $pkgid status)
116         if [ "$curstatus" = 'installed' ]; then
117                 die "$pkgid already installed"
118         fi
119
120         eval $(zpm parse -E $pkgid)
121
122         #zpm list -v
123         current=$(zpm list -s installed "$package")
124         
125         if [ $runscripts -gt 0 ]; then
126                 zpm runscript -f $pkgfile -p pre-install $pkgid $current
127                 if [ $? -ne 0 ]; then
128                         # TODO log
129                         die "pre-install script for $pkgid failed"
130                 fi
131         fi
132
133         # only merge if localdb and pkgfile are different
134         if [ "$pkgfile" != "$ZPMDB" ]; then
135                 zpm merge -f $pkgfile -s installing $pkgid
136                 if [ $? -ne 0 ]; then
137                         # TODO log
138                         die "merging $pkgid failed"
139                 fi
140         fi
141         # TODO but need to mark as installing if not merged
142
143         #zpm shell $ZPMDB 'select * from install_status' 1>&2
144         if [ $dryrun -gt 0 ]; then
145                 #zpm list -v
146                 #zpm shell $ZPMDB 'select * from install_status'
147                 zpm syncfs -nv -f $pkgfile
148                 zpm pkg $pkgid status=dryrun
149                 continue
150         fi
151
152         zpm syncfs -f $pkgfile
153
154         if [ $? -ne 0 ]; then
155                 die 'zpm-syncfs failed';
156         fi
157
158         if [ $runscripts -gt 0 ]; then
159                 zpm runscript -f $pkgfile -p post-install $pkgid $current
160         fi
161
162         if [ -n "$current" ]; then
163                 zpm pkg $pkgid status=installed :$current status=updated
164         else
165                 zpm pkg $pkgid status=installed
166         fi
167
168         # TODO skip configure if not on a terminal, regardless of settings
169         # TODO will need force option
170         if [ $runconfigure -gt 0 ]; then
171                 zpm runscript -f $pkgfile -p configure $pkgid $current
172         fi
173 done