X-Git-Url: https://pd.if.org/git/?p=zpackage;a=blobdiff_plain;f=bin%2Fzpm-newpackage;fp=bin%2Fzpm-newpackage;h=a92cea378c61c4032dfc904b40428c2d2ec09b08;hp=0000000000000000000000000000000000000000;hb=0419c62f964b259df1c1816f5870ef62eb97ed7c;hpb=0c2216d1e0dc8565a6bf61c9572e47bb1ae1c1fb diff --git a/bin/zpm-newpackage b/bin/zpm-newpackage new file mode 100755 index 0000000..a92cea3 --- /dev/null +++ b/bin/zpm-newpackage @@ -0,0 +1,115 @@ +#!/bin/sh + +builddate=$(date '+%s') + +# the repo implied by the arguments + +create=0 + +# newpackage -f pkgfile $pkgid +while getopts :Cf:r:d:a:u:l:p:b:In: opt; do + case $opt in + f) pkgfile="$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 + esac +done +shift $(( OPTIND - 1)) + +die() { + echo $* 1>&2 + exit 1 +} + +pkgid=$1 +shift + +if [ -z "$pkgid" ]; then + die "must specify pkgid" +fi + +eval "$(zpm parse -E $pkgid)" + +if [ -z "$pkgfile" ]; then + pkgfile=$ZPM_PACKAGE_FILE +fi + +# cases C = create ok, R = full package id, F = specified package file + +# immediate error +# C-- 100 error, must specify something +# --- 000 error, must specify something +if [ -z "$release" ] && [ -z "$pkgfile" ]; then + die must specify package file or complete package id +fi + +# --F 001 error, wouldn't know which pkgid to create, could derive from file? +# C-F 101 error, since package wouldn't exist in file to find +if [ -z "$release" ]; then + die must specify complete package id +fi + +# set file from pkgid +# CR- 110 set file from pkgid, create if needed +# -R- 010 set file from pkgid, create in file, error if no file +if [ -z "$pkgfile" ]; then + pkgfile="$pkgid.zpm" +fi + +# will now be one of these +# CRF 111 create package in file given, create file if needed +# -RF 011 create package in file, error if file doesn't exist +if [ ! -f "$pkgfile" ]; then + if [ $create -eq 1 ]; then + zpm init $pkgfile + else + die $pkgfile does not exist + fi +fi + +set -e + +if [ "$idempotent" = 1 ]; then + idempotent='or ignore' +fi + +package=$(zpm quote "$name") +pkgver=$(zpm quote "$version") +pkgrel=$(zpm quote "$release") +if [ -n "$description" ]; then + description=$(zpm quote -q "$description") +else + description=NULL +fi + +if [ -n "$licenses" ]; then + licenses=$(zpm quote -q "$licenses") +else + licenses=NULL +fi + +if [ -n "$packager" ]; then + packager=$(zpm quote -q "$packager") +else + packager=NULL +fi +if [ -n "$url" ]; then + url=$(zpm quote -q "$url") +else + url=NULL +fi + +zpm shell $pkgfile <