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