added more python files
This commit is contained in:
parent
3a81ab3533
commit
35abf7b27a
5 changed files with 166 additions and 0 deletions
106
setup.py
Normal file → Executable file
106
setup.py
Normal file → Executable file
|
@ -1 +1,107 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
developomp's arch linux setup script
|
||||
|
||||
This file is all that's needed for execution.
|
||||
It'll download all the dependencies and related files automatically.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from shutil import rmtree
|
||||
|
||||
|
||||
def minimal_check():
|
||||
"""
|
||||
Minimal checks before executing any code.
|
||||
Full checks will happen after downloading codes from the internet
|
||||
"""
|
||||
|
||||
#
|
||||
# check if OS is linux and if pacman exists
|
||||
#
|
||||
|
||||
if (
|
||||
"linux" not in sys.platform.lower()
|
||||
or os.system("command -v pacman &> /dev/null") != 0
|
||||
):
|
||||
print("This script should only be used on arch linux.", file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
#
|
||||
# check if the script is running as root
|
||||
#
|
||||
|
||||
# todo: allow running script as root when implementing user creation/arch installation logic
|
||||
if os.geteuid() == 0:
|
||||
print("Do not run this script as root.", file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
#
|
||||
# check if there's internet connection
|
||||
#
|
||||
|
||||
if os.system("ping -c 1 archlinux.org &> /dev/null") != 0:
|
||||
print("Failed to connect to internet.", file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
|
||||
def minimal_initialization():
|
||||
"""
|
||||
Does minimal initialization.
|
||||
Full initialization will happen after downloading codes from the internet.
|
||||
"""
|
||||
|
||||
#
|
||||
# Install git
|
||||
#
|
||||
|
||||
if os.system("command -v git &> /dev/null") != 0:
|
||||
print("git was not installed already. Installing now.")
|
||||
os.system("sudo pacman -S --noconfirm --needed git")
|
||||
|
||||
#
|
||||
# Download necessary files
|
||||
#
|
||||
|
||||
tmp_dir = "/tmp/com.developomp.setup"
|
||||
|
||||
# remove existing files
|
||||
if os.path.exists(tmp_dir):
|
||||
rmtree(tmp_dir)
|
||||
|
||||
# todo: change branch to master when merging with master
|
||||
if (
|
||||
os.system(
|
||||
f"git clone --depth 1 -b dev https://github.com/developomp/setup.git {tmp_dir} &> /dev/null"
|
||||
)
|
||||
!= 0
|
||||
):
|
||||
print("Failed to clone repository", file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
# allow everyone to read and write but not execute.
|
||||
if os.system(f"chmod -R a+rw {tmp_dir}") != 0:
|
||||
print("Failed to change file permission for cloned repo", file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
#
|
||||
# Add cloned directory to path
|
||||
#
|
||||
|
||||
sys.path.append(tmp_dir)
|
||||
|
||||
|
||||
def main():
|
||||
minimal_check()
|
||||
minimal_initialization()
|
||||
|
||||
from src.entry import entry
|
||||
|
||||
# hand over control to cloned code
|
||||
entry()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
5
src/entry.py
Normal file
5
src/entry.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from .initialize import initialize
|
||||
|
||||
|
||||
def entry():
|
||||
initialize()
|
15
src/initialize.py
Normal file
15
src/initialize.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import os
|
||||
|
||||
|
||||
def initialize():
|
||||
"""
|
||||
- install [pytermgui](https://github.com/bczsalba/pytermgui)
|
||||
- install pip
|
||||
- install flatpak
|
||||
"""
|
||||
|
||||
#
|
||||
# Install flatpak
|
||||
#
|
||||
|
||||
os.system("sudo pacman -S --noconfirm --needed flatpak")
|
40
src/log.py
Normal file
40
src/log.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
# https://stackoverflow.com/a/33206814/12979111
|
||||
|
||||
RESET = "\e[0m"
|
||||
|
||||
# style
|
||||
BOLD = "\e[1m"
|
||||
INVERT = "\e[7m"
|
||||
|
||||
# colors
|
||||
RED = "\e[91m" # actually light red
|
||||
GREEN = "\e[92m" # actually light green
|
||||
YELLOW = "\e[33m"
|
||||
|
||||
|
||||
def log_no_label(msg: str):
|
||||
print(f"{GREEN}{BOLD}{msg}{RESET}")
|
||||
|
||||
|
||||
def warn_no_label(msg: str):
|
||||
print(f"{YELLOW}{BOLD}{msg}{RESET}")
|
||||
|
||||
|
||||
def error_no_label(msg: str):
|
||||
print(f"{RED}{BOLD}{msg}{RESET}")
|
||||
|
||||
|
||||
def log(msg: str):
|
||||
print(f" {GREEN}{BOLD} INFO | {msg}{RESET}")
|
||||
|
||||
|
||||
def warn(msg: str):
|
||||
print(f" {YELLOW}{BOLD} WARNING | {msg}{RESET}")
|
||||
|
||||
|
||||
def error(msg: str):
|
||||
print(f" {RED}{BOLD} ERROR | {msg}{RESET}")
|
||||
|
||||
|
||||
def title(msg: str):
|
||||
print(f"\n{BOLD}{GREEN}====================[ {msg} ]===================={RESET}")
|
Loading…
Add table
Add a link
Reference in a new issue