#!/bin/sh
+# edit package metadata
+
package=${1:-$ZPMPACKAGE}
-pkgver=${ZPMPACKAGEVER:-1.0}
-pkgrel=${ZPMPACKAGEREL:-1}
+pkgver=${ZPMPKGVER:-1.0}
+pkgrel=${ZPMPKGREL:-1}
+
+#zpm pkg -s packager=foo zpm
+
+# zpm pkg -f <pkgfile> zpm packager=xyz
+# zpm pkg zpm packager zyz
+# zpm pkg zpm packager
+
-while getopts :n:v:r:d:a:u:l:p:b: opt; do
+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
+shift $((OPTIND - 1))
-pkgfile="$package-$pkgver-$pkgrel.zpm"
+set -e
if [ ! -f $pkgfile ]; then
- echo $pkgfile missing 1>&2
+ echo cannot find $pkgfile
exit 1
fi
-for path in $*; do
-hash=$(./zpm-addfile $pkgfile $path)
-
-sqlite3 $pkgfile <<EOS
-create table if not exists packagefiles (
- package text,
- subpackage text, -- libs, dev, client, server, whatever
- hash text,
- path text,
- filetype text -- e.g. config, etc?
-);
-insert into packagefiles
-values ('$package', nullif('$subpackage', ''), '$hash', '$path', NULL)
+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
+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
+