From: Nathan Wagner Date: Fri, 10 Aug 2018 05:29:36 +0000 (+0000) Subject: add zpm-log X-Git-Tag: v0.1.6~77 X-Git-Url: https://pd.if.org/git/?p=zpackage;a=commitdiff_plain;h=91e3c24b2f974c3f727e18c27001bcd1c8cb0ecc add zpm-log --- diff --git a/zpm-log b/zpm-log new file mode 100755 index 0000000..198a407 --- /dev/null +++ b/zpm-log @@ -0,0 +1,70 @@ +#!/bin/sh + +#-T timestamp +#-a action +#-t target +#-i insert, otherwise search + +op=search +action='log' + +pkgfile=${ZPMDB:-/var/lib/zpm/db.zpm} + +while getopts f:t:a:T:i opt; do + case $opt in + f) pkgfile="$OPTARG" ;; + t) target="$OPTARG" ;; + a) action="$OPTARG" ;; + T) timestamp="$OPTARG" ;; + i) op=insert ;; + *) printf '%s unknown option %s\n' "$0" "$opt" ; exit 1 ;; + esac +done +shift $((OPTIND - 1)) + +if [ $op = 'insert' ]; then +{ + cols='action,target,info'; + if [ -n "$timestamp" ]; then + cols='ts,action,target,info' + fi + + printf "insert into zpmlog (%s)\n" $cols + printf 'values('; + if [ -n "$timestamp" ]; then + printf "'%s', " "$timestamp" + fi + if [ -n "$action" ]; then + printf "'%s', " "$action" + else + printf 'NULL,' + fi + if [ -n "$target" ]; then + printf "'%s', " "$target" + else + printf 'NULL,' + fi + printf "'%s')" "$*" + printf ';\n' +} | zpm shell $pkgfile + +fi + +if [ $op = 'search' ]; then +{ + printf 'select ts,action,target,info from zpmlog where\n'; + if [ -n "$timestamp" ]; then + printf "ts >= '%s' and " "$timestamp" + fi + + if [ -n "$action" ]; then + printf "action = '%s' and " "$action" + fi + if [ -n "$target" ]; then + printf "target = '%s' and " "$target" + fi + printf "true;\n" +} | zpm shell $pkgfile + +fi +