]> pd.if.org Git - zpackage/blob - zpm-contents
remove debug
[zpackage] / zpm-contents
1 #!/bin/sh
2
3 pkgfile=${ZPMDB:-/var/lib/zpm/local.db}
4
5 long=0
6 pkgonly=0
7 quiet=0
8 config=include
9 showsoname=0
10 status=
11
12 while getopts f:qlncCLI opt; do
13         case $opt in
14                 f) pkgfile="$OPTARG" ;;
15                 l) long=1 ;;
16                 n) pkgonly=1 ;;
17                 q) quiet=1 ;;
18                 c) config=only ;;
19                 C) config=exclude ;;
20                 L) showsoname=1 ;;
21                 I) status=installed
22         esac
23 done
24 shift $((OPTIND - 1))
25
26 if [ ! -f $pkgfile ]; then
27         echo cannot find $pkgfile
28         exit 1
29 fi
30
31 if [ $long -gt 0 ]; then
32         cols="filetype,printf('%.4s', mode) as mode,username,groupname,"
33 fi
34
35 if [ $pkgonly -eq 1 ]; then
36         cols="pkgid"
37 elif [ $quiet -eq 0 ]; then
38         cols="pkgid,$cols"
39 fi
40
41 pkglist=
42 while [ $# -gt 0 ]; do
43         pkg=$1
44         shift
45         if [ "$pkg" = '--' ]; then
46                 break;
47         fi
48
49         pkgid=$(zpm findpkg -f $pkgfile "$pkg")
50         if [ -n "$pkgid" ]; then
51                 q=$(zpm quote -q "$pkgid")
52                 pkglist=",$q"
53         else
54                 warn "package $pkg not found, ignoring"
55         fi
56 done
57 pkglist=${pkglist#,}
58
59 globlist=
60 for glob in "$@"; do
61         q=$(zpm quote -q "$glob")
62         globlist="or path glob $q"
63 done
64 globlist=${globlist#'or '}
65
66 cols=${cols%,}
67
68 {
69         printf '.separator " "\n'
70 #       printf '.echo on\n'
71         printf 'select %s\n' "$cols"
72
73         if [ $pkgonly -eq 0 ]; then
74                 if [ -n "$cols" ]; then
75                         printf ', '
76                 fi
77
78                 printf "case\n";
79                 printf "when filetype = 'd' then rtrim(path,'/') || '/'\n"
80                 printf "when filetype = 'l' then printf('%%s -> %%s', path, target)\n"
81                 if [ $showsoname -eq 1 ]; then
82                         printf "when EL.soname is not null then printf('%%s (%%s)', path, EL.soname)\n"
83                 fi
84                 printf "else path end as path\n"
85         fi
86         printf "from packagefiles_pkgid PF\n"
87         if [ $showsoname -eq 1 ]; then
88                 printf "left join elflibraries EL on EL.file = PF.hash\n"
89         fi
90         if [ -n "$status" ]; then
91                 printf "join packages P on P.package = PF.package and P.version = PF.version and P.release = PF.release\n"
92         fi
93         printf "where true\n"
94         if [ -n "$globlist" ]; then
95                 printf "and (%s)\n" "$globlist"
96         fi
97         if [ -n "$pkglist" ]; then
98                 printf "and pkgid in (%s)\n" "$pkglist"
99         fi
100         case $config in
101                 only) printf "and configuration = 1\n" ;;
102                 exclude) printf "and configuration = 0\n" ;;
103         esac
104         if [ -n "$status" ]; then
105                 printf "and P.status = '%s'\n" "$status"
106         fi
107         printf 'order by package,version collate vercmp, release, path\n'
108         printf ';\n'
109 } | zpm shell $pkgfile
110 #} | cat