9 zpm log -i -a 'aborting install' -t "$pkgid" "$*"
22 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
23 while getopts f:d:R:nSCvAOa opt; do
25 f) pkgfile="$OPTARG" ;;
26 d) localdb="$OPTARG" ;;
27 R) rootdir="$OPTARG" ;;
30 A) absorb=1; syncopts="${syncopts} -A" ;;
32 O) overwrite=1; syncopts="${syncopts} -O" ;;
38 shift $(( OPTIND - 1))
44 if [ -z "$pkgfile" ]; then
45 pkgfile=$ZPM_PACKAGE_FILE
48 if [ $installall -eq 1 ]; then
49 pkglist="$(zpm list -f $pkgfile)"
51 pkglist=$(zpm findpkg -f $pkgfile "$1")
54 if [ $verbose -gt 0 ]; then
58 if [ -z "$pkglist" ]; then
59 die "$0 no packages specified for install"
62 if [ "$idempotent" = 1 ]; then
63 idempotent='or ignore'
66 if [ -n "$rootdir" ]; then
67 : rootdir=${rootdir%%/}
70 if [ -z "$localdb" ]; then
71 localdb=${rootdir}/var/lib/zpm/local.db
74 if [ ! -f "$localdb" ]; then
75 if [ -n "$rootdir" ] && [ ! -d $rootdir ]; then
76 mkdir $rootdir || die "can't create $rootdir: $!"
78 for d in /var /var/lib /var/lib/zpm; do
79 test -d $rootdir/$d || mkdir $rootdir/$d || die "can't create $rootdir/$d/: $!"
83 die "aborting install"
90 if [ -z "$ZPMDB" ]; then
93 #echo "localdb = $ZPMDB"
97 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
99 # check if we're installing something already
100 var=$(zpm list -f $localdb -s installing | wc -l)
101 if [ $var -gt 0 ]; then
102 zpm list -v -f $localdb -s installing
103 die "already ($localdb) installing $var package(s)"
105 # check if we're removing something already
106 var=$(zpm list -f $localdb -s removing | wc -l)
107 if [ $var -gt 0 ]; then
108 zpm list -v -f $localdb -s removing
109 die "already ($localdb) removing $var package(s)"
111 var=$(zpm list -f $localdb -s updating | wc -l)
112 if [ $var -gt 0 ]; then
113 zpm list -v -f $localdb -s updating
114 die "already ($localdb) updating $var package(s)"
117 if [ -n "$rootdir" ]; then
118 ZPM_ROOT_DIR="$rootdir"
122 for pkgid in $pkglist; do
123 curstatus=$(zpm pkg $pkgid status)
124 if [ "$curstatus" = 'installed' ]; then
125 die "$pkgid already installed"
128 package=$(zpm parse -n $pkgid)
129 current=$(zpm list -s installed "$package")
131 if [ $runscripts -gt 0 ]; then
132 # TODO run pre-upgrade script if needed
133 # zpm runscript -p pre-upgrade $current $pkgid
134 zpm script -f $pkgfile -p pre-install $pkgid $current
135 if [ $? -ne 0 ]; then
136 die "pre-install script for $pkgid failed"
140 # remove the package if it exists. can't be in an installed
141 # state, would have bailed above. So, if it exists, can only
142 # be 'upgraded'. This should be fast, because we won't run
143 # a garbage collect, so any possible duplicate files between
144 # an upgraded or removed files, if they're there, won't need
147 # only merge if localdb and pkgfile are different
148 if [ "$pkgfile" != "$ZPMDB" ]; then
150 if [ $verbose -gt 0 ]; then
153 zpm merge -u -F -f $pkgfile -s installing $pkgid
154 if [ $? -ne 0 ]; then
155 die "merging $pkgid failed"
158 zpm pkg $pkgid status=installing
164 #zpm shell $ZPMDB 'select * from install_status' 1>&2
165 if [ $dryrun -gt 0 ]; then
166 syncopts="$syncopts -n"
169 if [ $verbose -gt 0 ]; then
170 syncopts="$syncopts -v"
177 for pkgid in $pkglist; do
178 zpm pkg $pkgid status=dryrun
181 if [ $syncrv -ne 0 ]; then
182 zpm pkg $pkgid status=failed
183 die 'zpm-syncfs failed';
186 if [ $(id -u) -eq 0 ]; then
187 if [ ! -d $rootdir/etc ]; then
188 warn "no etc directory in $rootdir, skipping ldconfig"
189 elif [ -f $rootdir/sbin/ldconfig ]; then
190 $rootdir/sbin/ldconfig -r ${rootdir:-/}
191 elif [ -f /sbin/ldconfig ]; then
192 /sbin/ldconfig -r ${rootdir:-/}
198 for pkgid in $pkglist; do
199 package=$(zpm parse -n $pkgid)
200 current=$(zpm list -s installed "$package")
202 if [ $runscripts -gt 0 ]; then
203 zpm script -f $pkgfile -p post-install $pkgid $current
206 if [ -n "$current" ]; then
207 zpm pkg $pkgid status=installed :$current status=updated
209 zpm pkg $pkgid status=installed
212 # TODO skip configure if not on a terminal, regardless of settings
213 # TODO will need force option
214 if [ $runconfigure -gt 0 ]; then
215 zpm script -f $pkgfile -p configure $pkgid