add ability to bypass prompting with a MONKEYSPHERE_PROMPT variable,
[monkeysphere.git] / src / share / mh / revoke_hostname
1 # -*-shell-script-*-
2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
3
4 # Monkeysphere host revoke-hostname subcommand
5 #
6 # The monkeysphere scripts are written by:
7 # Jameson Rollins <jrollins@finestructure.net>
8 # Jamie McClelland <jm@mayfirst.org>
9 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
10 #
11 # They are Copyright 2008-2009, and are all released under the GPL,
12 # version 3 or later.
13
14 # revoke hostname user ID from host key
15
16 revoke_hostname() {
17
18 local userID
19 local fingerprint
20 local tmpuidMatch
21 local line
22 local uidIndex
23 local message
24 local revuidCommand
25
26 if [ -z "$1" ] ; then
27     failure "You must specify a hostname to revoke."
28 fi
29
30 echo "WARNING: There is a known bug in this function."
31 echo "This function has been known to occasionally revoke the wrong user ID."
32 echo "Please see the following bug report for more information:"
33 echo "https://labs.riseup.net/code/issues/show/422"
34 read -p "Are you sure you would like to proceed? (y/N) " OK; OK=${OK:=N}
35 if [ ${OK/y/Y} != 'Y' ] ; then
36     failure "aborting."
37 fi
38
39 userID="ssh://${1}"
40
41 # make sure the user ID to revoke
42 uidIndex=$(find_host_userid) || \
43     failure "No non-revoked user ID found matching '$userID'."
44
45 if [ "$PROMPT" = "true" ] ; then
46     echo "The following host key user ID will be revoked:"
47     echo "  $userID"
48     read -p "Are you sure you would like to revoke this user ID? (y/N) " OK; OK=${OK:=N}
49     if [ ${OK/y/Y} != 'Y' ] ; then
50         failure "User ID not revoked."
51     fi
52 else
53     log debug "revoking user ID without prompting."
54 fi
55
56 # edit-key script command to revoke user ID
57 revuidCommand=$(cat <<EOF
58 $uidIndex
59 revuid
60 y
61 4
62 Hostname removed by monkeysphere-host: $DATE
63
64 y
65 save
66 EOF
67     )   
68
69 # execute edit-key script
70 if echo "$revuidCommand" | gpg_host_edit ; then
71
72     update_gpg_pub_file
73
74     show_key
75
76     echo
77     echo "NOTE: User ID revoked, but revocation not published."
78     echo "Run '$PGRM publish-key' to publish the revocation."
79 else
80     failure "Problem revoking user ID."
81 fi
82
83 }