]> pd.if.org Git - zpackage/blobdiff - zpm-addtopackage
add -f pkgfile option to addtopackage
[zpackage] / zpm-addtopackage
index f096ea2eaef6c6eb2c2b0a2ec20c8d2c2720e0f2..a3b045b04c8f9330751a89a778c301dfe451bff5 100755 (executable)
@@ -1,7 +1,5 @@
 #!/bin/sh
 
-package=${1:-$ZPMPACKAGE}
-shift
 pkgver=${ZPMPKGVER:-1.0}
 pkgrel=${ZPMPKGREL:-1}
 
@@ -20,31 +18,40 @@ while getopts :f:v:r:d:a:u:l:p:b:P: opt; do
                p) packager="$OPTARG" ;;
                b) builddate="$OPTARG" ;;
                P) prefix="$OPTARG" ;;
+               t) tags="$OPTARG" ;;
+               c) tags="$tags +configuration" ;;
        esac
 done
+shift $((OPTIND - 1))
+
+die() {
+       echo $* 1&>2
+       exit 1
+}
+
+package="$1"
+shift
+if [ -z "$package" ]; then
+       die "must specify package"
+fi
 
 set -e
 if [ -z "$pkgfile" ]; then
        pkgfile="$package-$pkgver-$pkgrel.zpm"
 fi
 
-if [ ! -f $pkgfile ]; then
-       zpm newpackage $package || exit 1
-else
-       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
-       fi
-fi
+# make sure package exists
+zpm newpackage -I -f $pkgfile -v $pkgver -r $pkgrel $package || exit 1
+
+zpm test -v $pkgfile
 
 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)
+       mtime=$(zpm stat -f '%y' $path)
+       uid=$(zpm stat -f '%u' $path)
+       gid=$(zpm stat -f '%g' $path)
+       username=$(zpm stat -f '%U' $path)
+       groupname=$(zpm stat -f '%G' $path)
+       mode=$(zpm stat -f '%a' $path)
 
        # strip off leading slashes
        rpath=$(echo "$path" | sed -e 's|^/*||')
@@ -62,35 +69,36 @@ for path in $*; do
                rpath="$prefix/$rpath"
        fi
 
-       if [ -f "$path" ]; then
-
-               hash=$(zpm addfile $pkgfile $path)
-
-#if [ -z "$hash" ]; then continue; fi
+       filetype=$(zpm stat -f '%t' "$path")
+       hash='NULL'
+       target='NULL'
+       case "$filetype" in
+               regular)
+                       filetype=r
+                       hash=$(zpm addfile $pkgfile "$path")
+                       if [ $? -ne 0 ]; then
+                               die "zpm addfile failed ($?): $pkgfile $path" 
+                       fi
+                       hash="'$hash'"
+                       ;;
+               directory)
+                       filetype=d
+                       ;;
+               symlink)
+                       filetype=l
+                       target=$(readlink $path)
+                       target="'$target'"
+                       ;;
+       esac
 
-# 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
+       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')
-;
+begin;
+insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
+values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
+commit;
 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
 done