diff --git a/files/etc/ublue-update.d/system/00-system-update.py b/files/etc/ublue-update.d/system/00-system-update.py deleted file mode 100755 index eb3e399..0000000 --- a/files/etc/ublue-update.d/system/00-system-update.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env python3 - -from subprocess import run -from json import loads, load -from json.decoder import JSONDecodeError -from pathlib import Path - -import os - - -def check_for_rebase(): - # initialize variables - default_image_ref = [] - current_image_ref = [] - default_image_tag = "" - image_tag = "" - - try: - with open("/usr/share/ublue-os/image-info.json") as f: - image_info = load(f) - default_image_ref = image_info["image-ref"].split(":") - default_image_tag = image_info["image-tag"] - except (FileNotFoundError, KeyError): - print("uBlue image info file does not exist") - return False, "" - - # Branch away from the default tag when one is set - branch_file = Path("/var/ublue-update/branch") - if branch_file.exists(): - with branch_file.open() as f: - branch = f.readline() - branch_file.unlink() - if branch: - return ( - True, - f"{default_image_ref[0]}:{default_image_ref[1]}:{default_image_ref[2]}:{branch}", - ) - - status_cmd = [ - "rpm-ostree", - "status", - "--pending-exit-77", - "-b", - "--json", - ] - status_out = run(status_cmd, capture_output=True) - if status_out.returncode != 0: - print(status_out.stdout.decode("utf-8")) - return False, "" - - try: - current_image_ref = ( - loads(status_out.stdout)["deployments"][0]["container-image-reference"] - .replace( - "ostree-unverified-registry:", "ostree-unverified-image:docker://" - ) # replace shorthand - .split(":") - ) - # if the same ref as image-info.json then skip rebase - if current_image_ref[:-1] == default_image_ref: - return False, "" - except (JSONDecodeError, KeyError, IndexError): - print("unable to parse JSON output") - print(status_out.stdout.decode("utf-8")) - return False, "" - - image_tag = default_image_tag - try: - # if we are on an offline ISO installation - # rebase to image-info.json defaults - if current_image_ref[2] == "/var/ublue-os/image": - return ( - True, - f"{default_image_ref[0]}:{default_image_ref[1]}:{default_image_ref[2]}:{default_image_tag}", - ) - - # if current installation doesn't match image-info.json - # skip rebase to be safe - if current_image_ref[2] != default_image_ref[2]: - return False, "" - - # We want to rebase so preserve image tag when rebasing unsigned - if current_image_ref[2] == default_image_ref[2]: - image_tag = current_image_ref[3] - except IndexError: - print("unable to get image tag from current deployment!") - - return ( - True, - f"{default_image_ref[0]}:{default_image_ref[1]}:{default_image_ref[2]}:{image_tag}", - ) - - -if __name__ == "__main__": - rpm_ostree = os.access("/usr/bin/rpm-ostree", os.X_OK) - if not rpm_ostree: - print("system isn't managed by rpm-ostree") - os._exit(1) - rebase, image_ref = check_for_rebase() - if rebase: - rebase_cmd = ["rpm-ostree", "rebase", image_ref] - print(image_ref) - rebase_out = run(rebase_cmd, capture_output=True) - if rebase_out.returncode == 0: - os._exit(0) # rebase sucessful - else: - print("rebase failed!, command output:") - print(rebase_out.stdout.decode("utf-8")) - update_cmd = ["rpm-ostree", "upgrade"] - update_out = run(update_cmd, capture_output=True) - if update_out.returncode != 0: - print( - f"rpm-ostree upgrade returned code {update_out.returncode}, program output:" - ) - print(update_out.stdout.decode("utf-8")) - os._exit(update_out.returncode) diff --git a/files/etc/ublue-update.d/system/01-flatpak-system-update.sh b/files/etc/ublue-update.d/system/01-flatpak-system-update.sh deleted file mode 100755 index cba7208..0000000 --- a/files/etc/ublue-update.d/system/01-flatpak-system-update.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -/usr/bin/flatpak --system update -y --noninteractive diff --git a/files/etc/ublue-update.d/system/02-flatpak-system-repair-cleanup.sh b/files/etc/ublue-update.d/system/02-flatpak-system-repair-cleanup.sh deleted file mode 100755 index b10acc8..0000000 --- a/files/etc/ublue-update.d/system/02-flatpak-system-repair-cleanup.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -/usr/bin/flatpak uninstall --system --unused -y --noninteractive -/usr/bin/flatpak repair --system diff --git a/files/etc/ublue-update.d/user/00-flatpak-user-update.sh b/files/etc/ublue-update.d/user/00-flatpak-user-update.sh deleted file mode 100755 index 76d3b79..0000000 --- a/files/etc/ublue-update.d/user/00-flatpak-user-update.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -/usr/bin/flatpak --user update -y --noninteractive diff --git a/files/etc/ublue-update.d/user/01-flatpak-user-repair-cleanup.sh b/files/etc/ublue-update.d/user/01-flatpak-user-repair-cleanup.sh deleted file mode 100755 index 8046e76..0000000 --- a/files/etc/ublue-update.d/user/01-flatpak-user-repair-cleanup.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - - -/usr/bin/flatpak uninstall --user --unused -y --noninteractive -/usr/bin/flatpak repair --user diff --git a/files/etc/ublue-update.d/user/02-distrobox-user-update.sh b/files/etc/ublue-update.d/user/02-distrobox-user-update.sh deleted file mode 100755 index a45075b..0000000 --- a/files/etc/ublue-update.d/user/02-distrobox-user-update.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -if [ -x /usr/bin/distrobox ]; then - unset SUDO_USER # avoid distrobox sudo checks - /usr/bin/distrobox upgrade -a -fi diff --git a/files/etc/ublue-update.d/user/03-fleek-user-update.sh b/files/etc/ublue-update.d/user/03-fleek-user-update.sh deleted file mode 100755 index c322993..0000000 --- a/files/etc/ublue-update.d/user/03-fleek-user-update.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -if [ -x /var/usrlocal/bin/fleek ]; then - /var/usrlocal/bin/fleek update -a -fi diff --git a/files/etc/ublue-update.d/user/04-brew-update.sh b/files/etc/ublue-update.d/user/04-brew-update.sh deleted file mode 100644 index cb61d0f..0000000 --- a/files/etc/ublue-update.d/user/04-brew-update.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -if command -v /var/home/linuxbrew/.linuxbrew/bin/brew; then - /var/home/linuxbrew/.linuxbrew/bin/brew update --auto-update -fi diff --git a/files/usr/etc/ublue-update/topgrade.toml b/files/usr/etc/ublue-update/topgrade.toml new file mode 100644 index 0000000..a7f645d --- /dev/null +++ b/files/usr/etc/ublue-update/topgrade.toml @@ -0,0 +1,10 @@ +[misc] +only = ["system", "flatpak", "distrobox"] +ignore_failures = ["flatpak", "distrobox"] +skip_notify = true +assume_yes = true +no_retry = true +no_self_update = true + +[linux] +rpm_ostree = true diff --git a/src/ublue_update/cli.py b/src/ublue_update/cli.py index a8e501e..bb8a37d 100644 --- a/src/ublue_update/cli.py +++ b/src/ublue_update/cli.py @@ -86,30 +86,6 @@ def hardware_inhibitor_checks_failed( raise Exception(f"update failed to pass checks: \n - {exception_log}") -def run_update_scripts(root_dir: str): - for root, dirs, files in os.walk(root_dir): - for file in files: - full_path = root_dir + str(file) - executable = os.access(full_path, os.X_OK) - if executable: - log.info(f"Running update script: {full_path}") - out = subprocess.run( - [full_path], - capture_output=True, - ) - if out.returncode != 0: - log.error( - f"{full_path} returned error code: {out.returncode}, program output:" # noqa: E501 - ) - log.error(out.stdout.decode("utf-8")) - notify( - "System Updater", - f"Error in update script: {file}, check logs for more info", - ) - else: - log.info(f"could not execute file {full_path}") - - def run_updates(system, system_update_available): process_uid = os.getuid() filelock_path = "/run/ublue-update.lock" @@ -139,7 +115,6 @@ def run_updates(system, system_update_available): if system: users = [] - run_update_scripts(f"{root_dir}/system/") for user in users: try: xdg_runtime_dir = get_xdg_runtime_dir(user["User"]) @@ -160,8 +135,8 @@ def run_updates(system, system_update_available): "DISPLAY=:0", f"XDG_RUNTIME_DIR={xdg_runtime_dir}", f"DBUS_SESSION_BUS_ADDRESS=unix:path={xdg_runtime_dir}/bus", - "/usr/bin/ublue-update", - "-f", + "/usr/bin/topgrade", + "--config /etc/ublue-update/topgrade.toml", ], capture_output=True, ) @@ -181,7 +156,6 @@ def run_updates(system, system_update_available): raise Exception( "ublue-update needs to be run as root to perform system updates!" ) - run_update_scripts(f"{root_dir}/user/") release_lock(fd) os._exit(0) diff --git a/ublue-update.spec b/ublue-update.spec index 1717145..ef0fb64 100644 --- a/ublue-update.spec +++ b/ublue-update.spec @@ -18,7 +18,6 @@ Supplements: rpm-ostree flatpak BuildRequires: make BuildRequires: systemd-rpm-macros BuildRequires: black -BuildRequires: ShellCheck BuildRequires: python-flake8 BuildRequires: python-build BuildRequires: python-setuptools @@ -45,8 +44,6 @@ ls ls src black src flake8 src -shellcheck files/etc/%{NAME}.d/user/*.sh -shellcheck files/etc/%{NAME}.d/system/*.sh black files/etc/%{NAME}.d/system/*.py flake8 files/etc/%{NAME}.d/system/*.py %pyproject_wheel @@ -56,6 +53,13 @@ flake8 files/etc/%{NAME}.d/system/*.py %pyproject_save_files ublue_update cp -rp files/etc files/usr %{buildroot} +%pre +if [ ! -x /usr/bin/topgrade ] +then + echo "Topgrade not installed. Please install Topgrade (https://github.com/topgrade-rs/topgrade) to use %{name}." + exit 1 +fi + %post %systemd_post %{NAME}.timer @@ -68,8 +72,7 @@ cp -rp files/etc files/usr %{buildroot} %attr(0644,root,root) %{_exec_prefix}/lib/systemd/system/%{NAME}.timer %attr(0644,root,root) %{_exec_prefix}/lib/systemd/system-preset/00-%{NAME}.preset %attr(0644,root,root) %{_exec_prefix}/etc/%{NAME}/%{NAME}.toml -%attr(0755,root,root) %{_sysconfdir}/%{NAME}.d/user/* -%attr(0755,root,root) %{_sysconfdir}/%{NAME}.d/system/* +%attr(0644,root,root) %{_exec_prefix}/etc/%{NAME}/topgrade.toml %attr(0644,root,root) %{_exec_prefix}/etc/polkit-1/rules.d/%{NAME}.rules %changelog