9 zpm log -i -a 'aborting install' -t "$pkgid" "$*"
23 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
24 while getopts f:d:R:nSCvAOaF opt; do
26 f) pkgfile="$OPTARG" ;;
28 d) localdb="$OPTARG" ;;
29 R) rootdir="$OPTARG" ;;
32 A) absorb=1; syncopts="${syncopts} -A" ;;
34 O) overwrite=1; syncopts="${syncopts} -O" ;;
40 shift $(( OPTIND - 1))
46 if [ -z "$pkgfile" ]; then
47 pkgfile=$ZPM_PACKAGE_FILE
50 if [ $installall -eq 1 ]; then
51 pkglist="$(zpm list -f $pkgfile)"
53 pkglist=$(zpm findpkg -f $pkgfile "$1")
56 if [ $verbose -gt 0 ]; then
60 if [ -z "$pkglist" ]; then
61 die "$0 no packages specified for install"
64 if [ "$idempotent" = 1 ]; then
65 idempotent='or ignore'
68 if [ -n "$rootdir" ]; then
69 : rootdir=${rootdir%%/}
72 if [ -z "$localdb" ]; then
73 localdb=${rootdir}/var/lib/zpm/local.db
76 if [ ! -f "$localdb" ]; then
77 if [ -n "$rootdir" ] && [ ! -d $rootdir ]; then
78 mkdir $rootdir || die "can't create $rootdir: $!"
80 for d in /var /var/lib /var/lib/zpm; do
81 test -d $rootdir/$d || mkdir $rootdir/$d || die "can't create $rootdir/$d/: $!"
85 die "aborting install"
92 if [ -z "$ZPMDB" ]; then
95 #echo "localdb = $ZPMDB"
99 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
101 # check if we're installing something already
102 var=$(zpm list -f $localdb -s installing | wc -l)
103 if [ $var -gt 0 ]; then
104 zpm list -v -f $localdb -s installing
105 die "already ($localdb) installing $var package(s)"
107 # check if we're removing something already
108 var=$(zpm list -f $localdb -s removing | wc -l)
109 if [ $var -gt 0 ]; then
110 zpm list -v -f $localdb -s removing
111 die "already ($localdb) removing $var package(s)"
113 var=$(zpm list -f $localdb -s updating | wc -l)
114 if [ $var -gt 0 ]; then
115 zpm list -v -f $localdb -s updating
116 die "already ($localdb) updating $var package(s)"
119 if [ -n "$rootdir" ]; then
120 ZPM_ROOT_DIR="$rootdir"
124 for pkgid in $pkglist; do
125 curstatus=$(zpm pkg $pkgid status)
126 if [ "$curstatus" = 'installed' ]; then
127 die "$pkgid already installed"
130 package=$(zpm parse -n $pkgid)
131 current=$(zpm list -s installed "$package")
133 if [ $runscripts -gt 0 ]; then
134 # TODO run pre-upgrade script if needed
135 # zpm runscript -p pre-upgrade $current $pkgid
136 zpm script -f $pkgfile -p pre-install $pkgid $current
137 if [ $? -ne 0 ]; then
138 die "pre-install script for $pkgid failed"
141 if zpm script -f $pkgfile -Fql -p pre-install $pkgid; then
142 zpm note -e -p $pkgid -m 'pre-install script not run'
146 # remove the package if it exists. can't be in an installed
147 # state, would have bailed above. So, if it exists, can only
148 # be 'upgraded'. This should be fast, because we won't run
149 # a garbage collect, so any possible duplicate files between
150 # an upgraded or removed files, if they're there, won't need
153 # only merge if localdb and pkgfile are different
154 if [ "$pkgfile" != "$ZPMDB" ]; then
156 if [ $verbose -gt 0 ]; then
159 if [ $mergefiles -eq 1 ]; then
160 zpm merge -u -F -f $pkgfile -s installing $pkgid
162 zpm merge -u -f $pkgfile -s installing $pkgid
164 if [ $? -ne 0 ]; then
165 die "merging $pkgid failed"
168 zpm pkg $pkgid status=installing
174 #zpm shell $ZPMDB 'select * from install_status' 1>&2
175 if [ $dryrun -gt 0 ]; then
176 syncopts="$syncopts -n"
179 if [ $verbose -gt 0 ]; then
180 syncopts="$syncopts -v"
183 if [ "$pkgfile" != "$ZPMDB" ]; then
184 syncopts="$syncopts -f $pkgfile"
191 if [ $dryrun -gt 0 ]; then
192 for pkgid in $pkglist; do
193 zpm pkg $pkgid status=dryrun
197 if [ $syncrv -ne 0 ]; then
198 zpm pkg $pkgid status=failed
199 die 'zpm-syncfs failed';
202 if [ $(id -u) -eq 0 ]; then
203 if [ ! -d $rootdir/etc ]; then
204 warn "no etc directory in $rootdir, skipping ldconfig"
205 elif [ -f $rootdir/sbin/ldconfig ]; then
206 $rootdir/sbin/ldconfig -r ${rootdir:-/}
207 elif [ -f /sbin/ldconfig ]; then
208 /sbin/ldconfig -r ${rootdir:-/}
214 for pkgid in $pkglist; do
215 package=$(zpm parse -n $pkgid)
216 current=$(zpm list -s installed "$package")
218 if [ $runscripts -gt 0 ]; then
219 zpm script -p post-install $pkgid $current
221 if zpm script -Fql -p post-install $pkgid; then
222 zpm note -e -p $pkgid -m 'post-install script not run'
226 if [ -n "$current" ]; then
227 zpm pkg $pkgid status=installed :$current status=updated
229 zpm pkg $pkgid status=installed
232 # TODO skip configure if not on a terminal, regardless of settings
233 # TODO will need force option
234 if [ $runconfigure -gt 0 ]; then
235 zpm script -p configure $pkgid
237 if zpm script -Fql -p configure $pkgid; then
238 zpm note -e -p $pkgid -m 'configure script not run'