configs/arch-config/scripts/arch-config.py

100 lines
2.1 KiB
Python
Raw Normal View History

2022-12-07 21:10:22 +01:00
#!/usr/bin/env python3
import subprocess
import os
import uuid
import glob
import shutil
import filecmp
import importlib.util
import sys
def select_theme():
"""
Function to select a different theme
"""
pass
def update_firefox():
"""
Function to also update firefox config
"""
pass
def main():
2022-12-07 21:19:12 +01:00
# TODO
if not os.path.isfile(os.path.join(home, ".seltheme")):
select_theme()
# TODO remove previous backup
# ~/old_dat
# TODO create new backup
2022-12-07 21:10:22 +01:00
print("works")
# Set home path
home = os.path.expanduser("~")
# Check root or run as sudo
if os.getuid() != 0:
subprocess.run("sudo -v", shell=True, check=True)
if __name__ == "__main__":
2022-12-07 21:19:12 +01:00
# TODO arguments
# -t: select theme
# -f: update firefox config
# -h: help
2022-12-07 21:10:22 +01:00
# change to home directory
os.chdir(home)
# slightly random uuid for our config location
configdir = "config-" + str(uuid.uuid1())
# TODO remove old "config-" folder(s)
2022-12-07 21:19:12 +01:00
# https://stackoverflow.com/a/70860760
2022-12-07 21:10:22 +01:00
# clone git repo
subprocess.run(
"git clone https://gitlab.com/RealStickman-arch/config.git {configdir}".format(
configdir=configdir
),
shell=True,
check=True,
)
os.chdir(configdir)
subprocess.run(
2022-12-07 21:19:12 +01:00
"git checkout master",
shell=True,
check=True,
stderr=subprocess.STDOUT,
stdout=subprocess.DEVNULL,
2022-12-07 21:10:22 +01:00
)
os.chdir(home)
# check if downloaded script is different
if not filecmp.cmp(
os.path.join(home, "scripts/arch-config.py"),
os.path.join(configdir, "scripts/arch-config.py"),
):
print("Found newer config file")
2022-12-07 21:19:12 +01:00
# import newer script version
2022-12-07 21:10:22 +01:00
spec = importlib.util.spec_from_file_location(
"config",
os.path.join(configdir, "scripts/arch-config.py"),
)
config = importlib.util.module_from_spec(spec)
sys.modules["config"] = config
spec.loader.exec_module(config)
2022-12-07 21:20:21 +01:00
# call new main function
2022-12-07 21:10:22 +01:00
config.main()
else:
print("Config is up to date")
2022-12-07 21:20:21 +01:00
# call main function
main()