]> pd.if.org Git - zpackage/commitdiff
rewrite zpm-pkg for package metadata
authorNathan Wagner <nw@hydaspes.if.org>
Fri, 10 Aug 2018 05:31:29 +0000 (05:31 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Fri, 10 Aug 2018 05:31:29 +0000 (05:31 +0000)
zpm-pkg

diff --git a/zpm-pkg b/zpm-pkg
index 67f9eb11e968732b99ee2f7b030a9ec4d8044999..663866ed2e0a074da7ce537097ed59c73c435426 100755 (executable)
--- a/zpm-pkg
+++ b/zpm-pkg
@@ -1,37 +1,66 @@
 #!/bin/sh
 
+# edit package metadata
+
 package=${1:-$ZPMPACKAGE}
 pkgver=${ZPMPKGVER:-1.0}
 pkgrel=${ZPMPKGREL:-1}
 
-while getopts :n:v:r:d:a:u:l:p:b: opt; do
+#zpm pkg -s packager=foo zpm
+
+# zpm pkg -f <pkgfile> zpm packager=xyz
+# zpm pkg zpm packager zyz
+# zpm pkg zpm packager
+
+
+pkgfile=${ZPMDB:-/var/lib/zpm/db.zpm}
+
+while getopts f: opt; do
        case $opt in
-               n) 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" ;;
+               f) pkgfile="$OPTARG" ;;
        esac
 done
-
-pkgfile="$package-$pkgver-$pkgrel.zpm"
+shift $((OPTIND - 1))
 
 set -e
 
 if [ ! -f $pkgfile ]; then
-       zpm init $pkgfile
+       echo cannot find $pkgfile
+       exit 1
 fi
 
-for path in $*; do
-       hash=$(zpm addfile $pkgfile $path)
+pkg=$1
+shift
+#printf "pkg: %s\n" $pkg
+pkgid=$(zpm findpkg $pkgfile $pkg)
+
+#printf "pkgid: %s\n" $pkgid
 
+case $1 in
+       status) item=status ;;
+       *) printf 'no such field %s\n' $1; exit 1 ;;
+esac
+
+item=$1
+
+if [ -n "$2" ]; then
+       setting=$2
 zpm shell $pkgfile <<EOS
-insert into packagefiles
-values ('$package', nullif('$subpackage', ''), '$hash', '$path', NULL)
+update packages set $item = '$setting'
+where
+printf('%s-%s-%s', package,version,release) = '$pkgid'
 ;
 EOS
-done
+else
+       setting=$(zpm shell $pkgfile <<EOS
+select $item from packages
+where
+printf('%s-%s-%s', package,version,release) = '$pkgid'
+;
+EOS
+)
+       if [ -n "$setting" ]; then
+               printf '%s\n' "$setting"
+       fi
+fi
+