From e49d8f266df8a25b5ac3e168fbc2aa0313b772ab Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 11:50:15 -0600 Subject: [PATCH 01/14] Create 00-flatpak-user-update.sh --- files/usr/lib/ublue-update.d/user/00-flatpak-user-update.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 files/usr/lib/ublue-update.d/user/00-flatpak-user-update.sh diff --git a/files/usr/lib/ublue-update.d/user/00-flatpak-user-update.sh b/files/usr/lib/ublue-update.d/user/00-flatpak-user-update.sh new file mode 100644 index 0000000..76d3b79 --- /dev/null +++ b/files/usr/lib/ublue-update.d/user/00-flatpak-user-update.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +/usr/bin/flatpak --user update -y --noninteractive From 798790ed7a1be635e2efde9106a6e5e017ccb1a8 Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 11:55:28 -0600 Subject: [PATCH 02/14] Create 01-flatpak-user-repair-cleanup.sh --- .../ublue-update.d/user/01-flatpak-user-repair-cleanup.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 files/usr/lib/ublue-update.d/user/01-flatpak-user-repair-cleanup.sh diff --git a/files/usr/lib/ublue-update.d/user/01-flatpak-user-repair-cleanup.sh b/files/usr/lib/ublue-update.d/user/01-flatpak-user-repair-cleanup.sh new file mode 100644 index 0000000..8046e76 --- /dev/null +++ b/files/usr/lib/ublue-update.d/user/01-flatpak-user-repair-cleanup.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + + +/usr/bin/flatpak uninstall --user --unused -y --noninteractive +/usr/bin/flatpak repair --user From ff67101edc3cf348a6224d72ead0c1e07c501af4 Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 11:56:20 -0600 Subject: [PATCH 03/14] Create 02-distrobox-user-update.sh --- .../usr/lib/ublue-update.d/user/02-distrobox-user-update.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 files/usr/lib/ublue-update.d/user/02-distrobox-user-update.sh diff --git a/files/usr/lib/ublue-update.d/user/02-distrobox-user-update.sh b/files/usr/lib/ublue-update.d/user/02-distrobox-user-update.sh new file mode 100644 index 0000000..a45075b --- /dev/null +++ b/files/usr/lib/ublue-update.d/user/02-distrobox-user-update.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +if [ -x /usr/bin/distrobox ]; then + unset SUDO_USER # avoid distrobox sudo checks + /usr/bin/distrobox upgrade -a +fi From de843b54a0ff5289f022cfc5c30b8e2703bab1e7 Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 11:57:10 -0600 Subject: [PATCH 04/14] Create 03-fleek-user-update.sh --- files/usr/lib/ublue-update.d/user/03-fleek-user-update.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 files/usr/lib/ublue-update.d/user/03-fleek-user-update.sh diff --git a/files/usr/lib/ublue-update.d/user/03-fleek-user-update.sh b/files/usr/lib/ublue-update.d/user/03-fleek-user-update.sh new file mode 100644 index 0000000..c322993 --- /dev/null +++ b/files/usr/lib/ublue-update.d/user/03-fleek-user-update.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +if [ -x /var/usrlocal/bin/fleek ]; then + /var/usrlocal/bin/fleek update -a +fi From d6cabdd98e434774ef801996057248b559894dc6 Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 11:57:47 -0600 Subject: [PATCH 05/14] Create 04-brew-update.sh --- files/usr/lib/ublue-update.d/user/04-brew-update.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 files/usr/lib/ublue-update.d/user/04-brew-update.sh diff --git a/files/usr/lib/ublue-update.d/user/04-brew-update.sh b/files/usr/lib/ublue-update.d/user/04-brew-update.sh new file mode 100644 index 0000000..cb61d0f --- /dev/null +++ b/files/usr/lib/ublue-update.d/user/04-brew-update.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +if command -v /var/home/linuxbrew/.linuxbrew/bin/brew; then + /var/home/linuxbrew/.linuxbrew/bin/brew update --auto-update +fi From 2211a41222abf5fd6a03f35b13c7ef327792691f Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 11:58:45 -0600 Subject: [PATCH 06/14] Create 00-system-update.py --- .../ublue-update.d/system/00-system-update.py | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 files/usr/lib/ublue-update.d/system/00-system-update.py diff --git a/files/usr/lib/ublue-update.d/system/00-system-update.py b/files/usr/lib/ublue-update.d/system/00-system-update.py new file mode 100644 index 0000000..eb3e399 --- /dev/null +++ b/files/usr/lib/ublue-update.d/system/00-system-update.py @@ -0,0 +1,116 @@ +#!/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) From 833e2b5c68f2b2892f92c741fbf94cf5b07df5af Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 11:59:58 -0600 Subject: [PATCH 07/14] Create 01-flatpak-system-update.sh --- .../usr/lib/ublue-update.d/system/01-flatpak-system-update.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 files/usr/lib/ublue-update.d/system/01-flatpak-system-update.sh diff --git a/files/usr/lib/ublue-update.d/system/01-flatpak-system-update.sh b/files/usr/lib/ublue-update.d/system/01-flatpak-system-update.sh new file mode 100644 index 0000000..cba7208 --- /dev/null +++ b/files/usr/lib/ublue-update.d/system/01-flatpak-system-update.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +/usr/bin/flatpak --system update -y --noninteractive From 7c30c63e53822c301ec666519f1eb7b943169bde Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 12:00:34 -0600 Subject: [PATCH 08/14] Create 02-flatpak-system-repair-cleanup.sh --- .../ublue-update.d/system/02-flatpak-system-repair-cleanup.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 files/usr/lib/ublue-update.d/system/02-flatpak-system-repair-cleanup.sh diff --git a/files/usr/lib/ublue-update.d/system/02-flatpak-system-repair-cleanup.sh b/files/usr/lib/ublue-update.d/system/02-flatpak-system-repair-cleanup.sh new file mode 100644 index 0000000..b10acc8 --- /dev/null +++ b/files/usr/lib/ublue-update.d/system/02-flatpak-system-repair-cleanup.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +/usr/bin/flatpak uninstall --system --unused -y --noninteractive +/usr/bin/flatpak repair --system From 1ee019da2f3a890d3d4d491eba96b075825b46bf Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 12:11:29 -0600 Subject: [PATCH 09/14] Create 05-nix-update.sh --- files/usr/lib/ublue-update.d/user/05-nix-update.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 files/usr/lib/ublue-update.d/user/05-nix-update.sh diff --git a/files/usr/lib/ublue-update.d/user/05-nix-update.sh b/files/usr/lib/ublue-update.d/user/05-nix-update.sh new file mode 100644 index 0000000..b304345 --- /dev/null +++ b/files/usr/lib/ublue-update.d/user/05-nix-update.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +if [ -x /nix/var/nix/profiles/default/bin/nix ]; then + /nix/var/nix/profiles/default/bin/nix upgrade '.*' --profile ~/.nix-profile +fi From 2b2d691e3c31b850e9ba7e02218c179fc3619fdc Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 12:11:45 -0600 Subject: [PATCH 10/14] Rename 05-nix-update.sh to 05-nix-user-update.sh --- .../user/{05-nix-update.sh => 05-nix-user-update.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename files/usr/lib/ublue-update.d/user/{05-nix-update.sh => 05-nix-user-update.sh} (100%) diff --git a/files/usr/lib/ublue-update.d/user/05-nix-update.sh b/files/usr/lib/ublue-update.d/user/05-nix-user-update.sh similarity index 100% rename from files/usr/lib/ublue-update.d/user/05-nix-update.sh rename to files/usr/lib/ublue-update.d/user/05-nix-user-update.sh From f70502ae859535831b8c8c11ab68ab87f16ed4f8 Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 12:12:54 -0600 Subject: [PATCH 11/14] Create 03-nix-system-update.sh --- files/usr/lib/ublue-update.d/system/03-nix-system-update.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 files/usr/lib/ublue-update.d/system/03-nix-system-update.sh diff --git a/files/usr/lib/ublue-update.d/system/03-nix-system-update.sh b/files/usr/lib/ublue-update.d/system/03-nix-system-update.sh new file mode 100644 index 0000000..abab689 --- /dev/null +++ b/files/usr/lib/ublue-update.d/system/03-nix-system-update.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +if [ -x /nix/var/nix/profiles/default/bin/nix ]; then + /nix/var/nix/profiles/default/bin/nix upgrade '.*' --profile ~/nix/var/nix/profiles/default +fi From a8702c75f98792c9288cded5b0b10bdec35ea8d2 Mon Sep 17 00:00:00 2001 From: dnkmmr <104856296+dnkmmr69420@users.noreply.github.com> Date: Sun, 24 Dec 2023 12:14:01 -0600 Subject: [PATCH 12/14] Delete files/etc/ublue-update.d directory --- .../ublue-update.d/system/00-system-update.py | 116 ------------------ .../system/01-flatpak-system-update.sh | 3 - .../02-flatpak-system-repair-cleanup.sh | 4 - .../user/00-flatpak-user-update.sh | 3 - .../user/01-flatpak-user-repair-cleanup.sh | 5 - .../user/02-distrobox-user-update.sh | 6 - .../user/03-fleek-user-update.sh | 5 - .../etc/ublue-update.d/user/04-brew-update.sh | 5 - 8 files changed, 147 deletions(-) delete mode 100755 files/etc/ublue-update.d/system/00-system-update.py delete mode 100755 files/etc/ublue-update.d/system/01-flatpak-system-update.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 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 From 0205f2a2360eea9e0b10440b2d79b13989d8f767 Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Mon, 15 Jan 2024 21:44:54 -0800 Subject: [PATCH 13/14] feat: add override update functionality to cli.py --- src/ublue_update/cli.py | 61 ++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/src/ublue_update/cli.py b/src/ublue_update/cli.py index a8e501e..b0bc720 100644 --- a/src/ublue_update/cli.py +++ b/src/ublue_update/cli.py @@ -85,29 +85,45 @@ def hardware_inhibitor_checks_failed( exception_log = "\n - ".join(failures) raise Exception(f"update failed to pass checks: \n - {exception_log}") +def run_update_script(script_path: str): + executable = os.access(script_path, os.X_OK) + if executable: + log.info(f"Running update script: {script_path}") + out = subprocess.run( + [script_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: {script_path}, check logs for more info", + ) + else: + log.info(f"could not execute file {script_path}") + +def run_update_scripts(root_dir: str, override_dir: str): + # get a list of all the files in the override dir + override_files = [] + for root, dirs, files in os.walk(override_dir): + for file in files: + override_files.append(file) -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", - ) + # check if a script overrides the update script in the root dir + if file in override_files: + run_update_script(override_dir + str(file)) + # remove from the list to prevent running scripts again + override_files.remove(file) else: - log.info(f"could not execute file {full_path}") + run_update_script(root_dir + str(file)) + # run the remaining scripts in the override dir + for file in override_files: + run_update_script(override_dir + str(file)) def run_updates(system, system_update_available): @@ -120,7 +136,8 @@ def run_updates(system, system_update_available): fd = acquire_lock(filelock_path) if fd is None: raise Exception("updates are already running for this user") - root_dir = "/etc/ublue-update.d" + root_dir = "/usr/lib/ublue-update.d" + override_dir = "/etc/ublue-update.d" """Wait on any existing transactions to complete before updating""" transaction_wait() @@ -139,7 +156,7 @@ def run_updates(system, system_update_available): if system: users = [] - run_update_scripts(f"{root_dir}/system/") + run_update_scripts(f"{root_dir}/system/", f"{override_dir}/system/") for user in users: try: xdg_runtime_dir = get_xdg_runtime_dir(user["User"]) @@ -181,7 +198,7 @@ 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/") + run_update_scripts(f"{root_dir}/user/", f"{override_dir}/user/") release_lock(fd) os._exit(0) From c4f36e6f98bee3332c233dd150abf516d8dbffd5 Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Mon, 15 Jan 2024 21:53:29 -0800 Subject: [PATCH 14/14] fix: format --- src/ublue_update/cli.py | 3 ++- src/ublue_update/update_inhibitors/hardware.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ublue_update/cli.py b/src/ublue_update/cli.py index b0bc720..eac3367 100644 --- a/src/ublue_update/cli.py +++ b/src/ublue_update/cli.py @@ -85,6 +85,7 @@ def hardware_inhibitor_checks_failed( exception_log = "\n - ".join(failures) raise Exception(f"update failed to pass checks: \n - {exception_log}") + def run_update_script(script_path: str): executable = os.access(script_path, os.X_OK) if executable: @@ -105,6 +106,7 @@ def run_update_script(script_path: str): else: log.info(f"could not execute file {script_path}") + def run_update_scripts(root_dir: str, override_dir: str): # get a list of all the files in the override dir override_files = [] @@ -214,7 +216,6 @@ def run_updates(system, system_update_available): def main(): - # setup argparse parser = argparse.ArgumentParser() parser.add_argument( diff --git a/src/ublue_update/update_inhibitors/hardware.py b/src/ublue_update/update_inhibitors/hardware.py index 5774953..0759a6a 100644 --- a/src/ublue_update/update_inhibitors/hardware.py +++ b/src/ublue_update/update_inhibitors/hardware.py @@ -29,7 +29,8 @@ def check_battery_status() -> dict: battery_pass: bool = True if battery_status is not None: battery_pass = ( - battery_status.percent >= min_battery_percent or battery_status.power_plugged + battery_status.percent >= min_battery_percent + or battery_status.power_plugged ) return { "passed": battery_pass, @@ -56,7 +57,6 @@ def check_mem_percentage() -> dict: def check_hardware_inhibitors() -> bool: - hardware_inhibitors = [ check_network_status(), check_battery_status(),