auto deploy from workflow
This commit is contained in:
parent
78dc82fa92
commit
6ad4bd0080
1 changed files with 110 additions and 116 deletions
226
index.html
226
index.html
|
@ -1,10 +1,9 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
developomp's arch linux setup script
|
> developomp's Arch Linux setup script <
|
||||||
|
|
||||||
This file is all that's needed for execution.
|
For more information, please refer to the repository (https://github.com/developomp/setup).
|
||||||
It'll download all the dependencies and related files automatically.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from os import system, geteuid, popen
|
from os import system, geteuid, popen
|
||||||
|
@ -16,111 +15,32 @@ import sys
|
||||||
tmp_dir = "/tmp/com.developomp.setup"
|
tmp_dir = "/tmp/com.developomp.setup"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Util
|
# Utility functions
|
||||||
#
|
#
|
||||||
# These commands are from `src/util.py`.
|
# These functions are copied from `src/util.py`.
|
||||||
# Comments can only be found over there.
|
# Comments can only be found over there.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
def silent_system(command: str) -> None:
|
def silent_system(command: str, suppress_error: bool = True) -> None:
|
||||||
system(f"{command} &> /dev/null")
|
if suppress_error:
|
||||||
|
system(f"{command} &> /dev/null")
|
||||||
|
else:
|
||||||
|
system(f"{command} > /dev/null")
|
||||||
|
|
||||||
|
|
||||||
def command_exits(command: str) -> bool:
|
def run(command: str) -> list[str]:
|
||||||
return len(popen(f"command -v {command}").readlines()) == 1
|
return popen(command).readlines()
|
||||||
|
|
||||||
|
|
||||||
#
|
def command_exists(command: str) -> bool:
|
||||||
# Common
|
return len(run(f"command -v {command}")) == 1
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
def cleanup():
|
|
||||||
"""Removes temporary files and folders downloaded by this script"""
|
|
||||||
|
|
||||||
if exists(tmp_dir):
|
|
||||||
rmtree(tmp_dir)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Checks
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
def exit_if_root():
|
|
||||||
"""Exits script if it was executed as root"""
|
|
||||||
|
|
||||||
# todo: allow running script as root when implementing user creation/arch installation logic
|
|
||||||
if geteuid() == 0:
|
|
||||||
print("Do not run this script as root.", file=sys.stderr)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def exit_if_invalid_python_version():
|
|
||||||
"""Exits script if python version is lower than 3.7"""
|
|
||||||
|
|
||||||
# todo: implement
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def exit_if_system_not_compatible():
|
|
||||||
"""Exits script if the OS is not linux or if pacman does not exist"""
|
|
||||||
|
|
||||||
print("Checking if system is compatible")
|
|
||||||
if "linux" not in sys.platform.lower() or not command_exits("pacman"):
|
|
||||||
print("This script should only be used on arch linux.", file=sys.stderr)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def exit_if_no_internet():
|
|
||||||
"""Exits script if there's no internet connection.
|
|
||||||
Pings archlinux.org for testing."""
|
|
||||||
|
|
||||||
print("Checking if there's internet connection")
|
|
||||||
if silent_system("ping -c 1 archlinux.org"):
|
|
||||||
print("Failed to connect to internet.", file=sys.stderr)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Initializations
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
def install_git():
|
|
||||||
"""Installs git if it's not installed already"""
|
|
||||||
|
|
||||||
print("Initializing git")
|
|
||||||
if not command_exits("git"):
|
|
||||||
print("git was not installed already. Installing now.")
|
|
||||||
system("sudo pacman -S --noconfirm --needed git")
|
|
||||||
|
|
||||||
|
|
||||||
def clone_repository():
|
|
||||||
"""Clone this repository (https://github.com/developomp/setup) to `/tmp` directory"""
|
|
||||||
|
|
||||||
print("Cloning git repository")
|
|
||||||
|
|
||||||
# remove existing files first
|
|
||||||
cleanup()
|
|
||||||
|
|
||||||
# clone repository
|
|
||||||
if silent_system(
|
|
||||||
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}"):
|
|
||||||
print("Failed to change file permission for cloned repo", file=sys.stderr)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
# Check functions
|
||||||
#
|
#
|
||||||
|
# Checks environment incompatibility and apply fix if possible.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,45 +50,119 @@ def minimal_check():
|
||||||
Full checks will happen after downloading codes from the internet
|
Full checks will happen after downloading codes from the internet
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
print("Running checks...")
|
||||||
|
|
||||||
exit_if_root()
|
exit_if_root()
|
||||||
exit_if_invalid_python_version()
|
exit_if_invalid_python_version()
|
||||||
exit_if_system_not_compatible()
|
exit_if_os_not_compatible()
|
||||||
exit_if_no_internet()
|
exit_if_no_internet()
|
||||||
|
|
||||||
|
|
||||||
def minimal_initialization():
|
def exit_if_root():
|
||||||
|
"""Terminate execution if the script is being executed with superuser privilege."""
|
||||||
|
|
||||||
|
if geteuid() == 0:
|
||||||
|
print(" Do not run this script as root.", file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def exit_if_invalid_python_version():
|
||||||
|
"""Terminates execution if the python version is lower than 3.7"""
|
||||||
|
|
||||||
|
if sys.version_info.major != 3 or sys.version_info.minor < 7:
|
||||||
|
from platform import python_version
|
||||||
|
|
||||||
|
print(
|
||||||
|
f" Your python version ({python_version()}) does not meet the minimum requirement (3.7).",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def exit_if_os_not_compatible():
|
||||||
|
"""Terminate execution if the OS is not Arch Linux based."""
|
||||||
|
|
||||||
|
if "linux" not in sys.platform.lower() or not command_exists("pacman"):
|
||||||
|
print(" Incompatible OS.", file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
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"):
|
||||||
|
print(" Failed to connect to the internet.", file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Bootstrap functions
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
def bootstrap():
|
||||||
"""
|
"""
|
||||||
Does minimal initialization.
|
Does minimal initialization.
|
||||||
Full initialization will happen after downloading codes from the internet.
|
Full initialization will happen after downloading codes from the internet.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
print("Bootstrapping...")
|
||||||
|
|
||||||
install_git()
|
install_git()
|
||||||
|
|
||||||
# skip if testing
|
# When testing, there is no need to download the repository.
|
||||||
if exists(".git/") and exists("src/"):
|
if not exists("src/"):
|
||||||
return
|
clone_repository()
|
||||||
|
|
||||||
clone_repository()
|
# Add cloned directory to system path
|
||||||
|
sys.path.append(tmp_dir)
|
||||||
# Add cloned directory to system path
|
|
||||||
sys.path.append(tmp_dir)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
minimal_check()
|
|
||||||
minimal_initialization()
|
|
||||||
|
|
||||||
from src.entry import entry
|
from src.entry import entry
|
||||||
|
|
||||||
entry()
|
entry()
|
||||||
|
|
||||||
|
|
||||||
|
def install_git():
|
||||||
|
"""Install git if it's not installed already."""
|
||||||
|
|
||||||
|
if not command_exists("git"):
|
||||||
|
system("sudo pacman -S --noconfirm --needed git")
|
||||||
|
|
||||||
|
|
||||||
|
def clone_repository():
|
||||||
|
"""Clone the setup repository (https://github.com/developomp/setup) to `/tmp` directory"""
|
||||||
|
|
||||||
|
# remove existing files first
|
||||||
cleanup()
|
cleanup()
|
||||||
|
|
||||||
|
# clone repository
|
||||||
|
if silent_system(
|
||||||
|
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}"):
|
||||||
|
print(" Failed to change file permission for cloned repo", file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Main function
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
minimal_check()
|
||||||
|
bootstrap()
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
# Remove temporary files downloaded by this script
|
||||||
|
if exists(tmp_dir):
|
||||||
|
rmtree(tmp_dir)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue