9 zpm log -i -a 'aborting install' -t "$pkgid" "$*"
21 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
22 while getopts f:d:R:nSCvAO opt; do
24 f) pkgfile="$OPTARG" ;;
25 d) localdb="$OPTARG" ;;
26 R) rootdir="$OPTARG" ;;
29 A) absorb=1; syncopts="${syncopts} -A" ;;
30 O) overwrite=1; syncopts="${syncopts} -O" ;;
36 shift $(( OPTIND - 1))
40 if [ -z "$pkgid" ]; then
41 die "must specify pkgid"
44 eval "$(zpm parse -E $pkgid)"
46 if [ -z "$pkgfile" ]; then
47 pkgfile=$ZPM_PACKAGE_FILE
50 # cases R = full package id, F = specified package file
53 # -- 00 error, must specify something
54 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
55 die must specify package file or complete package id
58 # TODO look in package file
59 # -F 01 error, wouldn't know which pkgid to create, could derive from file?
60 if [ -z "$release" ]; then
61 # must have package file, or would have died above
62 pkgid=$(zpm findpkg -f $pkgfile $pkgid)
63 if [ -n "$pkgid" ]; then
64 eval "$(zpm parse -E $pkgid)"
68 if [ -z "$pkgid" ]; then
69 die "$0 can't figure out a package id"
73 # R- 10 set file from pkgid, create in file, error if no file
74 if [ -z "$pkgfile" ]; then
78 # will now be one of these
79 # RF 11 create package in file, error if file doesn't exist
80 if [ ! -f "$pkgfile" ]; then
81 die $pkgfile does not exist
84 if [ "$idempotent" = 1 ]; then
85 idempotent='or ignore'
88 package=$(zpm quote "$name")
89 pkgver=$(zpm quote "$version")
90 pkgrel=$(zpm quote "$release")
92 if [ -n "$rootdir" ]; then
93 : rootdir=${rootdir%%/}
96 if [ -z "$localdb" ]; then
97 localdb=${rootdir}/var/lib/zpm/local.db
100 if [ ! -f "$localdb" ]; then
101 if [ -n "$rootdir" ] && [ ! -d $rootdir ]; then
102 mkdir $rootdir || die "can't create $rootdir: $!"
104 for d in /var /var/lib /var/lib/zpm; do
105 test -d $rootdir/$d || mkdir $rootdir/$d || die "can't create $rootdir/$d/: $!"
108 if [ $? -ne 0 ]; then
109 die "aborting install"
116 if [ -z "$ZPMDB" ]; then
119 #echo "localdb = $ZPMDB"
123 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
125 # check if we're installing something already
126 var=$(zpm list -f $localdb -s installing | wc -l)
127 if [ $var -gt 0 ]; then
128 zpm list -v -f $localdb -s installing
129 die "already ($localdb) installing $var package(s)"
131 # check if we're installing something already
132 var=$(zpm list -f $localdb -s removing | wc -l)
133 if [ $var -gt 0 ]; then
134 zpm list -v -f $localdb -s removing
135 die "already ($localdb) removing $var package(s)"
137 var=$(zpm list -f $localdb -s updating | wc -l)
138 if [ $var -gt 0 ]; then
139 zpm list -v -f $localdb -s updating
140 die "already ($localdb) updating $var package(s)"
143 if [ -n "$rootdir" ]; then
144 ZPM_ROOT_DIR="$rootdir"
148 for pkgstr in "$@"; do
149 pkgid=$(zpm findpkg -f $pkgfile $pkgstr)
150 if [ $? -ne 0 ]; then
151 die "can't find package $pkgstr in $pkgfile"
154 curstatus=$(zpm pkg $pkgid status)
155 if [ "$curstatus" = 'installed' ]; then
156 die "$pkgid already installed"
159 eval $(zpm parse -E $pkgid)
162 current=$(zpm list -s installed "$package")
164 if [ $runscripts -gt 0 ]; then
165 # TODO run pre-upgrade script if needed
166 # zpm runscript -p pre-upgrade $current $pkgid
167 zpm script -f $pkgfile -p pre-install $pkgid $current
168 if [ $? -ne 0 ]; then
169 die "pre-install script for $pkgid failed"
173 # remove the package if it exists. can't be in an installed
174 # state, would have bailed above. So, if it exists, can only
175 # be 'upgraded'. This should be fast, because we won't run
176 # a garbage collect, so any possible duplicate files between
177 # an upgraded or removed files, if they're there, won't need
180 # only merge if localdb and pkgfile are different
181 if [ "$pkgfile" != "$ZPMDB" ]; then
183 zpm merge -f $pkgfile -s installing $pkgid
184 if [ $? -ne 0 ]; then
185 die "merging $pkgid failed"
188 zpm pkg $pkgid status=installing
191 #zpm shell $ZPMDB 'select * from install_status' 1>&2
192 if [ $dryrun -gt 0 ]; then
194 #zpm shell $ZPMDB 'select * from install_status'
195 zpm syncfs $syncopts -nv -f $pkgfile
196 zpm pkg $pkgid status=dryrun
200 if [ $verbose -gt 0 ]; then
201 syncopts="${syncopts} -v"
204 zpm syncfs $syncopts -f $pkgfile
206 if [ $? -ne 0 ]; then
207 zpm pkg $pkgid status=failed
208 die 'zpm-syncfs failed';
211 if [ $runscripts -gt 0 ]; then
212 zpm script -f $pkgfile -p post-install $pkgid $current
215 if [ -n "$current" ]; then
216 zpm pkg $pkgid status=installed :$current status=updated
218 zpm pkg $pkgid status=installed
221 if [ $(id -u) -eq 0 ]; then
222 if [ ! -d $rootdir/etc ]; then
223 warn "no etc directory in $rootdir, skipping ldconfig"
224 elif [ -f $rootdir/sbin/ldconfig ]; then
225 $rootdir/sbin/ldconfig -r ${rootdir:-/}
226 elif [ -f /sbin/ldconfig ]; then
227 /sbin/ldconfig -r ${rootdir:-/}
233 # TODO skip configure if not on a terminal, regardless of settings
234 # TODO will need force option
235 if [ $runconfigure -gt 0 ]; then
236 zpm script -f $pkgfile -p configure $pkgid $current