]> pd.if.org Git - zpackage/blob - zpm-contents
add script to commit configfiles to git
[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                 printf "package $pkg not found, ignoring\n" 1>&2
55                 exit 1
56         fi
57         pkglist=${pkglist#,}
58         if [ -z "$pkglist" ]; then
59                 printf "can't find any packages\n" 1>&2
60                 exit 1
61         fi
62 done
63
64 globlist=
65 for glob in "$@"; do
66         q=$(zpm quote -q "$glob")
67         globlist="or path glob $q"
68 done
69 globlist=${globlist#'or '}
70
71 cols=${cols%,}
72
73 {
74         printf '.separator " "\n'
75 #       printf '.echo on\n'
76         printf 'select %s\n' "$cols"
77
78         if [ $pkgonly -eq 0 ]; then
79                 if [ -n "$cols" ]; then
80                         printf ', '
81                 fi
82
83                 printf "case\n";
84                 printf "when filetype = 'd' then rtrim(path,'/') || '/'\n"
85                 printf "when filetype = 'l' then printf('%%s -> %%s', path, target)\n"
86                 if [ $showsoname -eq 1 ]; then
87                         printf "when EL.soname is not null then printf('%%s (%%s)', path, EL.soname)\n"
88                 fi
89                 printf "else path end as path\n"
90         fi
91         printf "from packagefiles_pkgid PF\n"
92         if [ $showsoname -eq 1 ]; then
93                 printf "left join elflibraries EL on EL.file = PF.hash\n"
94         fi
95         if [ -n "$status" ]; then
96                 printf "join packages P on P.package = PF.package and P.version = PF.version and P.release = PF.release\n"
97         fi
98         printf "where true\n"
99         if [ -n "$globlist" ]; then
100                 printf "and (%s)\n" "$globlist"
101         fi
102         if [ -n "$pkglist" ]; then
103                 printf "and pkgid in (%s)\n" "$pkglist"
104         fi
105         case $config in
106                 only) printf "and configuration = 1\n" ;;
107                 exclude) printf "and configuration = 0\n" ;;
108         esac
109         if [ -n "$status" ]; then
110                 printf "and P.status = '%s'\n" "$status"
111         fi
112         printf 'order by package,version collate vercmp, release, path\n'
113         printf ';\n'
114 } | zpm shell $pkgfile
115 #} | cat