From 643e4a61edf7e96077deedae32fa8686cbab9f16 Mon Sep 17 00:00:00 2001 From: Olof-Joachim Frahm Date: Thu, 8 Jan 2015 00:49:03 +0000 Subject: [PATCH] Initial commit. --- crypto-install.py | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 crypto-install.py diff --git a/crypto-install.py b/crypto-install.py new file mode 100755 index 0000000..2e3b926 --- /dev/null +++ b/crypto-install.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# -*- mode: python; coding: utf-8-unix; -*- + + +import argparse, ConfigParser, os, sys, textwrap + + +def print_version (): + print ("crypto-install.py GIT-TAG (GIT-REVISION)") + + +def input_string (prompt=""): + if sys.version_info[0] == 2: + return raw_input(prompt) + return input(prompt) + + +def parse_arguments (): + parser = argparse.ArgumentParser () + parser.add_argument ( + "-v", "--version", + dest = "version", + action = "store_true", + help = "Display version.") + parser.add_argument ( + "--no-gpg", + dest = "gnupg", + action = "store_false", + help = "Disable GnuPG setup.") + parser.add_argument ( + "--no-ssh", + dest = "openssh", + action = "store_false", + help = "Disable OpenSSH setup.") + parser.add_argument ( + "--ssh-config", + dest = "openssh_config", + default = "~/.ssh/config", + help = "Set path for OpenSSH configuration file.") + return parser.parse_args () + + +def gnupg_setup (): + if False: + print("Default GnuPG key already exists.") + return + + print (textwrap.fill (textwrap.dedent("""\ + No default GnuPG key available. Please enter your information to + create a new key."""), width = 80)) + + name = input_string("What is your name? (Max Mustermann) ") + email = input_string("What is your email address? (max@example.de) ") + motto = input_string("What is your motto phrase, if any? (Schlüssel für 2014) ") + + +def openssh_setup (arguments): + if not os.path.exists(arguments.openssh_config): + with open(arguments.openssh_config, "w") as ssh_config: + ssh_config.write(textwrap.dedent("""\ + ForwardAgent yes + ForwardX11 yes + """)) + + if os.path.exists (os.path.expanduser ("~/.ssh/id_rsa")) \ + or os.path.exists (os.path.expanduser ("~/.ssh/id_dsa")): + print("OpenSSH key already exists.") + return + + print (textwrap.fill (textwrap.dedent("""\ + No OpenSSH key available. Generating new key."""), width = 80)) + + os.system ("ssh-keygen") + + +def main (): + args = parse_arguments () + + if args.version: + print_version () + sys.exit () + + if args.gnupg: + gnupg_setup () + + if args.openssh: + openssh_setup (args) + + +if __name__ == "__main__": + main () -- 1.7.10.4