]> pd.if.org Git - zpackage/commitdiff
add create option to zpm-newpackage
authorNathan Wagner <nw@hydaspes.if.org>
Sat, 15 Sep 2018 11:42:41 +0000 (11:42 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 17 Sep 2018 12:16:13 +0000 (12:16 +0000)
Use environment variable ZPM_PACKAGE_FILE for package file name or
construct from package id.

zpm-newpackage

index 66044d942c2057f2ee34c1cbdc871b677cfbf9b7..d64690b552f7c3ff591eb9bb7030629daa25336d 100755 (executable)
@@ -1,27 +1,19 @@
 #!/bin/sh
 
-pkgver=${ZPMPKGVER:-1.0}
-pkgrel=${ZPMPKGREL:-1}
-
 builddate=$(date '+%s')
 
-# 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
+create=0
+
+while getopts :Cf: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" ;;
                a) arch="$OPTARG" ;;
                u) url="$OPTARG" ;;
                l) licenses="$OPTARG" ;;
+               C) create=1 ;;
                p) packager="$OPTARG" ;;
                b) builddate="$OPTARG" ;;
                I) idempotent=1
@@ -34,27 +26,45 @@ die() {
        exit 1
 }
 
-package=$1
+pkgid=$1
 shift
 
-if [ -z "$package" ]; then
-       die "must specify package"
+if [ -z "$pkgid" ]; then
+       die "must specify pkgid"
+fi
+
+eval "$(zpm parse -E $pkgid)"
+
+if [ -z "$release" ]; then
+       die 'must specify full package id'
 fi
 
 if [ -z "$pkgfile" ]; then
-       pkgfile="$package-$pkgver-$pkgrel.zpm"
+       pkgfile=$ZPM_PACKAGE_FILE
+fi
+
+if [ -z "$pkgfile" ]; then
+       pkgfile="$pkgid.zpm"
 fi
 
 set -e
 
 if [ ! -e $pkgfile ]; then
-       zpm init $pkgfile
+       if [ $create -eq 1 ]; then
+               zpm init $pkgfile
+       else
+               die "$pkgfile does not exist"
+       fi
 fi
 
 if [ "$idempotent" = 1 ]; then
        idempotent='or ignore'
 fi
 
+package=$(zpm quote "$name")
+pkgver=$(zpm quote "$version")
+pkgrel=$(zpm quote "$release")
+
 zpm shell $pkgfile <<EOS
 insert $idempotent into packages ("package", "version", "release", "build_time")
 values ('$package', '$pkgver', $pkgrel, $builddate)