]> pd.if.org Git - zpackage/blobdiff - zpm-newpackage
teach findpkg to parse full or partial package triples
[zpackage] / zpm-newpackage
index fbd44b5afc41c298ff3273f42e87551ff6a17687..66044d942c2057f2ee34c1cbdc871b677cfbf9b7 100755 (executable)
@@ -1,14 +1,21 @@
 #!/bin/sh
 
-package=${1:-$ZPMPACKAGE}
-pkgver=${ZPMPACKAGEVER:-1.0}
-pkgrel=${ZPMPACKAGEREL:-1}
+pkgver=${ZPMPKGVER:-1.0}
+pkgrel=${ZPMPKGREL:-1}
 
 builddate=$(date '+%s')
 
-while getopts :f:v:r:d:a:u:l:p:b: opt; do
+# create a new package in: local, env, arg
+# arg, then env, then local
+
+# the repo given via ZPMDB
+# the repo implied by the arguments
+# the repo in /var/lib/zpm/local.db
+
+while getopts :f:v:r:d:a:u:l:p:b:In: opt; do
        case $opt in
                f) pkgfile="$OPTARG" ;;
+               n) pkgname="$OPTARG" ;;
                v) pkgver="$OPTARG" ;;
                r) pkgrel="$OPTARG" ;;
                d) description="$OPTARG" ;;
@@ -17,21 +24,39 @@ while getopts :f:v:r:d:a:u:l:p:b: opt; do
                l) licenses="$OPTARG" ;;
                p) packager="$OPTARG" ;;
                b) builddate="$OPTARG" ;;
+               I) idempotent=1
        esac
 done
+shift $(( OPTIND - 1))
 
-set -e
+die() {
+       echo $* 1>&2
+       exit 1
+}
+
+package=$1
+shift
+
+if [ -z "$package" ]; then
+       die "must specify package"
+fi
 
 if [ -z "$pkgfile" ]; then
        pkgfile="$package-$pkgver-$pkgrel.zpm"
 fi
 
+set -e
+
 if [ ! -e $pkgfile ]; then
-       sqlite3 $pkgfile < db.sql
+       zpm init $pkgfile
+fi
+
+if [ "$idempotent" = 1 ]; then
+       idempotent='or ignore'
 fi
 
-sqlite3 $pkgfile <<EOS
-insert or ignore into packages ("package", "version", "release", "build_time")
+zpm shell $pkgfile <<EOS
+insert $idempotent into packages ("package", "version", "release", "build_time")
 values ('$package', '$pkgver', $pkgrel, $builddate)
 ;
 EOS