From bd46218e36b09bc89497dd8aa5426d6610cd240c Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Wed, 22 Mar 2017 16:09:02 -0500 Subject: [PATCH] add zpm-test program to check for valid zpm db files --- t/zpmtest.t | 29 +++++++++++++++++++++++++++++ zpm-test | 24 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100755 t/zpmtest.t create mode 100755 zpm-test diff --git a/t/zpmtest.t b/t/zpmtest.t new file mode 100755 index 0000000..89dfe08 --- /dev/null +++ b/t/zpmtest.t @@ -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 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 -- 2.40.0