]> pd.if.org Git - zpackage/blob - zpm-log
add support for notes
[zpackage] / zpm-log
1 #!/bin/sh
2
3 #-T timestamp
4 #-a action
5 #-t target
6 #-i insert, otherwise search
7
8 op=search
9 action='log'
10
11 pkgfile=${ZPMDB:-/var/lib/zpm/db.zpm}
12
13 while getopts f:t:a:T:i opt; do
14         case $opt in
15                 f) pkgfile="$OPTARG" ;;
16                 t) target="$OPTARG" ;;
17                 a) action="$OPTARG" ;;
18                 T) timestamp="$OPTARG" ;;
19                 i) op=insert ;;
20                 *) printf '%s unknown option %s\n' "$0" "$opt" ; exit 1 ;;
21         esac
22 done
23 shift $((OPTIND - 1))
24
25 if [ $op = 'insert' ]; then
26 {
27         cols='action,target,info';
28         if [ -n "$timestamp" ]; then
29                 cols='ts,action,target,info'
30         fi
31
32         printf "insert into zpmlog (%s)\n" $cols
33         printf 'values(';
34         if [ -n "$timestamp" ]; then
35                 printf "'%s', " "$timestamp"
36         fi
37         if [ -n "$action" ]; then
38                 printf "'%s', " "$action"
39         else
40                 printf 'NULL,'
41         fi
42         if [ -n "$target" ]; then
43                 printf "'%s', " "$target"
44         else
45                 printf 'NULL,'
46         fi
47         printf "'%s')" "$*"
48         printf ';\n'
49 } | zpm shell $pkgfile
50
51 fi
52
53 if [ $op = 'search' ]; then
54 {
55         printf 'select ts,action,target,info from zpmlog where\n';
56         if [ -n "$timestamp" ]; then
57                 printf "ts >= '%s' and " "$timestamp"
58         fi
59
60         if [ -n "$action" ]; then
61                 printf "action = '%s' and " "$action"
62         fi
63         if [ -n "$target" ]; then
64                 printf "target = '%s' and " "$target"
65         fi
66         printf "true;\n"
67 } | zpm shell $pkgfile
68
69 fi
70