fix: build option

This commit is contained in:
Domingo Dirutigliano
2024-04-21 17:17:43 +02:00
parent 9233b759df
commit 3e0cb28cb5

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from __future__ import annotations
import argparse, sys, platform, os, multiprocessing, subprocess, getpass import argparse, sys, platform, os, multiprocessing, subprocess, getpass
pref = "\033[" pref = "\033["
@@ -7,6 +7,8 @@ reset = f"{pref}0m"
composefile = "firegex-compose-tmp-file.yml" composefile = "firegex-compose-tmp-file.yml"
os.chdir(os.path.dirname(os.path.realpath(__file__))) os.chdir(os.path.dirname(os.path.realpath(__file__)))
#Terminal colors
class colors: class colors:
black = "30m" black = "30m"
red = "31m" red = "31m"
@@ -23,7 +25,7 @@ def puts(text, *args, color=colors.white, is_bold=False, **kwargs):
def sep(): puts("-----------------------------------", is_bold=True) def sep(): puts("-----------------------------------", is_bold=True)
def check_if_exists(program): def check_if_exists(program):
return subprocess.call(['sh', '-c',program], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) == 0 return subprocess.call(['sh', '-c', program], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) == 0
def composecmd(cmd, composefile=None): def composecmd(cmd, composefile=None):
if composefile: if composefile:
@@ -46,22 +48,28 @@ def dockercmd(cmd):
puts("Docker not found! please install docker!", color=colors.red) puts("Docker not found! please install docker!", color=colors.red)
def gen_args(): def gen_args():
parser = argparse.ArgumentParser()
#Main parser
parser = argparse.ArgumentParser(description="Firegex Manager")
if os.path.isfile("./Dockerfile"):
parser.add_argument('--build', "-b", dest="bef_build", required=False, action="store_true", help='Build the container from source', default=False)
subcommands = parser.add_subparsers(dest="command", help="Command to execute [Default start if not running]") subcommands = parser.add_subparsers(dest="command", help="Command to execute [Default start if not running]")
#Compose Command #Compose Command
parser_compose = subcommands.add_parser('compose', help='Run docker compose command') parser_compose = subcommands.add_parser('compose', help='Run docker compose command')
parser_compose.add_argument('compose_args', nargs=argparse.REMAINDER, help='Arguments to pass to docker compose', default=[]) parser_compose.add_argument('compose-args', nargs=argparse.REMAINDER, help='Arguments to pass to docker compose', default=[])
#Start Command #Start Command
parser_start = subcommands.add_parser('start', help='Start the firewall') parser_start = subcommands.add_parser('start', help='Start the firewall')
parser_start.add_argument('--threads', "-t", type=int, required=False, help='Number of threads started for each service/utility', default=-1) parser_start.add_argument('--threads', "-t", type=int, required=False, help='Number of threads started for each service/utility', default=-1)
parser_start.add_argument('--build', "-b", required=False, action="store_true", help='Build the container locally', default=False)
parser_start.add_argument('--psw-no-interactive',type=str, required=False, help='Password for no-interactive mode', default=None) parser_start.add_argument('--psw-no-interactive',type=str, required=False, help='Password for no-interactive mode', default=None)
parser_start.add_argument('--startup-psw','-P', required=False, action="store_true", help='Insert password in the startup screen of firegex', default=False) parser_start.add_argument('--startup-psw','-P', required=False, action="store_true", help='Insert password in the startup screen of firegex', default=False)
parser_start.add_argument('--port', "-p", type=int, required=False, help='Port where open the web service of the firewall', default=4444) parser_start.add_argument('--port', "-p", type=int, required=False, help='Port where open the web service of the firewall', default=4444)
parser_start.add_argument('--logs', required=False, action="store_true", help='Show firegex logs', default=False) parser_start.add_argument('--logs', required=False, action="store_true", help='Show firegex logs', default=False)
if os.path.isfile("./Dockerfile"):
parser_start.add_argument('--build', "-b", required=False, action="store_true", help='Build the container from source', default=False)
#Stop Command #Stop Command
parser_stop = subcommands.add_parser('stop', help='Stop the firewall') parser_stop = subcommands.add_parser('stop', help='Stop the firewall')
@@ -69,11 +77,30 @@ def gen_args():
parser_restart = subcommands.add_parser('restart', help='Restart the firewall') parser_restart = subcommands.add_parser('restart', help='Restart the firewall')
parser_restart.add_argument('--logs', required=False, action="store_true", help='Show firegex logs', default=False) parser_restart.add_argument('--logs', required=False, action="store_true", help='Show firegex logs', default=False)
args = parser.parse_args()
#General args if args.command is None:
if os.path.isfile("./Dockerfile"): if not check_already_running() and not args.clear:
parser.add_argument('--build', "-b", required=False, action="store_true", help='Build the container from source', default=False) args.command = "start"
return parser.parse_args()
if not "threads" in args or args.threads < 1:
args.threads = multiprocessing.cpu_count()
if not "port" in args or args.port < 1:
args.port = 4444
if not "clear" in args:
args.clear = False
if not "bef_build" in args:
args.bef_build = False
if not "build" in args:
args.build = False
args.build = args.bef_build or args.build
return args
args = gen_args() args = gen_args()
@@ -173,8 +200,6 @@ def delete_volume():
def main(): def main():
print(args)
if not check_if_exists("docker"): if not check_if_exists("docker"):
puts("Docker not found! please install docker and docker compose!", color=colors.red) puts("Docker not found! please install docker and docker compose!", color=colors.red)
exit() exit()
@@ -186,10 +211,6 @@ def main():
puts("Cannot use docker, the user hasn't the permission or docker isn't running", color=colors.red) puts("Cannot use docker, the user hasn't the permission or docker isn't running", color=colors.red)
exit() exit()
if args.command is None:
if not check_already_running() and not args.clear:
args.command = "start"
if not is_linux(): if not is_linux():
sep() sep()
puts("--- WARNING ---", color=colors.yellow) puts("--- WARNING ---", color=colors.yellow)
@@ -201,12 +222,6 @@ def main():
puts("The nfqueue kernel module seems not loaded, some features of firegex may not work.", color=colors.red) puts("The nfqueue kernel module seems not loaded, some features of firegex may not work.", color=colors.red)
sep() sep()
if not "threads" in args or args.threads < 1:
args.threads = multiprocessing.cpu_count()
if not "port" in args or args.port < 1:
args.port = 4444
if args.command: if args.command:
match args.command: match args.command:
case "start": case "start":
@@ -244,7 +259,7 @@ def main():
write_compose() write_compose()
if "clear" in args and args.clear: if args.clear:
if volume_exists(): if volume_exists():
delete_volume() delete_volume()
else: else: