Skip to content

Commit

Permalink
feat: Add topgrade support
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleGospo committed Jan 23, 2024
1 parent 593382b commit 8ebf6ab
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 180 deletions.
116 changes: 0 additions & 116 deletions files/etc/ublue-update.d/system/00-system-update.py

This file was deleted.

3 changes: 0 additions & 3 deletions files/etc/ublue-update.d/system/01-flatpak-system-update.sh

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions files/etc/ublue-update.d/user/00-flatpak-user-update.sh

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions files/etc/ublue-update.d/user/02-distrobox-user-update.sh

This file was deleted.

5 changes: 0 additions & 5 deletions files/etc/ublue-update.d/user/03-fleek-user-update.sh

This file was deleted.

5 changes: 0 additions & 5 deletions files/etc/ublue-update.d/user/04-brew-update.sh

This file was deleted.

10 changes: 10 additions & 0 deletions files/usr/etc/ublue-update/topgrade.toml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 2 additions & 28 deletions src/ublue_update/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"])
Expand All @@ -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,
)
Expand All @@ -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)

Expand Down
13 changes: 8 additions & 5 deletions ublue-update.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 8ebf6ab

Please sign in to comment.