]> pd.if.org Git - zpackage/commitdiff
add zpm-test program to check for valid zpm db files
authorNathan Wagner <nw@hydaspes.if.org>
Wed, 22 Mar 2017 21:09:02 +0000 (16:09 -0500)
committerNathan Wagner <nw@hydaspes.if.org>
Fri, 31 Mar 2017 05:03:41 +0000 (00:03 -0500)
t/zpmtest.t [new file with mode: 0755]
zpm-test [new file with mode: 0755]

diff --git a/t/zpmtest.t b/t/zpmtest.t
new file mode 100755 (executable)
index 0000000..89dfe08
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# test addfile
+
+. tap.sh
+
+plan 3
+
+PF=test.db
+
+rm -f $PF
+touch $PF
+
+zpm-test $PF
+failsok empty file is not zpm file
+rm -f $PF
+
+appid=$(sqlite3 $PF 'pragma application_id')
+zpm-test $PF
+failsok empty db is not zpm file
+rm -f $PF
+
+zpm-init $PF
+zpm-test $PF
+okexit 'new init db is zpm file'
+
+finish
+
+rm -f test.*
diff --git a/zpm-test b/zpm-test
new file mode 100755 (executable)
index 0000000..9f74718
--- /dev/null
+++ b/zpm-test
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# tests a package file
+
+# just checks that all args are valid pkg files
+verbose=0
+
+while getopts v opt; do
+        case $opt in
+                v) verbose=1 ;;
+        esac
+done
+
+for pkgfile in "$@"; do
+appid=$(sqlite3 $pkgfile 'pragma application_id;' | ( echo obase = 16; cat - ) | bc)
+if [ "$appid" != "5A504442" ]; then
+       if [ "$verbose" -eq 1 ]; then
+               echo $pkgfile does not appear to be a zpm package file 1>&2
+       fi
+       exit 1
+fi
+done
+
+exit 0