[sde-update-tree] Enhanced svn support to handle broken externals without aborting...
[opensde-nopast.git] / bin / sde-list-pkg
blob60b14e5051a9e2819ea4b3542b22bb72da91e64e
1 #!/bin/sh
2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: bin/sde-list-pkg
6 # Copyright (C) 2007 The OpenSDE Project
8 # More information can be found in the files COPYING and README.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- SDE-COPYRIGHT-NOTE-END ---
16 [ -n "$SDEROOT" ] ||
17 export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
19 . $SDEROOT/lib/libsde.in
21 list_usage() {
22 local progname=${0##*/}
23 cat <<EOT
24 Usage: $progname [--arch <arch>]
25 $progname [--cfg <config>] [--extenders] [--repositories] [ITEMS...]
26 EOT
29 list_arch() {
30 local repo= arch="$1"
31 local files=
33 if [ ! -s $SDEROOT/architecture/$arch/archtest.out ]; then
34 echo_error "wrong architecture ($arch) specified, aborting."
35 return 1
38 # the .awk file needs complete $SDEROOT relative .desc locations
39 cd $SDEROOT
41 for repo in package/*; do
42 files=$( ls -1d $repo/*/*.desc 2> /dev/null )
43 if [ -n "$files" ]; then
44 gawk -f ./lib/sde-package/package-list.awk -v "arch=$arch" $files
46 done | sort -k 3
49 list_desc_extenders() {
50 local config="$1"
51 local repo= pkg= pattern= pattern2= confdir=
52 shift
54 [ $# -gt 0 ] || return
56 if [ $# -eq 1 ]; then
57 pattern=$1
58 else
59 pattern="{$( echo $* | tr ' ' ',' )}"
62 if [ -z "$config" ]; then
63 for repo in $( cd "$SDEROOT/package"; ls -1d * 2> /dev/null ); do
64 ( cd "$SDEROOT"; eval ls -1d package/$repo/*/pkg_${pattern}_{pre,post}.conf 2> /dev/null | cut -d/ -f-3 | sort -u )
65 done | while read confdir; do
66 pkg=${confdir##*/}
67 echo $confdir/$pkg.desc
68 done
69 else
70 for repo in $( grep '^X' $SDEROOT/config/$config/packages | cut -d' ' -f4 | sort -u ); do
71 set -- $( grep "^X [^ ]\+ [^ ]\+ $repo " "$SDEROOT/config/$config/packages" | cut -d' ' -f5 )
73 if [ $# -eq 1 ]; then
74 pattern2=$1
75 else
76 pattern2="{$( echo $* | tr ' ' ',' )}"
79 ( cd "$SDEROOT"; eval ls -1d package/$repo/${pattern2}/pkg_${pattern}_{pre,post}.conf 2> /dev/null | cut -d/ -f-3 | sort -u )
80 done | while read confdir; do
81 pkg=${confdir##*/}
82 echo $confdir/$pkg.desc
83 done
87 list_desc_repo() {
88 local repo="$1" pkg= desc=
90 if [ -d "$SDEROOT/package/$repo/" ]; then
91 set -- $( cd "$SDEROOT/package/$repo/"; ls -1d * 2> /dev/null )
93 for pkg; do
94 desc="package/$repo/$pkg/$pkg.desc"
96 if [ -f "$SDEROOT/$desc" ]; then
97 echo "$desc"
99 done
101 if [ -n "$extenders" ]; then
102 # get desc of extenders of those packages
103 list_desc_extenders '' "$@"
108 list_desc() {
109 local config="$1" patterns=
110 local repo= file= pkg= desc=
111 shift;
113 if [ -z "$config" ]; then
114 if [ $# -eq 0 ]; then
115 # no config, use the whole db
116 for repo in $( cd "$SDEROOT/package"; ls -1d * 2> /dev/null ); do
117 extenders= list_desc_repo "$repo"
118 done
119 elif [ -z "$repositories" ]; then
120 # no config, but a given set of packages
121 for pkg; do
122 desc=$( cd "$SDEROOT"; ls -1d package/*/$pkg/$pkg.desc )
124 if [ -f "$SDEROOT/$desc" ]; then
125 echo "$desc"
128 done
130 if [ -n "$extenders" ]; then
131 # get desc of extenders of those packages
132 list_desc_extenders '' "$@"
134 else
135 for repo; do
136 list_desc_repo "$repo"
137 done
139 elif [ -r "$SDEROOT/config/$config/packages" ]; then
140 if [ $# -eq 0 ]; then
141 # every active package
142 grep '^X' config/xfce/packages | cut -d' ' -f4,5 | while read repo pkg; do
143 desc=package/$repo/$pkg/$pkg.desc
145 if [ -f "$SDEROOT/$desc" ]; then
146 echo "$desc"
148 done
149 elif [ -z "$repositories" ]; then
150 if [ $# -eq 1 ]; then
151 pattern=$1
152 else
153 pattern="\\($( echo $* | sed -e "s/ /\\\\|/g" )\\)"
156 grep "^X [^ ]\+ [^ ]\+ [^ ]\+ $pattern " "$SDEROOT/config/$config/packages" | cut -d' ' -f4,5 | while read repo pkg; do
157 desc=package/$repo/$pkg/$pkg.desc
159 if [ -f "$SDEROOT/$desc" ]; then
160 echo "$desc"
162 done
164 if [ -n "$extenders" ]; then
165 # get desc of extenders of those packages
166 list_desc_extenders "$config" "$@"
168 elif [ $# -gt 0 ]; then
169 if [ $# -eq 1 ]; then
170 pattern=$1
171 else
172 pattern="\\($( echo $* | sed -e "s/ /\\\\|/g" )\\)"
175 grep "^X [^ ]\+ [^ ]\+ $pattern " "$SDEROOT/config/$config/packages" | cut -d' ' -f4,5 | while read repo pkg; do
176 desc=package/$repo/$pkg/$pkg.desc
178 if [ -f "$SDEROOT/$desc" ]; then
179 echo "$desc"
181 done
183 if [ -n "$extenders" ]; then
184 # get desc of extenders of those packages
185 list_desc_extenders "$config" $( grep "^X [^ ]\+ [^ ]\+ $pattern " "$SDEROOT/config/$config/packages" |
186 cut -d' ' -f 5 )
189 else
190 echo_abort -1 "$config: config not found."
194 arch=
195 config=
196 mode=desc
197 extenders=
198 repositories=
200 shortopts='a:c:er'
201 longopts='arch:,cfg:,extenders,repositories'
202 options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
203 if [ $? -ne 0 ]; then
204 list_usage
205 exit -1
208 # load new arguments list
209 eval set -- "$options"
211 # arguments
212 while [ $# -gt 0 ]; do
213 case "$1" in
214 -a|--arch) mode=arch
215 arch="$2"; shift ;;
216 -c|--cfg) config="$2"; shift ;;
218 -r|--repositories)
219 repositories=yes ;;
220 -e|--extenders)
221 extenders=yes ;;
223 --) shift; break ;;
224 *) echo_abort 1 "Unknown argument '$1', aborting."
225 esac
226 shift
227 done
229 case "$mode" in
230 arch) list_arch "$arch" ;;
231 desc) list_desc "$config" "$@" ;;
232 *) list_usage ;;
233 esac