]> pd.if.org Git - zpackage/commitdiff
cleanup makefile and other files
authorNathan Wagner <nw@hydaspes.if.org>
Mon, 24 Sep 2018 23:10:57 +0000 (23:10 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 24 Sep 2018 23:10:57 +0000 (23:10 +0000)
.gitignore
Makefile
zpm-setscript [new file with mode: 0755]

index 8c399ace2d6dca15a14cb45e2c58f75d6b7ecaf0..7251c0d89a652647a1eccd9af189584a358420bf 100644 (file)
@@ -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
index 641e9129cfc2ca296eb1ca656714fc204af272d0..057711855b510d51bbd1780c5b425e71cadcaf41 100644 (file)
--- 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 (executable)
index 0000000..1b055fd
--- /dev/null
@@ -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 <<EOS
+       zpm shell $pkgfile <<EOS
+PRAGMA foreign_keys = ON;
+begin;
+insert or replace into scripts (package,version,release,stage,hash)
+values ('$package', '$pkgver', $pkgrel, '$stage', '$hash');
+commit;
+EOS
+
+#printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
+#printf "%s\n" $path
+)
+
+removescript() (
+       stage=$1
+       stage=$(zpm quote "$stage")
+
+       #cat <<EOS
+       zpm shell $pkgfile <<EOS
+PRAGMA foreign_keys = ON;
+begin;
+delete from scripts 
+where package = '$package' and version = '$pkgver' and release = $pkgrel
+and stage = '$stage'
+;
+commit;
+EOS
+
+#printf "%s %s%s\n" $path $rpath ${target:+" -> $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