Commit | Line | Data |
---|---|---|
865fc4a1 MW |
1 | #! /bin/sh |
2 | ### | |
3 | ### Delete a keeper set | |
4 | ### | |
5 | ### (c) 2012 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 | case "${KEYSLIB+t}" in t) ;; *) echo >&2 "$0: KEYSLIB unset"; exit 1 ;; esac | |
28 | . "$KEYSLIB"/keyfunc.sh | |
29 | ||
30 | defhelp <<HELP | |
31 | KEEPER | |
32 | Delete the keeper set named KEEPER. | |
33 | HELP | |
34 | ||
35 | case $# in 1) ;; *) usage_err ;; esac | |
36 | keeper=$1 | |
37 | checkword "keeper set label" "$keeper" | |
38 | ||
39 | cd $KEYS/keeper | |
40 | if [ ! -d $keeper ]; then | |
41 | echo >&2 "$quis: unknown keeper set \`$keeper'" | |
42 | exit 1 | |
43 | fi | |
44 | ||
45 | unset deps | |
46 | if [ -d $KEYS/recov ]; then | |
47 | cd $KEYS/recov | |
48 | for r in $(find . -type l -name current -print); do | |
49 | r=${r#./}; r=${r%/current} | |
50 | if ! expr >/dev/null "Q$r" : "Q$R_LABEL"; then continue; fi | |
51 | for ri in $r/*; do | |
52 | i=${ri##*/} | |
53 | case "$i" in *[!0-9]*) continue ;; esac | |
54 | this=nil others=nil | |
55 | for kp in $r/current/*.param; do | |
56 | k=${kp##*/}; k=${k%.param} | |
57 | case $k in $keeper) this=t ;; *) others=t ;; esac | |
58 | done | |
59 | case $this,$others in t,nil) deps="$deps $ri" ;; esac | |
60 | done | |
61 | done | |
62 | fi | |
63 | case "${deps+t}" in | |
64 | t) | |
65 | echo >&2 "$quis: deleting keeper \`$keeper' would orphan recovery keys:" | |
66 | for d in $deps; do echo 2>&1 " $d"; done | |
67 | exit 1 | |
68 | ;; | |
69 | esac | |
70 | ||
71 | if [ -d $KEYS/recov ]; then | |
72 | cd $KEYS/recov | |
73 | for r in $(find . -type l -name current -print); do | |
74 | r=${r#./}; r=${r%/current} | |
75 | if ! expr >/dev/null "Q$r" : "Q$R_LABEL"; then continue; fi | |
76 | for ri in $i/*; do | |
77 | i=${ri##*/} | |
78 | case "$i" in *[!0-9]*) continue ;; esac | |
79 | rm -f $ri/$keeper.* | |
80 | done | |
81 | changep=nil | |
82 | while read k rest; do | |
83 | case $k in $keeper) changep=t ;; *) echo "$k $rest" ;; esac | |
84 | done <$r/keepers >$r/keepers.new | |
85 | case $changep in | |
86 | t) mv $r/keepers.new $r/keepers ;; | |
87 | nil) rm $r/keepers.new ;; | |
88 | esac | |
89 | done | |
90 | fi | |
91 | ||
92 | cd $KEYS/keeper | |
93 | rm -r $keeper | |
94 | ||
95 | ###----- That's all, folks -------------------------------------------------- |