#!/bin/sh die() { echo $* 1>&2 exit 1 } dryrun=0 verbose=0 runscripts=1 runconfigure=1 localdb=/var/lib/zpm/local.db absorb=0 # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ... while getopts f:d:R:nSCvA opt; do case $opt in A) absorb=1 ;; f) pkgfile="$OPTARG" ;; d) localdb="$OPTARG" ;; R) rootdir="$OPTARG" ;; S) runscripts=0 ;; C) runconfigure=0 ;; n) dryrun=1 ;; v) verbose=1 ;; *) die "usage ..." ;; 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 # TODO look in package file # --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 if [ "$idempotent" = 1 ]; then idempotent='or ignore' fi package=$(zpm quote "$name") pkgver=$(zpm quote "$version") pkgrel=$(zpm quote "$release") ZPMDB=$localdb export ZPMDB if [ -z "$ZPMDB" ]; then die "no local db" else #echo "localdb = $ZPMDB" true fi zpm test -v "$ZPMDB" || die "$ZPMDB is not a zpm database" # check if we're installing something already var=$(zpm list -f $localdb -s installing | wc -l) if [ $var -gt 0 ]; then zpm list -v -f $localdb -s installing die "already ($localdb) installing $var package(s)" fi if [ -n "$rootdir" ]; then ZPM_ROOT_DIR="$rootdir" export ZPM_ROOT_DIR fi for pkgstr in "$@"; do echo removing $pkgstr from $ZPMDB pkgid=$(zpm findpkg -s installed -f $ZPMDB $pkgstr) if [ $? -ne 0 ]; then die "$pkgid is not installed" fi eval $(zpm parse -E $pkgid) echo found $name $version $release if [ $runscripts -gt 0 ]; then zpm script -r -f $pkgfile -p pre-uninstall $pkgid $current if [ $? -ne 0 ]; then # TODO log die "pre-uninstall script for $pkgid failed" fi fi zpm pkg $pkgid status=removing #zpm shell $ZPMDB 'select * from install_status' 1>&2 if [ $dryrun -gt 0 ]; then zpm syncfs -nv zpm pkg $pkgid status=dryrun continue fi zpm syncfs if [ $? -ne 0 ]; then die 'zpm-pkgfiles failed'; fi zpm pkg $pkgid status=removed if [ $runscripts -gt 0 ]; then zpm script -r -p post-uninstall $pkgid fi done