forked from cisagov/Malcolm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeat_config.py
executable file
·92 lines (77 loc) · 2.76 KB
/
beat_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2022 Battelle Energy Alliance, LLC. All rights reserved.
from __future__ import print_function
import argparse
import os
import platform
import sys
from beat_common import *
###################################################################################################
ScriptName = os.path.basename(__file__)
###################################################################################################
# main
def main():
# extract arguments from the command line
# print (sys.argv[1:]);
parser = argparse.ArgumentParser(
description='Beat configure script', add_help=False, usage='{} <arguments>'.format(ScriptName)
)
parser.add_argument(
'-v', '--verbose', dest='debug', type=str2bool, nargs='?', const=True, default=False, help="Verbose output"
)
parser.add_argument(
'-b', '--beat', required=True, dest='beatName', metavar='<STR>', type=str, default=None, help='Beat name'
)
parser.add_argument(
'-c',
'--config-file',
required=False,
dest='configFile',
metavar='<STR>',
type=str,
default=None,
help='Beat YML file to configure',
)
parser.add_argument(
'-d',
'--defaults',
dest='acceptDefault',
type=str2bool,
nargs='?',
const=True,
default=False,
help="Accept defaults to prompts without user interaction",
)
try:
parser.error = parser.exit
args = parser.parse_args()
except SystemExit:
parser.print_help()
exit(2)
if args.debug:
eprint(os.path.join(ScriptPath, ScriptName))
eprint("Arguments: {}".format(sys.argv[1:]))
eprint("Arguments: {}".format(args))
else:
sys.tracebacklimit = 0
args.beatName = args.beatName.lower()
if not args.beatName.endswith('beat'):
args.beatName = args.beatName + 'beat'
if args.configFile is None:
args.configFile = args.beatName + '.yml'
installerPlatform = platform.system()
if installerPlatform == PLATFORM_LINUX:
Beatbox = LinuxBeatbox(debug=args.debug, ymlFileSpec=args.configFile, beatName=args.beatName)
elif installerPlatform == PLATFORM_MAC:
Beatbox = MacBeatbox(debug=args.debug, ymlFileSpec=args.configFile, beatName=args.beatName)
elif installerPlatform == PLATFORM_WINDOWS:
Beatbox = WindowsBeatbox(debug=args.debug, ymlFileSpec=args.configFile, beatName=args.beatName)
success = False
if hasattr(Beatbox, 'configure_beat_yml'):
success = Beatbox.configure_beat_yml()
if hasattr(Beatbox, 'configure_keystore'):
success = Beatbox.configure_keystore()
return success
if __name__ == '__main__':
main()