#!/bin/sh die() { echo $* 1>&2 exit 1 } dryrun=0 runscripts=1 runconfigure=1 localdb=/var/lib/zpm/local.db # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ... while getopts :f:d:R:nSC opt; do case $opt in f) pkgfile="$OPTARG" ;; d) localdb="$OPTARG" ;; R) rootdir="$OPTARG" ;; S) runscripts=0 ;; C) runconfigure=0 ;; n) dryrun=1 esac done shift $(( OPTIND - 1)) pkgid=$1 if [ -z "$pkgid" ]; then die "must specify pkgid" fi eval "$(zpm parse -E $pkgid)" if [ -z "$pkgfile" ]; then pkgfile=$ZPM_PACKAGE_FILE fi # cases C = create ok, R = full package id, F = specified package file # immediate error # C-- 100 error, must specify something # --- 000 error, must specify something if [ -z "$release" ] && [ -z "$pkgfile" ]; then die must specify package file or complete package id fi # --F 001 error, wouldn't know which pkgid to create, could derive from file? # C-F 101 error, since package wouldn't exist in file to find if [ -z "$release" ]; then die must specify complete package id fi # set file from pkgid # CR- 110 set file from pkgid, create if needed # -R- 010 set file from pkgid, create in file, error if no file if [ -z "$pkgfile" ]; then pkgfile="$pkgid.zpm" fi # will now be one of these # CRF 111 create package in file given, create file if needed # -RF 011 create package in file, error if file doesn't exist if [ ! -f "$pkgfile" ]; then if [ $create -eq 1 ]; then zpm init $pkgfile else die $pkgfile does not exist fi fi set -e if [ "$idempotent" = 1 ]; then idempotent='or ignore' fi package=$(zpm quote "$name") pkgver=$(zpm quote "$version") pkgrel=$(zpm quote "$release") ZPMDB=$localdb export ZPMDB # check if we're installing something already var=$(zpm list -f $localdb -s installing | wc -l) if [ $var -ge 0 ]; then die 'already installing' fi if [ -n "$rootdir" ]; ZPM_ROOT_DIR="$rootdir" export ZPM_ROOT_DIR fi # TODO mark already installed packages as updating? for pkgstr in "$@"; do pkgid=$(zpm findpkg -f $pkgfile $pkgstr) if [ $? -ne 0 ]; then # TODO log die "can't find package $pkgstr in $pkgfile" fi curstatus=$(zpm pkg $pkgid status) if [ "$curstatus" = 'installed' ]; then die "$pkgid already installed" fi eval $(zpm parse -E $pkgid) current=$(zpm list -s installed "$package") if [ $runscripts -gt 0 ]; then zpm runscript -f $packagefile -p pre-install $pkgid $current if [ $? -ne 0 ]; then # TODO log die "pre-install script for $pkgid failed" fi fi # only merge if localdb and pkgfile are different if [ "$pkgfile" != "$ZPMDB" ]; then zpm merge -f $pkgfile -s installing $pkgid if [ $? -ne 0 ]; then # TODO log die "merging $pkgid failed" fi fi zpm pkgfiles -f $pkgfile $pkgid if [ $runscripts -gt 0 ]; then zpm runscript -f $pkgfile -p post-install $pkgid $current fi # need a way to update multiple statuses all in one # zpm pkgstatus $pkgid installed $pkgid updated zpm pkg $pkgid status installed if [ $runconfigure -gt 0 ]; then zpm runscript -f $pkgfile -p configure $pkgid $current fi done