67 lines
2.0 KiB
Python
Executable File
67 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
|
|
import logging, sys
|
|
import requests as r
|
|
from utils import *
|
|
|
|
ARCH = "x86_64"
|
|
|
|
def main():
|
|
packages = load_config()
|
|
clean_directories()
|
|
|
|
commands = []
|
|
diffs = 0
|
|
|
|
# Manage each package
|
|
for p in packages:
|
|
# Retreive tag to apply
|
|
if 'tag' in p:
|
|
logging.debug(f"{p['name']} forced to {p['tag']}")
|
|
elif 'repo' in p:
|
|
p['tag'] = get_tags_from_git(p['repo'])
|
|
else:
|
|
p['tag'] = get_package_version(p['name'], ARCH)
|
|
|
|
# Retreive current package version
|
|
current_tag = get_package_version(p['name'], ARCH)
|
|
|
|
# Check if update is required
|
|
if p['tag'] != current_tag:
|
|
logging.info(f"{p['name']} will be updated: {current_tag} → {p['tag']}")
|
|
render_pkgbuild(p['name'], p['tag'])
|
|
commands.append(f"su -c '/tmp/build.sh /tmp/pkgbuilds/{p['name']}' user")
|
|
diffs += 1
|
|
else:
|
|
tarball, url = get_package_tarball(p['name'], ARCH)
|
|
logging.info(f"{p['name']} will be retreived from {url}")
|
|
content = r.get(url).content
|
|
with open(f"packages/{tarball}", "wb") as file:
|
|
file.write(content)
|
|
commands.append(f"pacman -U --noconfirm /tmp/packages/{tarball}")
|
|
|
|
# Write the installation script
|
|
with open("scripts/run.sh", "w") as file:
|
|
file.write("#!/usr/bin/env bash\n")
|
|
file.write("useradd user\n")
|
|
file.write("echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers\n")
|
|
file.write(" && \\\n".join(commands))
|
|
|
|
if diffs == 0:
|
|
logging.info("no updates planned")
|
|
sys.exit(0)
|
|
|
|
docker_build()
|
|
|
|
# TODO:
|
|
# - push them to the repository
|
|
# - create a systemd timer to run this script
|
|
# - setup a web server to publish logs in case of failure
|
|
# - go to bed >_>
|
|
|
|
if __name__ == "__main__":
|
|
logging.basicConfig(format="[%(asctime)s] %(levelname)s (%(filename)s.%(funcName)s): %(message)s",
|
|
level=logging.INFO)
|
|
main()
|