new msmktempdir function, to simplify making temporary directories. remove MHTMPDIR...
[monkeysphere.git] / src / share / m / import_subkey
1 # -*-shell-script-*-
2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
3
4 # Monkeysphere import-subkey 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 # import an existing ssh key as a gpg subkey
15
16 import_subkey() {
17     local keyFile="~/.ssh/id_rsa"
18     local keyExpire
19     local keyID
20     local gpgOut
21     local userID
22
23     # get options
24     while true ; do
25         case "$1" in
26             -f|--keyfile)
27                 keyFile="$2"
28                 shift 2
29                 ;;
30             -e|--expire)
31                 keyExpire="$2"
32                 shift 2
33                 ;;
34             *)
35                 if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
36                     failure "Unknown option '$1'.
37 Type '$PGRM help' for usage."
38                 fi
39                 break
40                 ;;
41         esac
42     done
43
44     log verbose "importing ssh key..."
45     fifoDir=$(msmktempdir)
46     (umask 077 && mkfifo "$fifoDir/pass")
47     ssh2openpgp | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import &
48
49     passphrase_prompt  "Please enter your passphrase for $keyID: " "$fifoDir/pass"
50
51     rm -rf "$fifoDir"
52     wait
53     log verbose "done."
54 }