5 ### (c) 2011 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the distorted.org.uk key management suite.
12 ### distorted-keys is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### distorted-keys is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with distorted-keys; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 case "${KEYSLIB+t}" in t) ;; *) echo >&2 "$0: KEYSLIB unset"; exit 1 ;; esac
28 . "$KEYSLIB"/keyfunc.sh
31 [-Ha] [-C COLUMN,...] [-u USER] [PATTERN ...]
32 List stored keys. If PATTERNs are given, only list keys whose labels match
36 -H Don't show the column headings (useful for scripts).
37 -C COLUMN,... Select the columns to show.
38 -a Show keys owned by all users.
39 -u USER Show keys owned by USER.
41 A COLUMN spec consists of a column name and an optional column width; the
42 separator character determines the behaviour as shown below. The default is
44 NAME=WIDTH Exact width: truncate the contents to fit if necessary.
45 NAME:WIDTH Minimum width: spill into the next column (breaking the
46 alignment) if necessary.
47 NAME+WIDTH Minimum width: if a value won't fit then make the entire
51 flags Various flags for the key. (Unset flags are shown as \`.')
52 R key has recovery information
53 ! key nub needs recovery
54 label The key's label (relative to its owner).
55 profile The key's profile name.
56 recov Recovery key labels, comma-separated.
59 ###--------------------------------------------------------------------------
63 defcol () { ALLCOLS=${ALLCOLS:+$ALLCOLS,}$1; }
71 for i in recov/*/current/$label.recov; do
72 if [ -f "$i" ]; then rflag=R; break; fi
77 if [ -f nub/$label ]; then bangflag=.; fi
88 nil,$USERV_USER*) plabel=${label#*/} ;;
89 t,*) plabel=${label%%/*}:${label#*/} ;;
108 if [ -f "$i/current/$label.recov" ]; then
109 recov=${recov:+$recov,}${i#recov/}
115 ###--------------------------------------------------------------------------
118 ## Parse the command-line options. Remaining arguments are glob patterns.
123 while getopts "HaC:u:" opt; do
132 shift $(( $OPTIND - 1 ))
133 case $# in 0) set "*" ;; esac
136 ## First pass: validate the column specifications. Translate all bare column
137 ## names into explicit `NAME+0' forms. Decide whether we need a width-
144 ## Pick off the next column name. If none are left, leave the loop.
146 *,*) col=${cc%%,*} cc=${cc#*,} ;;
151 ## Extract the column name for later.
154 ## If we have a minimum width or no width, we need a measuring pass.
155 case "$col" in *[:=]*) ;; *) calcwd=t ;; esac
157 ## Check the column width is valid. Build the new column list with
162 wdcols=${wdcols:+$wdcols,}$col
163 checknumber "column width" "$wd"
166 wdcols=${wdcols:+$wdcols,}$col+0
170 ## Check the column name.
173 *) echo >&2 "$quis: unknown column \`$name'"; exit 1 ;;
177 ## Second and third pass: find the keys, compute their properties and either
178 ## measure column widths or display the results.
181 ## Decide whether we need to display a header. (We need this on both
182 ## passes, because it may contribute to width.)
185 ## Find the metadata files. This tells us where the keys are.
188 nil) dir=store/$user ;;
190 metas=$(find $dir -type f -name meta | sort)
192 ## Work through the keys we found.
195 ## If we're not doing a header line, read the next metadata file name.
196 ## Check that it matches at least one pattern.
199 if ! read meta; then break; fi
200 label=${meta#store/}; label=${label%/meta}
203 case "$label" in $pat) matchp=t; break ;; esac
205 case $matchp in nil) continue ;; esac
209 ## Now iterate over the columns. If we're calculating widths, use the
210 ## ones we worked out last time, and clear the list so we can build a new
212 case $calcwd in t) cols=$wdcols ;; esac
213 cc=$cols wdcols="" sep=""
216 ## Pick off the next column spec.
218 *,*) col=${cc%%,*} cc=${cc#*,} ;;
223 ## Work out the column name.
224 name=${col%[:=+]*} wd=${col#*[:=+]}
226 ## Work out the value. If this is a header line, then it's just the
227 ## column name in upper case; otherwise we have work to do.
229 t) value=$(echo $name | tr a-z A-Z) ;;
230 nil) value=$(col_$name $label) ;;
233 ## Work out what to do about it. If we're measuring, then update our
234 ## idea of the column width. If we're printing, work out a format.
237 wdcols=${wdcols:+$wdcols,}$col
240 colwd=$(( $(echo "$value" | wc -c) - 1 ))
241 if [ $colwd -gt $wd ]; then wd=$colwd; fi
242 wdcols=${wdcols:+$wdcols,}$name+$wd
252 ## If we're printing, then print something. Leave space between the
254 case $calcwd in nil) printf "$sep$fmt" "$value"; sep=" " ;; esac
257 ## The next line will certainly not be a header.
260 ## Start a new line if we're printing.
261 case $calcwd in nil) printf "\n" ;; esac
266 ## If we were measuring, go round again and print; otherwise we're done.
273 ###----- That's all, folks --------------------------------------------------