3 ### Delete a keeper set
5 ### (c) 2012 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
32 Delete the keeper set named KEEPER.
35 ## Parse the command line.
36 case $# in 1) ;; *) usage_err ;; esac
38 checkword "keeper set label" "$keeper"
40 ## Check that the set actually exists.
42 if [ ! -d $keeper ]; then
43 echo >&2 "$quis: unknown keeper set \`$keeper'"
47 ## Make sure that there aren't recovery keys which would be orphaned by
48 ## deleting this keeper set. Also, build a data structure of recovery keys
49 ## and their instances: `$recov' is a space-separated list of recovery key
50 ## labels, and for each such label R, `$ri_R' is a space-separated list of
53 if [ -d $KEYS/recov ]; then
56 ## Work through the available recovery keys.
58 if ! expr >/dev/null "Q$r" : "Q$R_WORD"; then continue; fi
59 if [ ! -l $r/current ]; then continue; fi
61 ## Add the key to our list.
64 ## Now work through the instances.
68 case "$i" in *[!0-9]*) continue ;; esac
70 ## Add the instance to our list.
73 ## For each recovery key, make sure that: either it doesn't depend on
74 ## this keeper set, or it also depends on at least one other set. If
75 ## not, add it to the `deps' list.
77 for kp in $r/current/*.param; do
78 k=${kp##*/}; k=${k%.param}
79 case $k in $keeper) this=t ;; *) others=t ;; esac
81 case $this,$others in t,nil) deps="$deps $ri" ;; esac
84 ## Record the list of instances.
89 ## If we found any hard dependencies, report a failure.
92 echo >&2 "$quis: deleting keeper \`$keeper' would orphan recovery keys:"
93 for d in $deps; do echo 2>&1 " $d"; done
98 ## Disentangle the dependent recovery keys from this keeper set.
101 ## Remove the keeper data from the key's instances.
103 for i in $ii; do rm -f $r/$i/$keeper.*; done
105 ## Work through the current keepers, and remove our keeper's name from the
108 while read k rest; do
109 case $k in $keeper) changep=t ;; *) echo "$k $rest" ;; esac
110 done <$r/keepers >$r/keepers.new
112 t) mv $r/keepers.new $r/keepers ;;
113 nil) rm $r/keepers.new ;;
117 ## Finally, actually delete the keeper keys.
121 ###----- That's all, folks --------------------------------------------------