fix: windows command....

This commit is contained in:
Domingo Dirutigliano
2024-07-04 14:31:41 +02:00
parent c4830d7125
commit b33b0b46d7

View File

@@ -4,9 +4,9 @@ import argparse, sys, platform, os, multiprocessing, subprocess, getpass
pref = "\033[" pref = "\033["
reset = f"{pref}0m" reset = f"{pref}0m"
class g:
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 #Terminal colors
class colors: class colors:
@@ -24,8 +24,10 @@ 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, get_output=False):
return subprocess.call(['sh', '-c', program], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) == 0 if get_output:
return subprocess.getoutput(program)
return subprocess.call(program, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, shell=True) == 0
def composecmd(cmd, composefile=None): def composecmd(cmd, composefile=None):
if composefile: if composefile:
@@ -47,8 +49,9 @@ def dockercmd(cmd):
else: else:
puts("Docker not found! please install docker!", color=colors.red) puts("Docker not found! please install docker!", color=colors.red)
def check_already_running(): def check_already_running():
return check_if_exists("docker ps --filter 'name=^firegex$' --no-trunc | grep firegex") return "firegex" in check_if_exists(f'docker ps --filter "name=^firegex$"', get_output=True)
def gen_args(args_to_parse: list[str]|None = None): def gen_args(args_to_parse: list[str]|None = None):
@@ -114,7 +117,7 @@ def is_linux():
def write_compose(skip_password = True): def write_compose(skip_password = True):
psw_set = get_password() if not skip_password else None psw_set = get_password() if not skip_password else None
with open(composefile,"wt") as compose: with open(g.composefile,"wt") as compose:
if is_linux(): #Check if not is a wsl also if is_linux(): #Check if not is a wsl also
compose.write(f""" compose.write(f"""
@@ -193,8 +196,9 @@ def get_password():
break break
return psw_set return psw_set
def volume_exists(): def volume_exists():
return check_if_exists('docker volume ls --filter="name=^firegex_firegex_data$" --quiet | grep firegex_firegex_data') return "firegex_firegex_data" in check_if_exists(f'docker volume ls --filter "name=^firegex_firegex_data$"', get_output=True)
def nfqueue_exists(): def nfqueue_exists():
import socket, fcntl, os, time import socket, fcntl, os, time
@@ -270,24 +274,24 @@ def main():
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", g.composefile)
case "compose": case "compose":
write_compose() write_compose()
compose_cmd = " ".join(args.compose_args) compose_cmd = " ".join(args.compose_args)
puts(f"Running 'docker compose {compose_cmd}'\n", color=colors.green) puts(f"Running 'docker compose {compose_cmd}'\n", color=colors.green)
composecmd(compose_cmd, composefile) composecmd(compose_cmd, g.composefile)
case "restart": case "restart":
if check_already_running(): if check_already_running():
write_compose() write_compose()
puts("Running 'docker compose restart'\n", color=colors.green) puts("Running 'docker compose restart'\n", color=colors.green)
composecmd("restart", composefile) composecmd("restart", g.composefile)
else: else:
puts("Firegex is not running!" , color=colors.red, is_bold=True, flush=True) puts("Firegex is not running!" , color=colors.red, is_bold=True, flush=True)
case "stop": case "stop":
if check_already_running(): if check_already_running():
write_compose() write_compose()
puts("Running 'docker compose down'\n", color=colors.green) puts("Running 'docker compose down'\n", color=colors.green)
composecmd("down", composefile) composecmd("down", g.composefile)
else: else:
puts("Firegex is not running!" , color=colors.red, is_bold=True, flush=True) puts("Firegex is not running!" , color=colors.red, is_bold=True, flush=True)
@@ -308,7 +312,7 @@ if __name__ == "__main__":
try: try:
main() main()
finally: finally:
if os.path.isfile(composefile): if os.path.isfile(g.composefile):
os.remove(composefile) os.remove(g.composefile)
except KeyboardInterrupt: except KeyboardInterrupt:
print() print()