diff --git a/app/file.py b/app/file.py index 655f342..6aa0498 100644 --- a/app/file.py +++ b/app/file.py @@ -2,7 +2,7 @@ import click import subprocess as sp import os -from app.helper import install_available +from app.helper import install_available, get_distro_name @click.group() def file_scan(): @@ -44,13 +44,14 @@ def setup(path, base_dir, file_prefix, etcd_url, branch): # Create virtualenv with site-packages enabled and install all dependencies sp.check_output(['pipenv', 'install'], cwd=repo_name) - # TODO: Devuan/Debian have crontab under /etc/crontab - # while Alpine have it under /etc/crontabs/root - # Detect in the following code where should we write - # our crontab entries # Write Crontab entry - with open("/etc/crontabs/root", "a") as crontab: + if get_distro_name() == "alpine": + crontab_path = "/etc/crontabs/root" + else: + crontab_path = "/etc/crontab" + + with open(crontab_path, "a") as crontab: crontab.write( f"*/1\t*\t*\t*\t*\t$(cd {os.path.join(os.getcwd(), repo_name)} && pipenv run python main.py)\n" - ) + ) \ No newline at end of file diff --git a/app/image.py b/app/image.py index dfcf005..aa0fd0c 100644 --- a/app/image.py +++ b/app/image.py @@ -2,7 +2,7 @@ import click import subprocess as sp import os -from app.helper import install_available +from app.helper import install_available, get_distro_name @click.group() def image(): @@ -42,15 +42,14 @@ def setup(path, base_dir, etcd_url, without_ceph, branch): install_available(repo_name) sp.check_output(['pipenv', 'install'], cwd=repo_name) - - # TODO: Devuan/Debian have crontab under /etc/crontab - # while Alpine have it under /etc/crontabs/root - # Detect in the following code where should we write - # our crontab entries - - + # Write Crontab entry - with open("/etc/crontabs/root", "a") as crontab: + if get_distro_name() == "alpine": + crontab_path = "/etc/crontabs/root" + else: + crontab_path = "/etc/crontab" + + with open(crontab_path, "a") as crontab: crontab.write( f"*/1\t*\t*\t*\t*\t$(cd {os.path.join(os.getcwd(), repo_name)} && pipenv run python main.py)\n" )