Delete the keeper set named KEEPER.
HELP
+## Parse the command line.
case $# in 1) ;; *) usage_err ;; esac
keeper=$1
checkword "keeper set label" "$keeper"
+## Check that the set actually exists.
cd $KEYS/keeper
if [ ! -d $keeper ]; then
echo >&2 "$quis: unknown keeper set \`$keeper'"
exit 1
fi
+## Make sure that there aren't recovery keys which would be orphaned by
+## deleting this keeper set.
unset deps
if [ -d $KEYS/recov ]; then
cd $KEYS/recov
+
+ ## Work through the available recovery keys.
for r in $(find . -type l -name current -print); do
r=${r#./}; r=${r%/current}
if ! expr >/dev/null "Q$r" : "Q$R_LABEL"; then continue; fi
+
+ ## Now work through the instances.
for ri in $r/*; do
i=${ri##*/}
case "$i" in *[!0-9]*) continue ;; esac
+
+ ## For each recovery key, make sure that: either it doesn't depend on
+ ## this keeper set, or it also depends on at least one other set. If
+ ## not, add it to the `deps' list.
this=nil others=nil
for kp in $r/current/*.param; do
k=${kp##*/}; k=${k%.param}
done
done
fi
+
+## If we found any hard dependencies, report a failure.
case "${deps+t}" in
t)
echo >&2 "$quis: deleting keeper \`$keeper' would orphan recovery keys:"
;;
esac
+## Disentangle the dependent recovery keys from this keeper set.
if [ -d $KEYS/recov ]; then
cd $KEYS/recov
+
+ ## Work through the recovery keys again.
for r in $(find . -type l -name current -print); do
r=${r#./}; r=${r%/current}
if ! expr >/dev/null "Q$r" : "Q$R_LABEL"; then continue; fi
+
+ ## Remove the keeper data from the key's instances.
for ri in $i/*; do
i=${ri##*/}
case "$i" in *[!0-9]*) continue ;; esac
rm -f $ri/$keeper.*
done
+
+ ## Work through the current keepers, and remove our keeper's name from
+ ## the list.
changep=nil
while read k rest; do
case $k in $keeper) changep=t ;; *) echo "$k $rest" ;; esac
done
fi
+## Finally, actually delete the keeper keys.
cd $KEYS/keeper
rm -r $keeper