renaming m-h update_gpg_pub_file to update_pgp_pub_file
[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 check_service_name "$serviceName"
38
39 if [ "$PROMPT" = "true" ] ; then
40     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
41     read OK; OK=${OK:=Y}
42     if [ "${OK/y/Y}" != 'Y' ] ; then
43         failure "Service name not added."
44     fi
45 else
46     log debug "adding service name without prompting."
47 fi
48
49 # execute edit-key script
50 if PEM2OPENPGP_USAGE_FLAGS=authenticate \
51     <"$GNUPGHOME_HOST/secring.gpg" \
52     "$SYSSHAREDIR/keytrans" adduserid "$keyID" "$serviceName" \
53     | gpg_host --import ; then
54
55     gpg_host --check-trustdb
56
57     update_pgp_pub_file
58
59     show_key "$keyID"
60
61     echo
62     echo "NOTE: Service name added to key, but key not published."
63     echo "Run '$PGRM publish-key' to publish the new service name."
64 else
65     failure "Problem adding service name."
66 fi
67
68 }