]> pd.if.org Git - zpackage/blobdiff - zpm-ipkgfile
add directories to ipkgfile
[zpackage] / zpm-ipkgfile
index 310a7b7cd569ee75ba1b666ce6f146b9cd5ff591..de9771115dc93029fd78cf978de2281a3fad7673 100755 (executable)
@@ -1,31 +1,34 @@
 #!/bin/sh
 
+# install a file from a package
+# -f pkgfile
+# -R root of pkg
+# -P prefix to file
+# -S strip prefix
+# -p pkgname
+
 pkgroot=/
 
-while getopts :f:v:r:d:a:u:l:p:b:P:R: opt; do
+while getopts :f:v:r:d:a:u:g: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" ;;
+               u) owner="$OPTARG" ;;
+               g) group="$OPTARG" ;;
         esac
 done
 shift $((OPTIND - 1))
 
 die() {
-       echo $* 1&>2
+       echo $* 1>&2
        exit 1
 }
 
 pkgfileinfo() {
-       sqlite3 $pkgfile<<EOS
+       zpm shell $pkgfile<<EOS
 select $1 from packagefiles
        where path='$2'
        and package||'-'||version||'-'||release = '$pkg'
@@ -41,30 +44,58 @@ fi
 pkg="$1"
 shift
 
+ZPMPKGFILE=$pkgfile
+export ZPMPKGFILE
+
 set -e
 for path in $*; do
-       fhash=$(pkgfileinfo hash $path)
-       mode=$(pkgfileinfo mode $path)
-       owner=$(pkgfileinfo username $path)
-       group=$(pkgfileinfo groupname $path)
-       ftype=$(pkgfileinfo filetype $path)
+
        name=$(basename -- $path)
+       dir=$(dirname -- $path)
+       dir=${dir#/}
 
        if [ "$pkgroot" != '/' ]; then
-               dir=$pkgroot/$(dirname -- $path)
+               dir=$pkgroot/$dir
                dir=${dir%/.}
-               if [ "$dir" = "//" ]; then dir=/ ; fi
-       else
-               dir=''
+#              if [ "$dir" = "//" ]; then dir=/ ; fi
        fi
 
+       # TODO generate some unique hash
        tmppath=$dir/.installing.$name
 
-       cat <<-EOC
+       printf '%s installing %s\n' $pkg $dir/$name
+
+       fhash=$(pkgfileinfo hash $path)
+       mode=$(pkgfileinfo mode $path)
+       ftype=$(pkgfileinfo filetype $path)
+       : ${owner:=$(pkgfileinfo username $path)}
+       : ${group:=$(pkgfileinfo groupname $path)}
+
+       # can't use install because it's not posix.
+       # probably worth writing a zpm-install, but with
+       # a different name since that wants to be a package install
+       # probably makes the most sense for extract to know how
+       # to do the extract to temp and such, then
+       # you can just add the -S option (secure)
+       #cat <<-EOC
        mkdir -p $dir
-       zpm extract $pkgfile $fhash $tmppath 0
-       chown $owner:$group $tmppath
-       chmod $mode $tmppath
-       mv $tmppath $dir/$name
-       EOC
+       umask 0700
+       case $ftype in
+               r*) zpm extract $pkgfile $fhash $tmppath
+                       chown $owner:$group $tmppath
+                       chmod $mode $tmppath
+                       # TODO mv -n non-posix, going to need to have extract
+                       # do all of this
+                       mv $tmppath $dir/$name
+                       ;;
+               d*)
+                       mkdir -m 000 $dir/$name
+                       chown $owner:$group $dir/$name
+                       chmod $mode $dir/name
+                       ;;
+
+               *) echo unknown filetype ; exit 1 ;;
+       esac
+
+       #EOC
 done