]> pd.if.org Git - zpackage/blob - zpm-list
add sql filter option to list
[zpackage] / zpm-list
1 #!/bin/sh
2
3 # zpm-list [-s status] [-vn] [ -f pkgfile ] [pkgid ...]
4
5 verbose=0
6 nameonly=0
7 latestonly=1
8
9 while getopts :s:f:vnIF: opt; do
10         case $opt in
11                 f) pkgfile="$OPTARG" ;;
12                 s) status="$OPTARG" ;;
13                 I) status=installed ;;
14                 v) verbose=1 ;;
15                 n) nameonly=1 ;;
16                 a) latestonly=0 ;;
17                 F) filter="$OPTARG" ;;
18         esac
19 done
20 shift $(( OPTIND - 1))
21
22 : ${pkgfile:=${ZPMDB:-/var/lib/zpm/local.db}}
23
24 if [ -z "$pkgfile" ]; then
25         echo "must specify package file"
26         exit 1
27 fi
28
29 if [ $nameonly -eq 0 ]; then
30         cols="pkgid"
31 else
32         cols="package"
33 fi
34
35 if [ $verbose -eq 1 ]; then
36         cols="$cols,coalesce(status,'-')"
37 fi
38
39 if [ -n "$status" ]; then
40         status=$(zpm quote "$status")
41         where="and status = '$status'"
42 fi
43
44 if [ -n "$filter" ]; then
45         where="$where and ($filter)"
46 fi
47
48 pkgid=$1
49
50 if [ -n "$pkgid" ]; then
51         eval $(zpm parse -E "$pkgid")
52         if [ -n "$name" ]; then
53                 package=$(zpm quote "$name")
54                 where="$where and package = '$package'"
55         fi
56         if [ -n "$version" ]; then
57                 version=$(zpm quote "$version")
58                 where="$where and version = '$version'"
59         fi
60         if [ -n "$release" ]; then
61                 release=$(zpm quote "$release")
62                 where="$where and release = '$release'"
63         fi
64 fi
65
66 zpm shell $pkgfile <<EOS
67 .separator "\t"
68 select $cols from packages_pkgid where true $where
69 ;
70 EOS
71
72 if [ $? -ne 0 ]; then
73         echo "select $cols from packages_pkgid where true $where" 1>&2
74 fi