X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-install;h=be851acf905259657a0ca500c385daa30f838795;hb=d30b60f479a576d52ff6bed022914806aaebdcb8;hp=e722bf321f1ea85b4be8b75427c86d47aeaa6449;hpb=ecdd57da7df775c039aee834e1f74172004f352b;p=zpackage diff --git a/zpm-install b/zpm-install index e722bf3..be851ac 100755 --- a/zpm-install +++ b/zpm-install @@ -1,16 +1,37 @@ #!/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" ;; @@ -25,78 +46,60 @@ while getopts :f:v:r:d:a:u:l:p:b:P: opt; do 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 < $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 + pathlist | xargs 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