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