11 localdb=/var/lib/zpm/local.db
13 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ...
14 while getopts :f:d:R:nSC opt; do
16 f) pkgfile="$OPTARG" ;;
17 d) localdb="$OPTARG" ;;
18 R) rootdir="$OPTARG" ;;
24 shift $(( OPTIND - 1))
28 if [ -z "$pkgid" ]; then
29 die "must specify pkgid"
32 eval "$(zpm parse -E $pkgid)"
34 if [ -z "$pkgfile" ]; then
35 pkgfile=$ZPM_PACKAGE_FILE
38 # cases C = create ok, R = full package id, F = specified package file
41 # C-- 100 error, must specify something
42 # --- 000 error, must specify something
43 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
44 die must specify package file or complete package id
47 # --F 001 error, wouldn't know which pkgid to create, could derive from file?
48 # C-F 101 error, since package wouldn't exist in file to find
49 if [ -z "$release" ]; then
50 die must specify complete package id
54 # CR- 110 set file from pkgid, create if needed
55 # -R- 010 set file from pkgid, create in file, error if no file
56 if [ -z "$pkgfile" ]; then
60 # will now be one of these
61 # CRF 111 create package in file given, create file if needed
62 # -RF 011 create package in file, error if file doesn't exist
63 if [ ! -f "$pkgfile" ]; then
64 if [ $create -eq 1 ]; then
67 die $pkgfile does not exist
73 if [ "$idempotent" = 1 ]; then
74 idempotent='or ignore'
77 package=$(zpm quote "$name")
78 pkgver=$(zpm quote "$version")
79 pkgrel=$(zpm quote "$release")
84 # check if we're installing something already
85 var=$(zpm list -f $localdb -s installing | wc -l)
86 if [ $var -ge 0 ]; then
87 die 'already installing'
91 ZPM_ROOT_DIR="$rootdir"
95 # TODO mark already installed packages as updating?
96 for pkgstr in "$@"; do
97 pkgid=$(zpm findpkg -f $pkgfile $pkgstr)
100 die "can't find package $pkgstr in $pkgfile"
103 curstatus=$(zpm pkg $pkgid status)
104 if [ "$curstatus" = 'installed' ]; then
105 die "$pkgid already installed"
108 eval $(zpm parse -E $pkgid)
110 current=$(zpm list -s installed "$package")
112 if [ $runscripts -gt 0 ]; then
113 zpm runscript -f $packagefile -p pre-install $pkgid $current
114 if [ $? -ne 0 ]; then
116 die "pre-install script for $pkgid failed"
120 # only merge if localdb and pkgfile are different
121 if [ "$pkgfile" != "$ZPMDB" ]; then
122 zpm merge -f $pkgfile -s installing $pkgid
123 if [ $? -ne 0 ]; then
125 die "merging $pkgid failed"
129 zpm pkgfiles -f $pkgfile $pkgid
130 if [ $runscripts -gt 0 ]; then
131 zpm runscript -f $pkgfile -p post-install $pkgid $current
133 # need a way to update multiple statuses all in one
134 # zpm pkgstatus $pkgid installed $pkgid updated
135 zpm pkg $pkgid status installed
136 if [ $runconfigure -gt 0 ]; then
137 zpm runscript -f $pkgfile -p configure $pkgid $current