20 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
21 while getopts f:d:R:nSCvAO opt; do
23 f) pkgfile="$OPTARG" ;;
24 d) localdb="$OPTARG" ;;
25 R) rootdir="$OPTARG" ;;
28 A) absorb=1; syncopts="${syncopts} -A" ;;
29 O) overwrite=1; syncopts="${syncopts} -O" ;;
35 shift $(( OPTIND - 1))
39 if [ -z "$pkgid" ]; then
40 die "must specify pkgid"
43 eval "$(zpm parse -E $pkgid)"
45 if [ -z "$pkgfile" ]; then
46 pkgfile=$ZPM_PACKAGE_FILE
49 # cases R = full package id, F = specified package file
52 # -- 00 error, must specify something
53 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
54 die must specify package file or complete package id
57 # TODO look in package file
58 # -F 01 error, wouldn't know which pkgid to create, could derive from file?
59 if [ -z "$release" ]; then
60 # must have package file, or would have died above
61 pkgid=$(zpm findpkg -f $pkgfile $pkgid)
62 if [ -n "$pkgid" ]; then
63 eval "$(zpm parse -E $pkgid)"
67 if [ -z "$pkgid" ]; then
68 die "$0 can't figure out a package id"
72 # R- 10 set file from pkgid, create in file, error if no file
73 if [ -z "$pkgfile" ]; then
77 # will now be one of these
78 # RF 11 create package in file, error if file doesn't exist
79 if [ ! -f "$pkgfile" ]; then
80 die $pkgfile does not exist
83 if [ "$idempotent" = 1 ]; then
84 idempotent='or ignore'
87 package=$(zpm quote "$name")
88 pkgver=$(zpm quote "$version")
89 pkgrel=$(zpm quote "$release")
91 if [ -z "$rootdir" ]; then
92 : rootdir=${rootdir%%/}
95 if [ -z "$localdb" ]; then
96 localdb=${rootdir}/var/lib/zpm/local.db
99 if [ ! -f "$localdb" ]; then
100 for d in /var /var/lib /var/lib/zpm; do
101 test -d $rootdir/$d || mkdir $rootdir/$d || die "can't create $rootdir/$d/: $!"
104 if [ $? -ne 0 ]; then
105 die "aborting install"
112 if [ -z "$ZPMDB" ]; then
115 #echo "localdb = $ZPMDB"
119 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
121 # check if we're installing something already
122 var=$(zpm list -f $localdb -s installing | wc -l)
123 if [ $var -gt 0 ]; then
124 zpm list -v -f $localdb -s installing
125 die "already ($localdb) installing $var package(s)"
127 # check if we're installing something already
128 var=$(zpm list -f $localdb -s removing | wc -l)
129 if [ $var -gt 0 ]; then
130 zpm list -v -f $localdb -s removing
131 die "already ($localdb) removing $var package(s)"
133 var=$(zpm list -f $localdb -s updating | wc -l)
134 if [ $var -gt 0 ]; then
135 zpm list -v -f $localdb -s updating
136 die "already ($localdb) updating $var package(s)"
139 if [ -n "$rootdir" ]; then
140 ZPM_ROOT_DIR="$rootdir"
144 # TODO mark already installed packages as updating?
145 for pkgstr in "$@"; do
146 pkgid=$(zpm findpkg -f $pkgfile $pkgstr)
147 if [ $? -ne 0 ]; then
149 die "can't find package $pkgstr in $pkgfile"
152 curstatus=$(zpm pkg $pkgid status)
153 if [ "$curstatus" = 'installed' ]; then
154 die "$pkgid already installed"
157 eval $(zpm parse -E $pkgid)
160 current=$(zpm list -s installed "$package")
162 if [ $runscripts -gt 0 ]; then
163 # TODO run pre-upgrade script if needed
164 # zpm runscript -p pre-upgrade $current $pkgid
165 zpm runscript -f $pkgfile -p pre-install $pkgid $current
166 if [ $? -ne 0 ]; then
168 die "pre-install script for $pkgid failed"
172 # remove the package if it exists. can't be in an installed
173 # state, would have bailed above. So, if it exists, can only
174 # be 'upgraded'. This should be fast, because we won't run
175 # a garbage collect, so any possible duplicate files between
176 # an upgraded or removed files, if they're there, won't need
179 # only merge if localdb and pkgfile are different
180 if [ "$pkgfile" != "$ZPMDB" ]; then
182 zpm merge -f $pkgfile -s installing $pkgid
183 if [ $? -ne 0 ]; then
185 die "merging $pkgid failed"
188 # TODO but need to mark as installing if not merged
190 #zpm shell $ZPMDB 'select * from install_status' 1>&2
191 if [ $dryrun -gt 0 ]; then
193 #zpm shell $ZPMDB 'select * from install_status'
194 zpm syncfs $syncopts -nv -f $pkgfile
195 zpm pkg $pkgid status=dryrun
199 if [ $verbose -gt 0 ]; then
200 syncopts="${syncopts} -v"
203 zpm syncfs $syncopts -f $pkgfile
205 if [ $? -ne 0 ]; then
206 die 'zpm-syncfs failed';
209 if [ $runscripts -gt 0 ]; then
210 zpm runscript -f $pkgfile -p post-install $pkgid $current
213 if [ -n "$current" ]; then
214 zpm pkg $pkgid status=installed :$current status=updated
216 zpm pkg $pkgid status=installed
219 if [ $(id -u) -eq 0 ]; then
220 if [ ! -d $rootdir/etc ]; then
221 warn "no etc directory in $rootdir, skipping ldconfig"
222 elif [ -f $rootdir/sbin/ldconfig ]; then
223 $rootdir/sbin/ldconfig -r ${rootdir:-/}
224 elif [ -f /sbin/ldconfig ]; then
225 /sbin/ldconfig -r ${rootdir:-/}
231 # TODO skip configure if not on a terminal, regardless of settings
232 # TODO will need force option
233 if [ $runconfigure -gt 0 ]; then
234 zpm runscript -f $pkgfile -p configure $pkgid $current