fixes on start.py

This commit is contained in:
Domingo Dirutigliano
2023-04-11 22:15:17 +02:00
parent 2e9da270f8
commit 39aa7242d8

View File

@@ -55,11 +55,11 @@ def run_checks():
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()
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--port', "-p", type=int, required=False, help='Port where open the web service of the firewall', default=4444) parser.add_argument('--port', "-p", type=int, required=False, help='Port where open the web service of the firewall', default=4444)
parser.add_argument('--threads', "-t", type=int, required=False, help='Number of threads started for each service/utility', default=-1) parser.add_argument('--threads', "-t", type=int, required=False, help='Number of threads started for each service/utility', default=-1)
parser.add_argument('--no-autostart', "-n", required=False, action="store_true", help='Save docker-compose file and not start the container', default=False) parser.add_argument('--no-autostart', "-n", required=False, action="store_true", help='Save docker-compose file and not start the container', default=False)
parser.add_argument('--build', "-b", required=False, action="store_true", help='Build the container locally', default=False)
parser.add_argument('--keep','-k', required=False, action="store_true", help='Keep the firegex-compose.yml file generated', default=False) parser.add_argument('--keep','-k', required=False, action="store_true", help='Keep the firegex-compose.yml file generated', default=False)
parser.add_argument('--stop', '-s', required=False, action="store_true", help='Stop firegex execution', default=False) parser.add_argument('--stop', '-s', required=False, action="store_true", help='Stop firegex execution', default=False)
parser.add_argument('--restart', '-r', required=False, action="store_true", help='Restart firegex', default=False) parser.add_argument('--restart', '-r', required=False, action="store_true", help='Restart firegex', default=False)
@@ -74,7 +74,9 @@ run_checks()
start_operation = not (args.stop or args.restart) start_operation = not (args.stop or args.restart)
to_build = os.path.isfile("./Dockerfile") and os.path.isfile("./tests/results/test-firegex.xlsx") #random file in firegex repo if args.build and not os.path.isfile("./Dockerfile"):
puts("This is not a clone of firegex, to build firegex the clone of the repository is needed!", color=colors.red)
exit()
if args.threads < 1: if args.threads < 1:
args.threads = multiprocessing.cpu_count() args.threads = multiprocessing.cpu_count()
@@ -92,8 +94,10 @@ if start_operation:
elif not args.startup_psw: elif not args.startup_psw:
puts("Insert the password for firegex: ", end="" , color=colors.yellow, is_bold=True) puts("Insert the password for firegex: ", end="" , color=colors.yellow, is_bold=True)
psw_set = input() psw_set = input()
with open("firegex-compose.yml","wt") as compose: composefile = "firegex-compose.yml"
with open(composefile,"wt") as compose:
if "linux" in sys.platform and not 'microsoft-standard' in platform.uname().release: #Check if not is a wsl also if "linux" in sys.platform and not 'microsoft-standard' in platform.uname().release: #Check if not is a wsl also
compose.write(f""" compose.write(f"""
@@ -102,7 +106,7 @@ version: '3.9'
services: services:
firewall: firewall:
restart: unless-stopped restart: unless-stopped
{"build: ." if to_build else "image: ghcr.io/pwnzer0tt1/firegex"} {"build: ." if args.build else "image: ghcr.io/pwnzer0tt1/firegex"}
network_mode: "host" network_mode: "host"
environment: environment:
- PORT={args.port} - PORT={args.port}
@@ -124,7 +128,7 @@ version: '3.9'
services: services:
firewall: firewall:
restart: unless-stopped restart: unless-stopped
{"build: ." if to_build else "image: ghcr.io/pwnzer0tt1/firegex"} {"build: ." if args.build else "image: ghcr.io/pwnzer0tt1/firegex"}
ports: ports:
- {args.port}:{args.port} - {args.port}:{args.port}
environment: environment:
@@ -138,7 +142,6 @@ services:
""") """)
sep() sep()
if not args.no_autostart: if not args.no_autostart:
composefile = None if to_build else "firegex-compose.yml"
try: try:
if args.restart: if args.restart:
puts("Running 'docker-compose restart'\n", color=colors.green) puts("Running 'docker-compose restart'\n", color=colors.green)
@@ -147,14 +150,14 @@ if not args.no_autostart:
puts("Running 'docker-compose down'\n", color=colors.green) puts("Running 'docker-compose down'\n", color=colors.green)
composecmd("down", composefile) composecmd("down", composefile)
else: else:
if not to_build: if not args.build:
puts("Downloading docker image from github packages 'docker pull ghcr.io/pwnzer0tt1/firegex'", color=colors.green) puts("Downloading docker image from github packages 'docker pull ghcr.io/pwnzer0tt1/firegex'", color=colors.green)
dockercmd("pull ghcr.io/pwnzer0tt1/firegex") dockercmd("pull ghcr.io/pwnzer0tt1/firegex")
puts("Running 'docker-compose up -d --build'\n", color=colors.green) puts("Running 'docker-compose up -d --build'\n", color=colors.green)
composecmd("up -d --build", composefile) composecmd("up -d --build", composefile)
finally: finally:
if not args.keep: if not args.keep:
os.remove("firegex-compose.yml") os.remove(composefile)
else: else:
puts("Done! You can start/stop firegex with docker-compose up -d --build", color=colors.yellow) puts("Done! You can start/stop firegex with docker-compose up -d --build", color=colors.yellow)
sep() sep()