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
94 if [ -z "$ZPMDB" ]; then
97 #echo "localdb = $ZPMDB"
101 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
103 # check if we're installing something already
104 var=$(zpm list -f $localdb -s installing | wc -l)
105 if [ $var -gt 0 ]; then
106 zpm list -v -f $localdb -s installing
107 die "already ($localdb) installing $var package(s)"
109 # check if we're installing something already
110 var=$(zpm list -f $localdb -s removing | wc -l)
111 if [ $var -gt 0 ]; then
112 zpm list -v -f $localdb -s removing
113 die "already ($localdb) removing $var package(s)"
115 var=$(zpm list -f $localdb -s updating | wc -l)
116 if [ $var -gt 0 ]; then
117 zpm list -v -f $localdb -s updating
118 die "already ($localdb) updating $var package(s)"
121 if [ -n "$rootdir" ]; then
122 ZPM_ROOT_DIR="$rootdir"
126 # TODO mark already installed packages as updating?
127 for pkgstr in "$@"; do
128 pkgid=$(zpm findpkg -f $pkgfile $pkgstr)
129 if [ $? -ne 0 ]; then
131 die "can't find package $pkgstr in $pkgfile"
134 curstatus=$(zpm pkg $pkgid status)
135 if [ "$curstatus" = 'installed' ]; then
136 die "$pkgid already installed"
139 eval $(zpm parse -E $pkgid)
142 current=$(zpm list -s installed "$package")
144 if [ $runscripts -gt 0 ]; then
145 zpm runscript -f $pkgfile -p pre-install $pkgid $current
146 if [ $? -ne 0 ]; then
148 die "pre-install script for $pkgid failed"
152 # only merge if localdb and pkgfile are different
153 if [ "$pkgfile" != "$ZPMDB" ]; then
154 zpm merge -f $pkgfile -s installing $pkgid
155 if [ $? -ne 0 ]; then
157 die "merging $pkgid failed"
160 # TODO but need to mark as installing if not merged
162 #zpm shell $ZPMDB 'select * from install_status' 1>&2
163 if [ $dryrun -gt 0 ]; then
165 #zpm shell $ZPMDB 'select * from install_status'
166 zpm syncfs -nv -f $pkgfile
167 zpm pkg $pkgid status=dryrun
171 if [ $verbose -gt 0 ]; then
172 zpm syncfs -v -f $pkgfile
174 zpm syncfs -f $pkgfile
177 if [ $? -ne 0 ]; then
178 die 'zpm-syncfs failed';
181 if [ $runscripts -gt 0 ]; then
182 zpm runscript -f $pkgfile -p post-install $pkgid $current
185 if [ -n "$current" ]; then
186 zpm pkg $pkgid status=installed :$current status=updated
188 zpm pkg $pkgid status=installed
191 if [ $(id -u) -eq 0 ]; then
195 # TODO skip configure if not on a terminal, regardless of settings
196 # TODO will need force option
197 if [ $runconfigure -gt 0 ]; then
198 zpm runscript -f $pkgfile -p configure $pkgid $current