|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | 3 | from __future__ import print_function |
| 4 | +import numbers |
4 | 5 | import os |
5 | | -import sys |
6 | | -import socket |
7 | 6 | import posix |
| 7 | +import socket |
8 | 8 | import shutil |
9 | 9 | from subprocess import (Popen, PIPE) |
| 10 | +import sys |
10 | 11 |
|
11 | 12 | IRODS_SSL_DIR = '/etc/irods/ssl' |
12 | 13 | SERVER_CERT_HOSTNAME = None |
@@ -71,24 +72,33 @@ def test(options, args=()): |
71 | 72 | ssl_dir_files = create_ssl_dir(use_strong_primes_for_dh_generation = dh_strong_primes) |
72 | 73 | print('ssl_dir_files=', ssl_dir_files, file = sys.stderr) |
73 | 74 |
|
| 75 | +def usage(exit_code = None): |
| 76 | + |
| 77 | + print("""Usage: {sys.argv[0]} [-f] [-h <hostname>] [-k] [-q] [-x <extension>] |
| 78 | + -f Force replacement of the existing SSL directory (/etc/irods/ssl) with a new one, containing newly generated files. |
| 79 | + -h In the generated certificate, use the given hostname rather than the value returned from socket.gethostname() |
| 80 | + -k (Keep old secrets files.) Do not generate new key file or dhparams.pem file. |
| 81 | + -q For testing; do a quick generation of a dhparams.pem file rather than waiting on system entropy to make it more secure. |
| 82 | + -x Optional extra extension for appending to end of the filename for the generated certificate. |
| 83 | + --help Print this help. |
| 84 | +
|
| 85 | + Any invalid option prints this help. |
| 86 | + """.format(**globals()), file = sys.stderr) |
| 87 | + if isinstance(exit_code, numbers.Integral): |
| 88 | + exit(exit_code) |
| 89 | + |
74 | 90 | if __name__ == '__main__': |
75 | 91 | import getopt |
76 | 92 | try: |
77 | | - opt, arg_list = getopt.getopt(sys.argv[1:],'x:fh:kq') |
| 93 | + opt, arg_list = getopt.getopt(sys.argv[1:],'x:fh:kq',['help']) |
78 | 94 | except getopt.GetoptError: |
79 | | - print("""Usage: {sys.argv[0]} [-f] [-h <hostname>] [-k] [-q] [-x <extension>] |
80 | | - -f Force replacement of the existing SSL directory (/etc/irods/ssl) with a new one, containing newly generated files. |
81 | | - -h In the generated certificate, use the given hostname rather than the value returned from socket.gethostname() |
82 | | - -k (Keep old secrets files.) Do not generate new key file or dhparams.pem file. |
83 | | - -q For testing; do a quick generation of a dhparams.pem file rather than waiting on system entropy to make it more secure. |
84 | | - -x Optional extra extension for appending to end of the filename for the generated certificate. |
85 | | -
|
86 | | - Any invalid option prints this help. |
87 | | - """.format(**locals()), file = sys.stderr) |
88 | | - exit(1) |
| 95 | + usage(exit_code = 1) |
89 | 96 |
|
90 | 97 | opt_lookup = dict(opt) |
91 | 98 |
|
| 99 | + if '--help' in opt_lookup: |
| 100 | + usage(exit_code = 0) |
| 101 | + |
92 | 102 | ext = opt_lookup.get('-x','') |
93 | 103 | if ext: |
94 | 104 | ext = '.' + ext.lstrip('.') |
|
0 commit comments