]> pd.if.org Git - zpackage/blob - zpm-list
fix recursive zpm-add
[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:vnI 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         esac
18 done
19 shift $(( OPTIND - 1))
20
21 : ${pkgfile:=${ZPMDB:-/var/lib/zpm/local.db}}
22
23 if [ -z "$pkgfile" ]; then
24         echo "must specify package file"
25         exit 1
26 fi
27
28 if [ $nameonly -eq 0 ]; then
29         cols="pkgid"
30 else
31         cols="package"
32 fi
33
34 if [ $verbose -eq 1 ]; then
35         cols="$cols,coalesce(status,'-')"
36 fi
37
38 if [ -n "$status" ]; then
39         status=$(zpm quote "$status")
40         where="and status = '$status'"
41 fi
42
43 pkgid=$1
44
45 if [ -n "$pkgid" ]; then
46         eval $(zpm parse -E "$pkgid")
47         if [ -n "$name" ]; then
48                 package=$(zpm quote "$name")
49                 where="$where and package = '$package'"
50         fi
51         if [ -n "$version" ]; then
52                 version=$(zpm quote "$version")
53                 where="$where and version = '$version'"
54         fi
55         if [ -n "$release" ]; then
56                 release=$(zpm quote "$release")
57                 where="$where and release = '$release'"
58         fi
59 fi
60
61 zpm shell $pkgfile <<EOS
62 .separator "\t"
63 select $cols from packages_pkgid where true $where
64 ;
65 EOS
66
67 if [ $? -ne 0 ]; then
68         echo "select $cols from packages_pkgid where true $where" 1>&2
69 fi