Add generation of run.sh

Remove useless file
Add some logging
This commit is contained in:
Darks 2021-06-09 00:18:04 +02:00
parent c185215c25
commit 569a56c4bc
Signed by: Darks
GPG Key ID: 7515644268BE1433
3 changed files with 28 additions and 23 deletions

28
main.py
View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
import logging
import logging, sys
import requests as r
from utils import *
@ -9,9 +9,11 @@ ARCH = "x86_64"
def main():
packages = load_config()
clean_directories()
commands = []
diffs = 0
# Manage each package
for p in packages:
# Retreive tag to apply
@ -29,13 +31,35 @@ def main():
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)
# TODO:
# - build the container with a tag
# - run it
# - retreive built packages if everthing is fine
# - 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",

View File

@ -1,21 +0,0 @@
#!/usr/bin/env bash
useradd user
echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
pacman -U /tmp/packages/isl-0.24-1.tar.gz --no-confirm
pacman -U /tmp/packages/sh-elf-binutils-casio-2.36.1-3.tar.gz --no-confirm
pacman -U /tmp/packages/sh-elf-gcc-casio-11.1.0-4.tar.gz --no-confirm
pacman -U /tmp/packages/openlibm-casio-0.7.5-2.tar.gz --no-confirm
su -c '/tmp/build.sh /tmp/pkgbuilds/mkg3a' user
pacman -U /tmp/packages/fxsdk-2.5.1-1.tar.gz --no-confirm
su -c '/tmp/build.sh /tmp/pkgbuilds/fxlibc' user
su -c '/tmp/build.sh /tmp/pkgbuilds/gint' user
pacman -U /tmp/packages/libimg-2.4.0-1.tar.gz --no-confirm
pacman -U /tmp/packages/libprof-2.4.0-1.tar.gz --no-confirm
pacman -U /tmp/packages/justui-1.1.0-1.tar.gz --no-confirm
pacman -U /tmp/packages/libp7-3.0-1.tar.gz --no-confirm
pacman -U /tmp/packages/libp7-3.0-1.tar.gz --no-confirm
pacman -U /tmp/packages/p7screen-3.0-2.tar.gz --no-confirm
ls -l /tmp/packages

View File

@ -1,5 +1,6 @@
import hashlib
import jinja2 as j2
import logging
import os
import re
import requests as r
@ -19,6 +20,7 @@ def get_hash(name, tag):
try:
url = regex.search(content).group(1)
except:
logging.warning(f"cannot find valid source for {name} (is it a git version?)")
return "SKIP"
url = url.replace("${pkgver}", tag)
url = url.replace("${pkgname}", name)