12 localdb=/var/lib/zpm/local.db
14 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
15 while getopts f:d:R:nSCv opt; do
17 f) pkgfile="$OPTARG" ;;
18 d) localdb="$OPTARG" ;;
19 R) rootdir="$OPTARG" ;;
27 shift $(( OPTIND - 1))
31 if [ -z "$pkgid" ]; then
32 die "must specify pkgid"
35 eval "$(zpm parse -E $pkgid)"
37 if [ -z "$pkgfile" ]; then
38 pkgfile=$ZPM_PACKAGE_FILE
41 # cases C = create ok, R = full package id, F = specified package file
44 # C-- 100 error, must specify something
45 # --- 000 error, must specify something
46 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
47 die must specify package file or complete package id
50 # TODO look in package file
51 # --F 001 error, wouldn't know which pkgid to create, could derive from file?
52 # C-F 101 error, since package wouldn't exist in file to find
53 if [ -z "$release" ]; then
54 die must specify complete package id
58 # CR- 110 set file from pkgid, create if needed
59 # -R- 010 set file from pkgid, create in file, error if no file
60 if [ -z "$pkgfile" ]; then
64 # will now be one of these
65 # CRF 111 create package in file given, create file if needed
66 # -RF 011 create package in file, error if file doesn't exist
67 if [ ! -f "$pkgfile" ]; then
68 if [ $create -eq 1 ]; then
71 die $pkgfile does not exist
75 if [ "$idempotent" = 1 ]; then
76 idempotent='or ignore'
79 package=$(zpm quote "$name")
80 pkgver=$(zpm quote "$version")
81 pkgrel=$(zpm quote "$release")
86 if [ -z "$ZPMDB" ]; then
89 #echo "localdb = $ZPMDB"
93 zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database"
95 # check if we're installing something already
96 var=$(zpm list -f $localdb -s installing | wc -l)
97 if [ $var -gt 0 ]; then
98 zpm list -v -f $localdb -s installing
99 die "already ($localdb) installing $var package(s)"
101 # check if we're installing something already
102 var=$(zpm list -f $localdb -s removing | wc -l)
103 if [ $var -gt 0 ]; then
104 zpm list -v -f $localdb -s removing
105 die "already ($localdb) removing $var package(s)"
107 var=$(zpm list -f $localdb -s updating | wc -l)
108 if [ $var -gt 0 ]; then
109 zpm list -v -f $localdb -s updating
110 die "already ($localdb) updating $var package(s)"
113 if [ -n "$rootdir" ]; then
114 ZPM_ROOT_DIR="$rootdir"
118 # TODO mark already installed packages as updating?
119 for pkgstr in "$@"; do
120 pkgid=$(zpm findpkg -f $pkgfile $pkgstr)
121 if [ $? -ne 0 ]; then
123 die "can't find package $pkgstr in $pkgfile"
126 curstatus=$(zpm pkg $pkgid status)
127 if [ "$curstatus" = 'installed' ]; then
128 die "$pkgid already installed"
131 eval $(zpm parse -E $pkgid)
134 current=$(zpm list -s installed "$package")
136 if [ $runscripts -gt 0 ]; then
137 zpm runscript -f $pkgfile -p pre-install $pkgid $current
138 if [ $? -ne 0 ]; then
140 die "pre-install script for $pkgid failed"
144 # only merge if localdb and pkgfile are different
145 if [ "$pkgfile" != "$ZPMDB" ]; then
146 zpm merge -f $pkgfile -s installing $pkgid
147 if [ $? -ne 0 ]; then
149 die "merging $pkgid failed"
152 # TODO but need to mark as installing if not merged
154 #zpm shell $ZPMDB 'select * from install_status' 1>&2
155 if [ $dryrun -gt 0 ]; then
157 #zpm shell $ZPMDB 'select * from install_status'
158 zpm syncfs -nv -f $pkgfile
159 zpm pkg $pkgid status=dryrun
163 zpm syncfs -f $pkgfile
165 if [ $? -ne 0 ]; then
166 die 'zpm-syncfs failed';
169 if [ $runscripts -gt 0 ]; then
170 zpm runscript -f $pkgfile -p post-install $pkgid $current
173 if [ -n "$current" ]; then
174 zpm pkg $pkgid status=installed :$current status=updated
176 zpm pkg $pkgid status=installed
179 # TODO skip configure if not on a terminal, regardless of settings
180 # TODO will need force option
181 if [ $runconfigure -gt 0 ]; then
182 zpm runscript -f $pkgfile -p configure $pkgid $current