13 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
14 while getopts f:d:R:nSCv opt; do
16 f) pkgfile="$OPTARG" ;;
17 d) localdb="$OPTARG" ;;
18 R) rootdir="$OPTARG" ;;
26 shift $(( OPTIND - 1))
30 if [ -z "$pkgid" ]; then
31 die "must specify pkgid"
34 eval "$(zpm parse -E $pkgid)"
36 if [ -z "$pkgfile" ]; then
37 pkgfile=$ZPM_PACKAGE_FILE
40 # cases R = full package id, F = specified package file
43 # -- 00 error, must specify something
44 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
45 die must specify package file or complete package id
48 # TODO look in package file
49 # -F 01 error, wouldn't know which pkgid to create, could derive from file?
50 if [ -z "$release" ]; then
51 # must have package file, or would have died above
52 pkgid=$(zpm findpkg -f $pkgfile $pkgid)
53 if [ -n "$pkgid" ]; then
54 eval "$(zpm parse -E $pkgid)"
58 if [ -z "$pkgid" ]; then
59 die "$0 can't figure out a package id"
63 # R- 10 set file from pkgid, create in file, error if no file
64 if [ -z "$pkgfile" ]; then
68 # will now be one of these
69 # RF 11 create package in file, error if file doesn't exist
70 if [ ! -f "$pkgfile" ]; then
71 die $pkgfile does not exist
74 if [ "$idempotent" = 1 ]; then
75 idempotent='or ignore'
78 package=$(zpm quote "$name")
79 pkgver=$(zpm quote "$version")
80 pkgrel=$(zpm quote "$release")
82 if [ -z "$localdb" ]; then
83 : rootdir=${rootdir%%/}
84 localdb=${rootdir:-/}/var/lib/zpm/local.db
87 if [ ! -f "$localdb" ]; then
90 die "aborting install"
97 if [ -z "$ZPMDB" ]; then
100 #echo "localdb = $ZPMDB"
104 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
106 # check if we're installing something already
107 var=$(zpm list -f $localdb -s installing | wc -l)
108 if [ $var -gt 0 ]; then
109 zpm list -v -f $localdb -s installing
110 die "already ($localdb) installing $var package(s)"
112 # check if we're installing something already
113 var=$(zpm list -f $localdb -s removing | wc -l)
114 if [ $var -gt 0 ]; then
115 zpm list -v -f $localdb -s removing
116 die "already ($localdb) removing $var package(s)"
118 var=$(zpm list -f $localdb -s updating | wc -l)
119 if [ $var -gt 0 ]; then
120 zpm list -v -f $localdb -s updating
121 die "already ($localdb) updating $var package(s)"
124 if [ -n "$rootdir" ]; then
125 ZPM_ROOT_DIR="$rootdir"
129 # TODO mark already installed packages as updating?
130 for pkgstr in "$@"; do
131 pkgid=$(zpm findpkg -f $pkgfile $pkgstr)
132 if [ $? -ne 0 ]; then
134 die "can't find package $pkgstr in $pkgfile"
137 curstatus=$(zpm pkg $pkgid status)
138 if [ "$curstatus" = 'installed' ]; then
139 die "$pkgid already installed"
142 eval $(zpm parse -E $pkgid)
145 current=$(zpm list -s installed "$package")
147 if [ $runscripts -gt 0 ]; then
148 zpm runscript -f $pkgfile -p pre-install $pkgid $current
149 if [ $? -ne 0 ]; then
151 die "pre-install script for $pkgid failed"
155 # only merge if localdb and pkgfile are different
156 if [ "$pkgfile" != "$ZPMDB" ]; then
157 zpm merge -f $pkgfile -s installing $pkgid
158 if [ $? -ne 0 ]; then
160 die "merging $pkgid failed"
163 # TODO but need to mark as installing if not merged
165 #zpm shell $ZPMDB 'select * from install_status' 1>&2
166 if [ $dryrun -gt 0 ]; then
168 #zpm shell $ZPMDB 'select * from install_status'
169 zpm syncfs -nv -f $pkgfile
170 zpm pkg $pkgid status=dryrun
174 if [ $verbose -gt 0 ]; then
175 zpm syncfs -v -f $pkgfile
177 zpm syncfs -f $pkgfile
180 if [ $? -ne 0 ]; then
181 die 'zpm-syncfs failed';
184 if [ $runscripts -gt 0 ]; then
185 zpm runscript -f $pkgfile -p post-install $pkgid $current
188 if [ -n "$current" ]; then
189 zpm pkg $pkgid status=installed :$current status=updated
191 zpm pkg $pkgid status=installed
194 if [ $(id -u) -eq 0 ]; then
195 if [ -f $rootdir/sbin/ldconfig ]; then
196 $rootdir/sbin/ldconfig -r ${rootdir:-/}
197 elif [ -f /sbin/ldconfig ]; then
198 /sbin/ldconfig -r ${rootdir:-/}
204 # TODO skip configure if not on a terminal, regardless of settings
205 # TODO will need force option
206 if [ $runconfigure -gt 0 ]; then
207 zpm runscript -f $pkgfile -p configure $pkgid $current