remove executable bit, remove shebang line, update copyright on subcommands.
[monkeysphere.git] / src / subcommands / 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 fingerprint=$(fingerprint_server_key)
31
32 # match to only ultimately trusted user IDs
33 tmpuidMatch="u:$(echo $userID | gpg_escape)"
34
35 # find the index of the requsted user ID
36 # NOTE: this is based on circumstantial evidence that the order of
37 # this output is the appropriate index
38 if line=$(gpg_host --list-keys --with-colons --fixed-list-mode "0x${fingerprint}!" \
39     | egrep '^(uid|uat):' | cut -f2,10 -d: | grep -n -x -F "$tmpuidMatch") ; then
40     failure "Host userID '$userID' already exists."
41 fi
42
43 echo "The following user ID will be added to the host key:"
44 echo "  $userID"
45 read -p "Are you sure you would like to add this user ID? (y/N) " OK; OK=${OK:=N}
46 if [ ${OK/y/Y} != 'Y' ] ; then
47     failure "User ID not added."
48 fi
49
50 # edit-key script command to add user ID
51 adduidCommand=$(cat <<EOF
52 adduid
53 $userID
54
55
56 save
57 EOF
58 )
59
60 # execute edit-key script
61 if echo "$adduidCommand" | \
62     gpg_host --quiet --command-fd 0 --edit-key "0x${fingerprint}!" ; then
63
64     show_key
65
66     echo
67     echo "NOTE: User ID added to key, but key not published."
68     echo "Run '$PGRM publish-key' to publish the new user ID."
69 else
70     failure "Problem adding user ID."
71 fi
72
73 }