]> pd.if.org Git - zpackage/commitdiff
general zpm-install work
authorNathan Wagner <nw@hydaspes.if.org>
Fri, 31 Mar 2017 04:55:36 +0000 (23:55 -0500)
committerNathan Wagner <nw@hydaspes.if.org>
Fri, 31 Mar 2017 05:05:18 +0000 (00:05 -0500)
zpm-install

index 8123b9ba4c90967fa99d1c0d124ef6f43e371873..487740ddc4dbca063b3cbab96d1177dfa7a60bab 100755 (executable)
@@ -1,7 +1,6 @@
 #!/bin/sh
 
-package=${1:-$ZPMPACKAGE}
-shift
+#package=${1:-$ZPMPACKAGE}
 pkgver=${ZPMPACKAGEVER:-1.0}
 pkgrel=${ZPMPACKAGEREL:-1}
 
@@ -22,7 +21,7 @@ pkgroot=/
 # 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
+while getopts :f:v:r:d:a:u:l:p:b:P:R: opt; do
        case $opt in
                R) pkgroot="$OPTARG" ;;
                f) pkgfile="$OPTARG" ;;
@@ -37,78 +36,56 @@ while getopts :f:v:r:d:a:u:l:p:b:P: opt; do
                P) prefix="$OPTARG" ;;
        esac
 done
+shift $((OPTIND - 1))
 
 set -e
 if [ -z "$pkgfile" ]; then
+       # actually, if no pkgfile, get pkgfile from repo
        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
+die() {
+       echo $* 1&>2
        exit 1
-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)
+set -e
+zpm test -v $pkgfile
+set +e
 
-       # strip off leading slashes
-       rpath=$(echo "$path" | sed -e 's|^/*||')
-       # and a leading ./
-       rpath=${rpath#./}
-       rpath=$(echo "$rpath" | sed -e 's|^/*||')
+if [ $# -gt 0 ]; then
+       pkglist="$@"
+else
+       pkglist=$(zpm findpkg $pkgfile)
+fi
 
-       if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
-               continue
-       fi
+pathlist() {
+       sqlite3 $pkgfile<<EOS
+select path from packagefiles
+       where package||'-'||version||'-'||release = '$pkg'
+       ;
+EOS
+}
 
-       if [ ! -z "$prefix" ]; then
-               # trailing slashes on prefix
-               prefix=$(echo "$prefix" | sed -e 's|/*$||')
-               rpath="$prefix/$rpath"
-       fi
+for pkg in $pkglist; do
+       # TODO find scripts marked as pre-install
+       # TODO if this is an upgrade, run pre-upgrade
 
-       if [ -f "$path" ]; then
+       # TODO get total size of install so we can do a progress bar
 
-               hash=$(./zpm-addfile $pkgfile $path)
+       # add package info to local package db
+       # zpm merge -L -f $pkgfile $pkg
+       # 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 
 
-#if [ -z "$hash" ]; then continue; fi
+       # TODO find scripts marked as post-install
+       # TODO if this is an upgrade, run post-upgrade
 
-# 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')
-;
-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
+       # mark as ready for install
+       #zpm setmark ready $pkg
 done
+
+#zpm setmark installed $pkglist