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