9465d9635ac0bab68034c9ac29ef9356d7f80fd3
[monkeysphere.git] / src / share / mh / add_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 add-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 # add hostname user ID to server key
15
16 add_hostname() {
17
18 local userID
19 local fingerprint
20 local tmpuidMatch
21 local line
22 local adduidCommand
23
24 if [ -z "$1" ] ; then
25     failure "You must specify a hostname to add."
26 fi
27
28 userID="ssh://${1}"
29
30 # test that the desired user ID does not already exist
31 find_host_userid > /dev/null && \
32     failure "Host userID '$userID' already exists."
33
34 if [ "$PROMPT" = "true" ] ; then
35     printf "The following user ID will be added to the host key:\n  %s\nAre you sure you would like to add this user ID? (Y/n) " "$userID" >&2
36     read OK; OK=${OK:=Y}
37     if [ "${OK/y/Y}" != 'Y' ] ; then
38         failure "User ID not added."
39     fi
40 else
41     log debug "adding user ID without prompting."
42 fi
43
44 # edit-key script command to add user ID
45 adduidCommand="adduid
46 $userID
47
48
49 save"
50 # end script
51
52 # execute edit-key script
53 if echo "$adduidCommand" | gpg_host_edit ; then
54
55     update_gpg_pub_file
56
57     show_key
58
59     echo
60     echo "NOTE: User ID added to key, but key not published."
61     echo "Run '$PGRM publish-key' to publish the new user ID."
62 else
63     failure "Problem adding user ID."
64 fi
65
66 }