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

index 0f9440c9c928256f2dfb63b663e68833772f7940..310a7b7cd569ee75ba1b666ce6f146b9cd5ff591 100755 (executable)
@@ -1,10 +1,70 @@
 #!/bin/sh
 
-pkgfile=$1
+pkgroot=/
+
+while getopts :f:v:r:d:a:u:l:p:b:P:R: opt; do
+        case $opt in
+                R) pkgroot="$OPTARG" ;;
+                f) pkgfile="$OPTARG" ;;
+                v) pkgver="$OPTARG" ;;
+                r) pkgrel="$OPTARG" ;;
+                d) description="$OPTARG" ;;
+                a) arch="$OPTARG" ;;
+                u) url="$OPTARG" ;;
+                l) licenses="$OPTARG" ;;
+                p) packager="$OPTARG" ;;
+                b) builddate="$OPTARG" ;;
+                P) prefix="$OPTARG" ;;
+        esac
+done
+shift $((OPTIND - 1))
+
+die() {
+       echo $* 1&>2
+       exit 1
+}
+
+pkgfileinfo() {
+       sqlite3 $pkgfile<<EOS
+select $1 from packagefiles
+       where path='$2'
+       and package||'-'||version||'-'||release = '$pkg'
+       ;
+EOS
+}
+
+# if not from a package file, from local db
+if [ -z "$pkgfile" ]; then
+       die "installing from non-pkgfile not supported"
+fi
+
+pkg="$1"
 shift
 
+set -e
 for path in $*; do
-       mkdir -p tmp/$(dirname $path)
-       fhash=$(sqlite3 $pkgfile "select hash from packagefiles where path = '$path';")
-       ./zpm-extract $pkgfile $fhash ./tmp/$path
+       fhash=$(pkgfileinfo hash $path)
+       mode=$(pkgfileinfo mode $path)
+       owner=$(pkgfileinfo username $path)
+       group=$(pkgfileinfo groupname $path)
+       ftype=$(pkgfileinfo filetype $path)
+       name=$(basename -- $path)
+
+       if [ "$pkgroot" != '/' ]; then
+               dir=$pkgroot/$(dirname -- $path)
+               dir=${dir%/.}
+               if [ "$dir" = "//" ]; then dir=/ ; fi
+       else
+               dir=''
+       fi
+
+       tmppath=$dir/.installing.$name
+
+       cat <<-EOC
+       mkdir -p $dir
+       zpm extract $pkgfile $fhash $tmppath 0
+       chown $owner:$group $tmppath
+       chmod $mode $tmppath
+       mv $tmppath $dir/$name
+       EOC
 done