#! /bin/sh ### ### List a user's keys ### ### (c) 2011 Mark Wooding ### ###----- Licensing notice --------------------------------------------------- ### ### This file is part of the distorted.org.uk key management suite. ### ### distorted-keys is free software; you can redistribute it and/or modify ### it under the terms of the GNU General Public License as published by ### the Free Software Foundation; either version 2 of the License, or ### (at your option) any later version. ### ### distorted-keys is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ### GNU General Public License for more details. ### ### You should have received a copy of the GNU General Public License ### along with distorted-keys; if not, write to the Free Software Foundation, ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. set -e case "${KEYSLIB+t}" in t) ;; *) echo >&2 "$0: KEYSLIB unset"; exit 1 ;; esac . "$KEYSLIB"/keyfunc.sh defhelp <&2 "$quis: unknown column \`$name'"; exit 1 ;; esac done ## Second and third pass: find the keys, compute their properties and either ## measure column widths or display the results. while :; do ## Decide whether we need to display a header. (We need this on both ## passes, because it may contribute to width.) doheader=$header ## Find the metadata files. This tells us where the keys are. case $all in t) dir=store ;; nil) dir=store/$user ;; esac metas=$(find $dir -type f -name meta | sort) ## Work through the keys we found. while :; do ## If we're not doing a header line, read the next metadata file name. ## Check that it matches at least one pattern. case $doheader in nil) if ! read meta; then break; fi label=${meta#store/}; label=${label%/meta} matchp=nil for pat in "$@"; do case "$label" in $pat) matchp=t; break ;; esac done case $matchp in nil) continue ;; esac ;; esac ## Now iterate over the columns. If we're calculating widths, use the ## ones we worked out last time, and clear the list so we can build a new ## one as we go. cc=$cols sep="" case $calcwd in t) cols="" ;; esac while :; do ## Pick off the next column spec. case "$cc" in *,*) col=${cc%%,*} cc=${cc#*,} ;; ?*) col=$cc cc="" ;; *) break ;; esac ## Work out the column name. name=${col%[:=+]*} wd=${col#*[:=+]} ## Work out the value. If this is a header line, then it's just the ## column name in upper case; otherwise we have work to do. case $doheader in t) value=$(echo $name | tr a-z A-Z) ;; nil) value=$(col_$name $label) ;; esac ## Work out what to do about it. If we're measuring, then update our ## idea of the column width. If we're printing, work out a format. case $calcwd,$col in t,*[:=]*) cols=${cols:+$cols,}$col ;; t,*+*) colwd=$(( $(echo "$value" | wc -c) - 1 )) if [ $colwd -gt $wd ]; then wd=$colwd; fi cols=${cols:+$cols,}$name+$wd ;; nil,*[=+]*) fmt="%-${wd}.${wd}s" ;; nil,*:*) fmt="%-${wd}s" ;; esac ## If we're printing, then print something. Leave space between the ## columns. case $calcwd in nil) printf "$sep$fmt" "$value"; sep=" " ;; esac done ## The next line will certainly not be a header. doheader=nil ## Start a new line if we're printing. case $calcwd in nil) printf "\n" ;; esac done <