#!/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