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 [ -n "$rootdir" ]; then
92 : rootdir=${rootdir%%/}
95 if [ -z "$localdb" ]; then
96 localdb=${rootdir}/var/lib/zpm/local.db
99 if [ ! -f "$localdb" ]; then
100 if [ -n "$rootdir" ] && [ ! -d $rootdir ]; then
101 mkdir $rootdir || die "can't create $rootdir: $!"
103 for d in /var /var/lib /var/lib/zpm; do
104 test -d $rootdir/$d || mkdir $rootdir/$d || die "can't create $rootdir/$d/: $!"
107 if [ $? -ne 0 ]; then
108 die "aborting install"
115 if [ -z "$ZPMDB" ]; then
118 #echo "localdb = $ZPMDB"
122 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
124 # check if we're installing something already
125 var=$(zpm list -f $localdb -s installing | wc -l)
126 if [ $var -gt 0 ]; then
127 zpm list -v -f $localdb -s installing
128 die "already ($localdb) installing $var package(s)"
130 # check if we're installing something already
131 var=$(zpm list -f $localdb -s removing | wc -l)
132 if [ $var -gt 0 ]; then
133 zpm list -v -f $localdb -s removing
134 die "already ($localdb) removing $var package(s)"
136 var=$(zpm list -f $localdb -s updating | wc -l)
137 if [ $var -gt 0 ]; then
138 zpm list -v -f $localdb -s updating
139 die "already ($localdb) updating $var package(s)"
142 if [ -n "$rootdir" ]; then
143 ZPM_ROOT_DIR="$rootdir"
147 # TODO mark already installed packages as updating?
148 for pkgstr in "$@"; do
149 pkgid=$(zpm findpkg -f $pkgfile $pkgstr)
150 if [ $? -ne 0 ]; then
152 die "can't find package $pkgstr in $pkgfile"
155 curstatus=$(zpm pkg $pkgid status)
156 if [ "$curstatus" = 'installed' ]; then
157 die "$pkgid already installed"
160 eval $(zpm parse -E $pkgid)
163 current=$(zpm list -s installed "$package")
165 if [ $runscripts -gt 0 ]; then
166 # TODO run pre-upgrade script if needed
167 # zpm runscript -p pre-upgrade $current $pkgid
168 zpm runscript -f $pkgfile -p pre-install $pkgid $current
169 if [ $? -ne 0 ]; then
171 die "pre-install script for $pkgid failed"
175 # remove the package if it exists. can't be in an installed
176 # state, would have bailed above. So, if it exists, can only
177 # be 'upgraded'. This should be fast, because we won't run
178 # a garbage collect, so any possible duplicate files between
179 # an upgraded or removed files, if they're there, won't need
182 # only merge if localdb and pkgfile are different
183 if [ "$pkgfile" != "$ZPMDB" ]; then
185 zpm merge -f $pkgfile -s installing $pkgid
186 if [ $? -ne 0 ]; then
188 die "merging $pkgid failed"
191 # TODO but need to mark as installing if not merged
193 #zpm shell $ZPMDB 'select * from install_status' 1>&2
194 if [ $dryrun -gt 0 ]; then
196 #zpm shell $ZPMDB 'select * from install_status'
197 zpm syncfs $syncopts -nv -f $pkgfile
198 zpm pkg $pkgid status=dryrun
202 if [ $verbose -gt 0 ]; then
203 syncopts="${syncopts} -v"
206 zpm syncfs $syncopts -f $pkgfile
208 if [ $? -ne 0 ]; then
209 die 'zpm-syncfs failed';
212 if [ $runscripts -gt 0 ]; then
213 zpm runscript -f $pkgfile -p post-install $pkgid $current
216 if [ -n "$current" ]; then
217 zpm pkg $pkgid status=installed :$current status=updated
219 zpm pkg $pkgid status=installed
222 if [ $(id -u) -eq 0 ]; then
223 if [ ! -d $rootdir/etc ]; then
224 warn "no etc directory in $rootdir, skipping ldconfig"
225 elif [ -f $rootdir/sbin/ldconfig ]; then
226 $rootdir/sbin/ldconfig -r ${rootdir:-/}
227 elif [ -f /sbin/ldconfig ]; then
228 /sbin/ldconfig -r ${rootdir:-/}
234 # TODO skip configure if not on a terminal, regardless of settings
235 # TODO will need force option
236 if [ $runconfigure -gt 0 ]; then
237 zpm runscript -f $pkgfile -p configure $pkgid $current