16 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
17 while getopts f:d:R:nSCvAO opt; do
19 f) pkgfile="$OPTARG" ;;
20 d) localdb="$OPTARG" ;;
21 R) rootdir="$OPTARG" ;;
24 A) absorb=1; syncopts="${syncopts} -A" ;;
25 O) overwrite=1; syncopts="${syncopts} -O" ;;
31 shift $(( OPTIND - 1))
35 if [ -z "$pkgid" ]; then
36 die "must specify pkgid"
39 eval "$(zpm parse -E $pkgid)"
41 if [ -z "$pkgfile" ]; then
42 pkgfile=$ZPM_PACKAGE_FILE
45 # cases R = full package id, F = specified package file
48 # -- 00 error, must specify something
49 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
50 die must specify package file or complete package id
53 # TODO look in package file
54 # -F 01 error, wouldn't know which pkgid to create, could derive from file?
55 if [ -z "$release" ]; then
56 # must have package file, or would have died above
57 pkgid=$(zpm findpkg -f $pkgfile $pkgid)
58 if [ -n "$pkgid" ]; then
59 eval "$(zpm parse -E $pkgid)"
63 if [ -z "$pkgid" ]; then
64 die "$0 can't figure out a package id"
68 # R- 10 set file from pkgid, create in file, error if no file
69 if [ -z "$pkgfile" ]; then
73 # will now be one of these
74 # RF 11 create package in file, error if file doesn't exist
75 if [ ! -f "$pkgfile" ]; then
76 die $pkgfile does not exist
79 if [ "$idempotent" = 1 ]; then
80 idempotent='or ignore'
83 package=$(zpm quote "$name")
84 pkgver=$(zpm quote "$version")
85 pkgrel=$(zpm quote "$release")
87 if [ -z "$rootdir" ]; then
88 : rootdir=${rootdir%%/}
91 if [ -z "$localdb" ]; then
92 localdb=${rootdir}/var/lib/zpm/local.db
95 if [ ! -f "$localdb" ]; then
96 for d in /var /var/lib /var/lib/zpm; do
97 test -d $rootdir/$d || mkdir $rootdir/$d || die "can't create $rootdir/$d/: $!"
100 if [ $? -ne 0 ]; then
101 die "aborting install"
108 if [ -z "$ZPMDB" ]; then
111 #echo "localdb = $ZPMDB"
115 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
117 # check if we're installing something already
118 var=$(zpm list -f $localdb -s installing | wc -l)
119 if [ $var -gt 0 ]; then
120 zpm list -v -f $localdb -s installing
121 die "already ($localdb) installing $var package(s)"
123 # check if we're installing something already
124 var=$(zpm list -f $localdb -s removing | wc -l)
125 if [ $var -gt 0 ]; then
126 zpm list -v -f $localdb -s removing
127 die "already ($localdb) removing $var package(s)"
129 var=$(zpm list -f $localdb -s updating | wc -l)
130 if [ $var -gt 0 ]; then
131 zpm list -v -f $localdb -s updating
132 die "already ($localdb) updating $var package(s)"
135 if [ -n "$rootdir" ]; then
136 ZPM_ROOT_DIR="$rootdir"
140 # TODO mark already installed packages as updating?
141 for pkgstr in "$@"; do
142 pkgid=$(zpm findpkg -f $pkgfile $pkgstr)
143 if [ $? -ne 0 ]; then
145 die "can't find package $pkgstr in $pkgfile"
148 curstatus=$(zpm pkg $pkgid status)
149 if [ "$curstatus" = 'installed' ]; then
150 die "$pkgid already installed"
153 eval $(zpm parse -E $pkgid)
156 current=$(zpm list -s installed "$package")
158 if [ $runscripts -gt 0 ]; then
159 zpm runscript -f $pkgfile -p pre-install $pkgid $current
160 if [ $? -ne 0 ]; then
162 die "pre-install script for $pkgid failed"
166 # only merge if localdb and pkgfile are different
167 if [ "$pkgfile" != "$ZPMDB" ]; then
168 zpm merge -f $pkgfile -s installing $pkgid
169 if [ $? -ne 0 ]; then
171 die "merging $pkgid failed"
174 # TODO but need to mark as installing if not merged
176 #zpm shell $ZPMDB 'select * from install_status' 1>&2
177 if [ $dryrun -gt 0 ]; then
179 #zpm shell $ZPMDB 'select * from install_status'
180 zpm syncfs $syncopts -nv -f $pkgfile
181 zpm pkg $pkgid status=dryrun
185 if [ $verbose -gt 0 ]; then
186 syncopts="${syncopts} -v"
189 zpm syncfs $syncopts -f $pkgfile
191 if [ $? -ne 0 ]; then
192 die 'zpm-syncfs failed';
195 if [ $runscripts -gt 0 ]; then
196 zpm runscript -f $pkgfile -p post-install $pkgid $current
199 if [ -n "$current" ]; then
200 zpm pkg $pkgid status=installed :$current status=updated
202 zpm pkg $pkgid status=installed
205 if [ $(id -u) -eq 0 ]; then
206 if [ -f $rootdir/sbin/ldconfig ]; then
207 $rootdir/sbin/ldconfig -r ${rootdir:-/}
208 elif [ -f /sbin/ldconfig ]; then
209 /sbin/ldconfig -r ${rootdir:-/}
215 # TODO skip configure if not on a terminal, regardless of settings
216 # TODO will need force option
217 if [ $runconfigure -gt 0 ]; then
218 zpm runscript -f $pkgfile -p configure $pkgid $current