1
0
Fork 0

auto deploy from workflow

This commit is contained in:
github-actions[bot] 2022-07-07 01:23:51 +00:00
parent e48560ff17
commit bf48d41274

View file

@ -17,24 +17,30 @@ tmp_dir = "/tmp/com.developomp.setup"
#
# Utility functions
#
# These functions are copied from `src/util.py`.
# These functions are copied from `src/util.py` (except for cleanup).
# Comments can only be found over there.
#
def silent_system(command: str, suppress_error: bool = False) -> None:
if suppress_error:
def run(command: str, hide_stdout: bool = True, hide_stderr: bool = True):
if hide_stderr:
system(f"{command} &> /dev/null")
else:
return
if hide_stdout:
system(f"{command} > /dev/null")
return
system(command)
def run(command: str) -> list[str]:
def run_and_return(command: str) -> list[str]:
return popen(command).readlines()
def command_exists(command: str) -> bool:
return len(run(f"command -v {command}")) == 1
return len(run_and_return(f"command -v {command}")) == 1
def cleanup() -> None:
"""Remove temporary files downloaded or created by this script"""
@ -42,6 +48,7 @@ def cleanup() -> None:
if exists(tmp_dir):
rmtree(tmp_dir)
#
# Check functions
#
@ -96,7 +103,7 @@ def exit_if_no_internet():
"""Exits script if there's no internet connection.
Pings archlinux.org for testing."""
if silent_system("ping -c 1 archlinux.org"):
if run("ping -c 1 archlinux.org"):
print(" Failed to connect to the internet.", file=sys.stderr)
exit(1)
@ -132,7 +139,7 @@ def install_git():
"""Install git if it's not installed already."""
if not command_exists("git"):
system("sudo pacman -S --noconfirm --needed git")
run("sudo pacman -S --noconfirm --needed git")
def clone_repository():
@ -142,14 +149,12 @@ def clone_repository():
cleanup()
# clone repository
if silent_system(
f"git clone --depth 1 https://github.com/developomp/setup.git {tmp_dir}"
):
if run(f"git clone --depth 1 https://github.com/developomp/setup.git {tmp_dir}"):
print(" Failed to clone repository", file=sys.stderr)
exit(1)
# allow everyone to read and write.
if system(f"chmod -R a+rw {tmp_dir}"):
if run(f"chmod -R a+rw {tmp_dir}"):
print(" Failed to change file permission for cloned repo", file=sys.stderr)
exit(1)