From: Nathan Wagner Date: Mon, 24 Sep 2018 23:10:57 +0000 (+0000) Subject: cleanup makefile and other files X-Git-Tag: v0.1.7~26 X-Git-Url: https://pd.if.org/git/?p=zpackage;a=commitdiff_plain;h=b7a4dd34227b6cf84908ffde9f2c4395f29fe1b4 cleanup makefile and other files --- diff --git a/.gitignore b/.gitignore index 8c399ac..7251c0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ elftype *.o *.a +*~ uncompress zpm-addfile zpm-foreach-path @@ -8,11 +9,15 @@ zpm-vercmp zpm-extract zpm-init zpm-soneed +zpm-soname +zpm-parse +zpm-quote zpm-hash zpm-stat zpm-findpkg zpm-shell zpm-runscript +zpm-pkgfiles *.zpm *.db soname @@ -20,3 +25,4 @@ compress newdb.c test.* t/test.* +t/ctap/prove diff --git a/Makefile b/Makefile index 641e912..0577118 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ curdir=$(shell pwd) ZPKGBIN=zpm-addfile zpm-extract zpm-init zpm-vercmp zpm-stat zpm-hash \ zpm-findpkg zpm-shell zpm-soneed zpm-foreach-path zpm-parse \ - zpm-runscript + zpm-runscript zpm-soname SCRIPTS=zpm zpm-install zpm-merge zpm-list zpm-preserve zpm-test zpm-log \ zpm-contents diff --git a/zpm-setscript b/zpm-setscript new file mode 100755 index 0000000..1b055fd --- /dev/null +++ b/zpm-setscript @@ -0,0 +1,147 @@ +#!/bin/sh + +# zpm add -f pkgfile pkgid [ files ] + +# no package file? take from ZPM_PACKAGE_FILE +# no pkgid ? take from ZPM_PACKAGE_ID +# no id impossible + +die() { + echo $* 1>&2 + exit 1 +} + +while getopts :f: opt; do + case $opt in + f) pkgfile="$OPTARG" ;; + *) echo 'zpm-setscript unknown option' $opt; exit 1 ;; + esac +done +shift $((OPTIND - 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 R = full package id, F = specified package file + +# immediate error +# --- 000 error, must specify something +if [ -z "$release" ] && [ -z "$pkgfile" ]; then + die must specify package file or complete package id +fi + +# try to get from package file +if [ -z "$release" ]; then + pkgid=$(zpm findpkg $pkgfile $pkgid) + if [ -z "$pkgid" ]; then + die cannot find package id + fi + eval "$(zpm parse -E $pkgid)" +fi + +# --F 001 error, wouldn't know which pkgid to create, could derive from file? +if [ -z "$release" ]; then + die must specify complete package id +fi + +#echo "have '$pkgid' '$pkgfile'" + +# set file from pkgid +# -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 +# -RF 011 create package in file, error if file doesn't exist +if [ ! -f "$pkgfile" ]; then + die $pkgfile does not exist +fi + +set -e + +if [ "$idempotent" = 1 ]; then + idempotent='or ignore' +fi + +package=$(zpm quote "$name") +pkgver=$(zpm quote "$version") +pkgrel=$(zpm quote "$release") + +# args are stage and script + +addscript() ( + stage=$1 + path=$2 + + #echo adding $path + if [ ! -f "$script" ]; then + die "$script is not a regular file" + fi + hash=$(zpm addfile $pkgfile "$path") + if [ $? -ne 0 ]; then + die "zpm addfile failed ($?): $pkgfile $path" + fi + #echo adding script $hash $path + hash=$(zpm quote "$hash") + + stage=$(zpm quote "$stage") + + #cat < $target"} +#printf "%s\n" $path +) + +removescript() ( + stage=$1 + stage=$(zpm quote "$stage") + + #cat < $target"} +#printf "%s\n" $path +) + +# TODO better syntax for showing the script +# TODO a way to set the script hash directly +while [ $# -gt 1 ]; do + stage=$1 + script=$2 + shift 2 + + if [ "$script" = '-' ]; then + removescript "$stage" + elif [ -z "$script" ]; then + showscript "$stage" + else + addscript "$stage" "$script" + fi + +done