754ced45f47774c9e18414a4467fc6e8c7ebf307
[monkeysphere.git] / src / share / mh / add_name
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-2010, and are all released under the GPL,
12 # version 3 or later.
13
14 # add servicename user ID to server key
15
16 add_name() {
17
18 local serviceName
19 local keyID
20 local fingerprint
21 local tmpuidMatch
22 local line
23 local adduidCommand
24
25 if [ -z "$1" ] ; then
26     failure "You must specify a service name to add."
27 fi
28 serviceName="$1"
29 shift
30
31 keyID=$(check_key_input "$@")
32
33 # test that the desired user ID does not already exist
34 check_key_userid "$keyID" "$serviceName" && \
35     failure "Service name '$serviceName' already exists on key '$keyID'."
36
37 # test that a key with that user ID does not already exist
38 prompt_userid_exists "$serviceName"
39
40 check_service_name "$serviceName"
41
42 if [ "$PROMPT" = "true" ] ; then
43     printf "The following service name will be added to key '$keyID':\n  %s\nAre you sure you would like to add this service name? (Y/n) " "$serviceName" >&2
44     read OK; OK=${OK:=Y}
45     if [ "${OK/y/Y}" != 'Y' ] ; then
46         failure "Service name not added."
47     fi
48 else
49     log debug "adding service name without prompting."
50 fi
51
52 # execute edit-key script
53 if PEM2OPENPGP_USAGE_FLAGS=authenticate \
54     <"$GNUPGHOME_HOST/secring.gpg" \
55     "$SYSSHAREDIR/keytrans" adduserid "$keyID" "$serviceName" \
56     | gpg_host --import ; then
57
58     gpg_host --check-trustdb
59
60     update_pgp_pub_file
61
62     show_key "$keyID"
63
64     echo
65     echo "NOTE: Service name added to key, but key not published."
66     echo "Run '$PGRM publish-key' to publish the new service name."
67 else
68     failure "Problem adding service name."
69 fi
70
71 }