chiark / gitweb /
more progress. recovery seems to be working now.
[distorted-keys] / keys.in
1 #! /bin/sh
2 ###
3 ### Front-end dispatch for key-management scripts
4 ###
5 ### (c) 2011 Mark Wooding
6 ###
7
8 ###----- Licensing notice ---------------------------------------------------
9 ###
10 ### This file is part of the distorted.org.uk key management suite.
11 ###
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.
16 ###
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.
21 ###
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.
25
26 set -e
27
28 quis=${0##*/}
29 PACKAGE=@PACKAGE@
30 VERSION=@VERSION@
31
32 : ${KEYS=@pkgconfdir@}
33 : ${KEYSLIB=@pkglibdir@}
34 export KEYS KEYSLIB
35
36 ###--------------------------------------------------------------------------
37 ### Help.
38
39 usage="usage: $quis COMMAND [ARGUMENTS ...]"
40
41 version () {
42   echo "$PACKAGE version $VERSION"
43 }
44
45 help () {
46   rc=0
47   version
48   case $# in
49     0)
50       cat <<EOF
51
52 $usage
53
54 Options:
55   -h            Show this help text.
56   -v            Show the program version number.
57
58 Commands installed:
59 EOF
60       cd "$KEYSLIB"
61       for i in *; do
62         case "$i" in *.*) continue ;; esac
63         if [ ! -x "$i" ]; then continue; fi
64         sed -n "/<<HELP/{n;s/^/ $i /;p;q;}" "$i"
65       done
66       ;;
67     *)
68       for i in "$@"; do
69         echo
70         if [ ! -x "$KEYSLIB"/"$i" ]; then
71           echo >&2 "$quis: unrecognized command \`$i'"
72           rc=1
73           continue
74         elif ! KEYS_HELP=t "$KEYSLIB"/"$i"; then
75           rc=1
76         fi
77       done
78       ;;
79   esac
80   return $rc
81 }
82
83 ###--------------------------------------------------------------------------
84 ### Command dispatch.
85
86 while getopts "hv" opt; do
87   case "$opt" in
88     h) help; exit ;;
89     v) version; exit ;;
90     *) echo >&2 "$usage"; exit 1 ;;
91   esac
92 done
93 shift $((OPTIND - 1))
94
95 case $# in 0) echo >&2 "$usage"; exit 1 ;; esac
96 cmd=$1; shift
97 case "$cmd" in help) help "$@"; exit ;; esac
98 if [ ! -x "$KEYSLIB"/"$cmd" ]; then
99   echo >&2 "$quis: unrecognized command \`$cmd'"
100   exit 1
101 fi
102
103 unset KEYS_HELP
104 exec "$KEYSLIB"/"$cmd" "$@"
105
106 ###----- That's all, folks --------------------------------------------------