here's an "expect"-based function i use in a bash script for just such purpose,

# function: "DO_GENKEY_SESSION"
        # auto-execute a GPG --gen-key session
        # usage:
                #       DO_GENKEY_SESSION (SELECTION) $NOTATION $COMMENT
        # gen-key dialog options (SELECTION):
        # Please select what kind of key you want:
        #   (1) DSA and Elgamal (default)
        #   (2) DSA (sign only)
        #   (3) DSA (set your own capabilities)
        #   (5) RSA (sign only)
        #   (7) RSA (set your own capabilities)
DO_GENKEY_SESSION () {
        echo "START: $COMMENT"
        VAR=$($EXPECT -c "
                spawn  $GPG $GPG_RING_OPTS --expert --cert-notation $NOTATION 
--gen-key
                set timeout -1
                stty -echo
                expect     \"Your selection? \"
                exp_send   \"$1\n\"
                expect -re \"(What keysize do you want\?).*\\\\(\[0-9\]*\\\\) \"
                exp_send   \"$BITS\n\"
                expect     \"Key is valid for? (0) \"
                exp_send   \"0\n\"
                expect     \"Is this correct? (y/N) \"
                exp_send   \"y\n\"
                expect     \"Real name: \"
                exp_send   \"$NAME_REAL\n\"
                expect     \"Email address: \"
                exp_send   \"$EMAIL\n\"
                expect     \"Comment: \"
                exp_send   \"$SIG_COMMENT\n\"
                expect     \"(O)kay/(Q)uit? \"
                exp_send   \"O\n\"
                expect     \"Enter passphrase: \"
                exp_send   \"$PASS\n\"
                expect     \"Repeat passphrase: \"
                exp_send   \"$PASS\n\"
                expect exp_continue -continue_timer
        ")
        echo "   DONE"
}

of course, you define/pass/replace the various vars as you need/like ...


hth!

_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-users

Reply via email to