From 700b984e7500843042b4712e56ad5d8eb2b169ff Mon Sep 17 00:00:00 2001 From: Kyle Gospodnetich Date: Tue, 23 Jan 2024 11:00:24 -0800 Subject: [PATCH] feat: Add topgrade support --- .../{00-system-update.py => 00-system-rebase.py} | 10 +--------- .../system/01-flatpak-system-update.sh | 3 --- files/etc/ublue-update.d/system/01-topgrade.sh | 3 +++ .../system/02-flatpak-system-repair-cleanup.sh | 4 ---- .../ublue-update.d/user/00-flatpak-user-update.sh | 3 --- .../user/01-flatpak-user-repair-cleanup.sh | 5 ----- .../ublue-update.d/user/02-distrobox-user-update.sh | 6 ------ .../etc/ublue-update.d/user/03-fleek-user-update.sh | 5 ----- files/etc/ublue-update.d/user/04-brew-update.sh | 5 ----- files/usr/etc/ublue-update/topgrade-system.toml | 10 ++++++++++ files/usr/etc/ublue-update/topgrade-user.toml | 13 +++++++++++++ src/ublue_update/cli.py | 5 ++--- ublue-update.spec | 11 ++++++++--- 13 files changed, 37 insertions(+), 46 deletions(-) rename files/etc/ublue-update.d/system/{00-system-update.py => 00-system-rebase.py} (90%) delete mode 100755 files/etc/ublue-update.d/system/01-flatpak-system-update.sh create mode 100755 files/etc/ublue-update.d/system/01-topgrade.sh delete mode 100755 files/etc/ublue-update.d/system/02-flatpak-system-repair-cleanup.sh delete mode 100755 files/etc/ublue-update.d/user/00-flatpak-user-update.sh delete mode 100755 files/etc/ublue-update.d/user/01-flatpak-user-repair-cleanup.sh delete mode 100755 files/etc/ublue-update.d/user/02-distrobox-user-update.sh delete mode 100755 files/etc/ublue-update.d/user/03-fleek-user-update.sh delete mode 100644 files/etc/ublue-update.d/user/04-brew-update.sh create mode 100644 files/usr/etc/ublue-update/topgrade-system.toml create mode 100644 files/usr/etc/ublue-update/topgrade-user.toml diff --git a/files/etc/ublue-update.d/system/00-system-update.py b/files/etc/ublue-update.d/system/00-system-rebase.py similarity index 90% rename from files/etc/ublue-update.d/system/00-system-update.py rename to files/etc/ublue-update.d/system/00-system-rebase.py index eb3e399..412024c 100755 --- a/files/etc/ublue-update.d/system/00-system-update.py +++ b/files/etc/ublue-update.d/system/00-system-rebase.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/python3 from subprocess import run from json import loads, load @@ -106,11 +106,3 @@ def check_for_rebase(): 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/01-topgrade.sh b/files/etc/ublue-update.d/system/01-topgrade.sh new file mode 100755 index 0000000..5e25f68 --- /dev/null +++ b/files/etc/ublue-update.d/system/01-topgrade.sh @@ -0,0 +1,3 @@ +#!/usr/bin/bash + +/usr/bin/topgrade --config /etc/ublue-update/topgrade-system.toml 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-system.toml b/files/usr/etc/ublue-update/topgrade-system.toml new file mode 100644 index 0000000..9c74827 --- /dev/null +++ b/files/usr/etc/ublue-update/topgrade-system.toml @@ -0,0 +1,10 @@ +[misc] +only = ["system", "flatpak"] +ignore_failures = ["flatpak"] +skip_notify = true +assume_yes = true +no_retry = true +no_self_update = true + +[linux] +rpm_ostree = true diff --git a/files/usr/etc/ublue-update/topgrade-user.toml b/files/usr/etc/ublue-update/topgrade-user.toml new file mode 100644 index 0000000..a83ac17 --- /dev/null +++ b/files/usr/etc/ublue-update/topgrade-user.toml @@ -0,0 +1,13 @@ +[misc] +only = ["flatpak", "distrobox"] +ignore_failures = ["flatpak", "distrobox"] +skip_notify = true +assume_yes = true +no_retry = true +no_self_update = true + +[distrobox] +use_root = false + +[flatpak] +use_sudo = false diff --git a/src/ublue_update/cli.py b/src/ublue_update/cli.py index a8e501e..b03af9b 100644 --- a/src/ublue_update/cli.py +++ b/src/ublue_update/cli.py @@ -160,8 +160,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-user.toml", ], capture_output=True, ) @@ -181,7 +181,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..0ae4e2f 100644 --- a/ublue-update.spec +++ b/ublue-update.spec @@ -45,7 +45,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 @@ -56,6 +55,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 @@ -67,8 +73,7 @@ cp -rp files/etc files/usr %{buildroot} %attr(0644,root,root) %{_exec_prefix}/lib/systemd/system/%{NAME}.service %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(0644,root,root) %{_exec_prefix}/etc/%{NAME}/*.toml %attr(0755,root,root) %{_sysconfdir}/%{NAME}.d/system/* %attr(0644,root,root) %{_exec_prefix}/etc/polkit-1/rules.d/%{NAME}.rules