]> pd.if.org Git - zpackage/blob - zpm-contents
print link target in contents
[zpackage] / zpm-contents
1 #!/bin/sh
2
3 pkgfile=${ZPMDB:-/var/lib/zpm/db.zpm}
4
5 long=0
6 pkgonly=0
7 quiet=0
8
9 while getopts f:qln opt; do
10         case $opt in
11                 f) pkgfile="$OPTARG" ;;
12                 l) long=1 ;;
13                 n) pkgonly=1 ;;
14                 q) quiet=1 ;;
15         esac
16 done
17 shift $((OPTIND - 1))
18
19 if [ ! -f $pkgfile ]; then
20         echo cannot find $pkgfile
21         exit 1
22 fi
23
24 if [ $long -gt 0 ]; then
25         cols="filetype,printf('%.4s', mode) as mode,username,groupname,"
26 fi
27
28 if [ $pkgonly -eq 1 ]; then
29         cols="pkgid"
30 elif [ $quiet -eq 0 ]; then
31         cols="pkgid,$cols"
32 fi
33
34 pkglist=
35 while [ $# -gt 0 ]; do
36         pkg=$1
37         shift
38         if [ "$pkg" = '--' ]; then
39                 break;
40         fi
41
42         pkgid=$(zpm findpkg -f $pkgfile "$pkg")
43         if [ -n "$pkgid" ]; then
44                 q=$(zpm quote -q "$pkgid")
45                 pkglist=",$q"
46         else
47                 warn "package $pkg not found, ignoring"
48         fi
49 done
50 pkglist=${pkglist#,}
51
52 globlist=
53 for glob in "$@"; do
54         q=$(zpm quote -q "$glob")
55         globlist="or path glob $q"
56 done
57 globlist=${globlist#'or '}
58
59 cols=${cols%,}
60
61 {
62         printf '.separator " "\n'
63         printf 'select %s\n' "$cols"
64
65         if [ $pkgonly -eq 0 ]; then
66                 if [ -n "$cols" ]; then
67                         printf ', '
68                 fi
69
70                 cat <<-EOC
71                 case when filetype = 'd' then
72                         rtrim(path,'/') || '/'
73                 when filetype = 'l' then
74                         printf('%s -> %s', path, target)
75                 else
76                         path
77                 end as path
78                 EOC
79         fi
80         printf 'from packagefiles_pkgid\nwhere true\n'
81         if [ -n "$globlist" ]; then
82                 printf "and (%s)\n" "$globlist"
83         fi
84         if [ -n "$pkglist" ]; then
85                 printf "and pkgid in (%s)\n" "$pkglist"
86         fi
87         printf 'order by pkgid,path\n'
88         printf ';\n'
89 } | zpm shell $pkgfile
90 #} | cat