#!/bin/sh
-package=${1:-$ZPMPACKAGE}
-shift
+#package=${1:-$ZPMPACKAGE}
pkgver=${ZPMPACKAGEVER:-1.0}
pkgrel=${ZPMPACKAGEREL:-1}
pkgroot=/
+# allocate an install id, perhaps hash package and timestamp
+# installid=$(echo $(date) $pkglist | zpm hash)
+
+# extract pre-scripts and run them
+# get list of paths to install
+# for each path, if directory, create and set mode
+# for each path, create leading directories
+# extract to something like /var/tmp/.hash, with low perms
+# only atomic if same filesystem, so use .installid.hash in the
+# install directory
+# set perms and such
+# move into place
+# after all the files, extract post scripts and run them
+
+# also need to mark package as installing so if it fails part way
+# through, it can be finished later
+# probably also want an option to "backup" any packages being upgraded
+# so it's trivial to downgrade or to revert if the install fails
+
# option for "multipackage" just to let the system know that's what you meant
# option to take filenames from stdin
# parse package, version, release from file if not given
-while getopts :f:v:r:d:a:u:l:p:b:P: opt; do
+# TODO what's the difference between prefix and pkgroot
+# need an option to not chown the files
+# option to install but not merge/track
+while getopts :f:v:r:d:a:u:l:p:b:P:R: opt; do
case $opt in
R) pkgroot="$OPTARG" ;;
f) pkgfile="$OPTARG" ;;
P) prefix="$OPTARG" ;;
esac
done
+shift $((OPTIND - 1))
+
+die() {
+ echo $* 1>&2
+ exit 1
+}
-set -e
if [ -z "$pkgfile" ]; then
+ # actually, if no pkgfile, get pkgfile from repo
+ # but need to loop over finding package files then
+ # so this program probably needs to be "install from pkgfile"
+ # and a separate one that will loop over a package
+ # spec list and find from repos
+ die "must specify package file"
pkgfile="$package-$pkgver-$pkgrel.zpm"
fi
-appid=$(sqlite3 $pkgfile 'pragma application_id;' | ( echo obase = 16; cat - ) | bc)
-if [ "$appid" != "5A504442" ]; then
- echo $pkgfile does not appear to be a zpm package file
- exit 1
+set -e
+zpm test -v $pkgfile
+
+if [ $# -gt 0 ]; then
+ pkglist="$@"
+else
+ pkglist=$(zpm findpkg $pkgfile)
fi
-# check if package exists
-# run preinstall or preupgrade stage, in chroot
-
-# add package info and mark installing to local package database
-# each path: add to local db, extract, set mode/owner/mtime etc.
-# mark install done in local database
-
-for path in $*; do
- mtime=$(stat -c '%Y' $path)
- uid=$(stat -c '%u' $path)
- gid=$(stat -c '%g' $path)
- username=$(stat -c '%U' $path)
- groupname=$(stat -c '%G' $path)
- mode=$(stat -c '%a' $path)
-
- # strip off leading slashes
- rpath=$(echo "$path" | sed -e 's|^/*||')
- # and a leading ./
- rpath=${rpath#./}
- rpath=$(echo "$rpath" | sed -e 's|^/*||')
-
- if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
- continue
- fi
-
- if [ ! -z "$prefix" ]; then
- # trailing slashes on prefix
- prefix=$(echo "$prefix" | sed -e 's|/*$||')
- rpath="$prefix/$rpath"
- fi
-
- if [ -f "$path" ]; then
-
- hash=$(./zpm-addfile $pkgfile $path)
-
-#if [ -z "$hash" ]; then continue; fi
-
-# TODO mtime, mode
-sqlite3 $pkgfile <<EOS
-PRAGMA foreign_keys = ON;
-insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,hash)
-values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$hash')
-;
+pathlist() {
+ zpm shell $pkgfile<<EOS
+select path from packagefiles
+ where package||'-'||version||'-'||release = '$pkg'
+ ;
EOS
-elif [ -d "$path" ]; then
-sqlite3 $pkgfile <<EOS
-PRAGMA foreign_keys = ON;
-insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname)
-values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname')
-;
-EOS
-elif [ -l "$path" ]; then
- target=$(readlink $path)
-sqlite3 $pkgfile <<EOS
-PRAGMA foreign_keys = ON;
-insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,target)
-values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$target')
-;
-EOS
-fi
-#printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
-printf "%s\n" $path
+}
+
+for pkg in $pkglist; do
+ # TODO find scripts marked as pre-install
+ # TODO if this is an upgrade, run pre-upgrade
+
+ # TODO get total size of install so we can do a progress bar
+
+ # add package info to local package db
+ # zpm merge -L -f $pkgfile $pkg
+ # check for conflicts
+ # mark package in localdb as installing
+ # zpm setmark installing $pkg
+ # install all the files for a package
+ # TODO install directories first in order of path length
+ echo installing $pkglist
+ filecount=$(pathlist | wc -l)
+ echo $filecount files
+ pathlist
+ pathlist | xargs -t zpm ipkgfile -R "$pkgroot" -f $pkgfile -- $pkg
+
+ # TODO find scripts marked as post-install
+ # TODO if this is an upgrade, run post-upgrade
+
+ # mark as ready for install
+ #zpm setmark ready $pkg
done
+
+#zpm setmark installed $pkglist