16 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
17 while getopts f:d:R:nSCvAO opt; do
19 f) pkgfile="$OPTARG" ;;
20 d) localdb="$OPTARG" ;;
21 R) rootdir="$OPTARG" ;;
24 A) absorb=1; syncopts="${syncopts} -A" ;;
25 O) overwrite=1; syncopts="${syncopts} -O" ;;
31 shift $(( OPTIND - 1))
35 if [ -z "$pkgid" ]; then
36 die "must specify pkgid"
39 eval "$(zpm parse -E $pkgid)"
41 if [ -z "$pkgfile" ]; then
42 pkgfile=$ZPM_PACKAGE_FILE
45 # cases R = full package id, F = specified package file
48 # -- 00 error, must specify something
49 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
50 die must specify package file or complete package id
53 # TODO look in package file
54 # -F 01 error, wouldn't know which pkgid to create, could derive from file?
55 if [ -z "$release" ]; then
56 # must have package file, or would have died above
57 pkgid=$(zpm findpkg -f $pkgfile $pkgid)
58 if [ -n "$pkgid" ]; then
59 eval "$(zpm parse -E $pkgid)"
63 if [ -z "$pkgid" ]; then
64 die "$0 can't figure out a package id"
68 # R- 10 set file from pkgid, create in file, error if no file
69 if [ -z "$pkgfile" ]; then
73 # will now be one of these
74 # RF 11 create package in file, error if file doesn't exist
75 if [ ! -f "$pkgfile" ]; then
76 die $pkgfile does not exist
79 if [ "$idempotent" = 1 ]; then
80 idempotent='or ignore'
83 package=$(zpm quote "$name")
84 pkgver=$(zpm quote "$version")
85 pkgrel=$(zpm quote "$release")
87 if [ -z "$rootdir" ]; then
88 : rootdir=${rootdir%%/}
91 if [ -z "$localdb" ]; then
92 localdb=${rootdir}/var/lib/zpm/local.db
95 if [ ! -f "$localdb" ]; then
96 for d in /var /var/lib /var/lib/zpm; do
97 test -d $rootdir/$d || mkdir $rootdir/$d || die "can't create $rootdir/$d/: $!"
100 if [ $? -ne 0 ]; then
101 die "aborting install"
108 if [ -z "$ZPMDB" ]; then
111 #echo "localdb = $ZPMDB"
115 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
117 # check if we're installing something already
118 var=$(zpm list -f $localdb -s installing | wc -l)
119 if [ $var -gt 0 ]; then
120 zpm list -v -f $localdb -s installing
121 die "already ($localdb) installing $var package(s)"
123 # check if we're installing something already
124 var=$(zpm list -f $localdb -s removing | wc -l)
125 if [ $var -gt 0 ]; then
126 zpm list -v -f $localdb -s removing
127 die "already ($localdb) removing $var package(s)"
129 var=$(zpm list -f $localdb -s updating | wc -l)
130 if [ $var -gt 0 ]; then
131 zpm list -v -f $localdb -s updating
132 die "already ($localdb) updating $var package(s)"
135 if [ -n "$rootdir" ]; then
136 ZPM_ROOT_DIR="$rootdir"
140 # TODO mark already installed packages as updating?
141 for pkgstr in "$@"; do
142 pkgid=$(zpm findpkg -f $pkgfile $pkgstr)
143 if [ $? -ne 0 ]; then
145 die "can't find package $pkgstr in $pkgfile"
148 curstatus=$(zpm pkg $pkgid status)
149 if [ "$curstatus" = 'installed' ]; then
150 die "$pkgid already installed"
153 eval $(zpm parse -E $pkgid)
156 current=$(zpm list -s installed "$package")
158 if [ $runscripts -gt 0 ]; then
159 # TODO run pre-upgrade script if needed
160 # zpm runscript -p pre-upgrade $current $pkgid
161 zpm runscript -f $pkgfile -p pre-install $pkgid $current
162 if [ $? -ne 0 ]; then
164 die "pre-install script for $pkgid failed"
168 # remove the package if it exists. can't be in an installed
169 # state, would have bailed above. So, if it exists, can only
170 # be 'upgraded'. This should be fast, because we won't run
171 # a garbage collect, so any possible duplicate files between
172 # an upgraded or removed files, if they're there, won't need
175 # only merge if localdb and pkgfile are different
176 if [ "$pkgfile" != "$ZPMDB" ]; then
178 zpm merge -f $pkgfile -s installing $pkgid
179 if [ $? -ne 0 ]; then
181 die "merging $pkgid failed"
184 # TODO but need to mark as installing if not merged
186 #zpm shell $ZPMDB 'select * from install_status' 1>&2
187 if [ $dryrun -gt 0 ]; then
189 #zpm shell $ZPMDB 'select * from install_status'
190 zpm syncfs $syncopts -nv -f $pkgfile
191 zpm pkg $pkgid status=dryrun
195 if [ $verbose -gt 0 ]; then
196 syncopts="${syncopts} -v"
199 zpm syncfs $syncopts -f $pkgfile
201 if [ $? -ne 0 ]; then
202 die 'zpm-syncfs failed';
205 if [ $runscripts -gt 0 ]; then
206 zpm runscript -f $pkgfile -p post-install $pkgid $current
209 if [ -n "$current" ]; then
210 zpm pkg $pkgid status=installed :$current status=updated
212 zpm pkg $pkgid status=installed
215 if [ $(id -u) -eq 0 ]; then
216 if [ -f $rootdir/sbin/ldconfig ]; then
217 $rootdir/sbin/ldconfig -r ${rootdir:-/}
218 elif [ -f /sbin/ldconfig ]; then
219 /sbin/ldconfig -r ${rootdir:-/}
225 # TODO skip configure if not on a terminal, regardless of settings
226 # TODO will need force option
227 if [ $runconfigure -gt 0 ]; then
228 zpm runscript -f $pkgfile -p configure $pkgid $current