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
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 installing 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 # TODO mark already installed packages as updating?
123 for pkgstr in "$@"; do
124 pkgid=$(zpm findpkg -f $pkgfile $pkgstr)
125 if [ $? -ne 0 ]; then
127 die "can't find package $pkgstr in $pkgfile"
130 curstatus=$(zpm pkg $pkgid status)
131 if [ "$curstatus" = 'installed' ]; then
132 die "$pkgid already installed"
135 eval $(zpm parse -E $pkgid)
138 current=$(zpm list -s installed "$package")
140 if [ $runscripts -gt 0 ]; then
141 zpm runscript -f $pkgfile -p pre-install $pkgid $current
142 if [ $? -ne 0 ]; then
144 die "pre-install script for $pkgid failed"
148 # only merge if localdb and pkgfile are different
149 if [ "$pkgfile" != "$ZPMDB" ]; then
150 zpm merge -f $pkgfile -s installing $pkgid
151 if [ $? -ne 0 ]; then
153 die "merging $pkgid failed"
156 # TODO but need to mark as installing if not merged
158 #zpm shell $ZPMDB 'select * from install_status' 1>&2
159 if [ $dryrun -gt 0 ]; then
161 #zpm shell $ZPMDB 'select * from install_status'
162 zpm syncfs -nv -f $pkgfile
163 zpm pkg $pkgid status=dryrun
167 if [ $verbose -gt 0 ]; then
168 zpm syncfs -v -f $pkgfile
170 zpm syncfs -f $pkgfile
173 if [ $? -ne 0 ]; then
174 die 'zpm-syncfs failed';
177 if [ $runscripts -gt 0 ]; then
178 zpm runscript -f $pkgfile -p post-install $pkgid $current
181 if [ -n "$current" ]; then
182 zpm pkg $pkgid status=installed :$current status=updated
184 zpm pkg $pkgid status=installed
187 if [ $(id -u) -eq 0 ]; then
191 # TODO skip configure if not on a terminal, regardless of settings
192 # TODO will need force option
193 if [ $runconfigure -gt 0 ]; then
194 zpm runscript -f $pkgfile -p configure $pkgid $current