@@ -0,0 +1,2215 @@
+#!/usr/bin/env python%0A%0Aimport argparse%0Aimport gnupg%0Aimport os%0Aimport shutil%0Aimport scriptworker.gpg%0A%0A%0Aclass FullPaths(argparse.Action):%0A    %22%22%22Expand user- and relative-paths%22%22%22%0A%0A    def __call__(self, parser, namespace, values, option_string=None):%0A        setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values)))%0A%0A%0Aparser = argparse.ArgumentParser(description=%22GPG keypair creation and export script%22)%0Aparser.add_argument('-b', '--gpgbin', nargs='?', help=%22GPG binary used%22, action=FullPaths,%0A                    default=%22/usr/local/bin/gpg2%22)%0Aparser.add_argument('-o', '--gpghome', nargs='?', help=%22GPG home folder%22, action=FullPaths,%0A                    default=os.path.join(os.getcwd(), %22gpg%22))%0Aparser.add_argument('-u', '--username', nargs='?', help=%22Email username%22, default=%22cltsign%22)%0Aparser.add_argument('-s', '--hosts', nargs='+', help=%22Host names to generate for%22,%0A                    default=%5B%22signing-linux-1.srv.releng.use1.mozilla.com%22,%0A                             %22signing-linux-2.srv.releng.usw2.mozilla.com%22,%0A                             %22signing-linux-3.srv.releng.use1.mozilla.com%22,%0A                             %22signing-linux-4.srv.releng.usw2.mozilla.com%22%5D)%0Aparser.add_argument('-e', '--expires', nargs='?', help=%22Validity period for key%22, default=%222y%22)%0Aparser.add_argument('--clean', action='store_true', default=False)%0Aargs = parser.parse_args()%0A%0Agpgbinary = args.gpgbin%0Agpghome = args.gpghome%0Auser = args.username%0Ahosts = args.hosts%0Aduration = args.expires%0Acleanup = args.clean%0A%0Agpg = gnupg.GPG(%0A    gnupghome=gpghome,%0A    keyring=os.path.join(gpghome, %22pubring.gpg%22),%0A    secret_keyring=os.path.join(gpghome, %22secring.gpg%22),%0A    gpgbinary=gpgbinary,%0A)%0A%0Aif cleanup:%0A    shutil.rmtree(gpghome)%0A    os.makedirs(gpghome)%0A%0Afor host in hosts:%0A    name = host.split('.')%5B0%5D%0A    fingerprint = scriptworker.gpg.generate_key(%0A        gpg, name, '', user + '@%7B%7D'.format(host),%0A        expiration=duration%0A    )%0A    for pvt in (True, False):%0A        key = scriptworker.gpg.export_key(gpg, fingerprint, private=pvt)%0A        suffix = %22.pub%22%0A        if pvt:%0A            suffix = %22.sec%22%0A        with open(%22%7B%7D%7B%7D%22.format(name, suffix), %22w%22) as fh:%0A            print(key, file=fh, end='')%0A

add gpg keypair create and export helper script