[neon/neon/settings/Neon/release] /: allow the user to cancel system updates for a brief moment

Harald Sitter null at kde.org
Mon Jun 14 14:48:47 BST 2021


Git commit dc428425ab63dd2710081e9d90fa6f8e2e98584d by Harald Sitter.
Committed on 14/06/2021 at 13:41.
Pushed by sitter into branch 'Neon/release'.

allow the user to cancel system updates for a brief moment

there is a new unit that runs before all the other offline update magic
and allows the user to cancel the update.
if the user opts to cancel we'll simply isolate into the regular
default.target. as nothing special has been done yet this should be
entirely side effect free. for all intents and purposes we've even in
the worst case simply started and stopped a bunch of units that we
didn't actually need.

if the user doesn't we'll go ahead with the update after 10 seconds.
discover ought to then suggest the update again on next login.

the timing maybe ought to be reduced to 5 even. the general expectation
would be that the update shouldn't be canceled.

A  +21   -0    lib/systemd/system/neon-offline-skip.service
A  +44   -0    usr/lib/neon_update/neon_offline_skip.sh

https://invent.kde.org/neon/neon/settings/commit/dc428425ab63dd2710081e9d90fa6f8e2e98584d

diff --git a/lib/systemd/system/neon-offline-skip.service b/lib/systemd/system/neon-offline-skip.service
new file mode 100644
index 0000000..5de895a
--- /dev/null
+++ b/lib/systemd/system/neon-offline-skip.service
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
+# SPDX-FileCopyrightText: 2021 Harald Sitter <sitter at kde.org>
+
+[Unit]
+Description=Skip System Update Question
+DefaultDependencies=no
+Requires=sysinit.target
+After=sysinit.target systemd-journald.socket plymouth-start.service
+Before=packagekit-offline-update.service system-update-pre.target shutdown.target system-update.target
+
+[Service]
+# oneshot is only considered started when we exit
+# this is important, our after units may not start while we wait for input
+Type=oneshot
+ExecStart=/usr/lib/neon_update/neon_offline_skip.sh
+TimeoutSec=30s
+
+[Install]
+# Technically the -pre is enough but get wanted by both for greatest reliability.
+WantedBy=system-update-pre.target
+WantedBy=system-update.target
diff --git a/usr/lib/neon_update/neon_offline_skip.sh b/usr/lib/neon_update/neon_offline_skip.sh
new file mode 100755
index 0000000..e330844
--- /dev/null
+++ b/usr/lib/neon_update/neon_offline_skip.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
+# SPDX-FileCopyrightText: 2021 Harald Sitter <sitter at kde.org>
+
+ret=0
+if plymouth --ping; then
+  TXT0="Preparing system update..."
+  TXT1="keys:press 'c' to cancel" # keys: is a special behavior hack we have in breeze-plymouth, putting it in a special label
+  plymouth display-message --text="$TXT0"
+  plymouth display-message --text="$TXT1"
+  timeout -s KILL 10s plymouth watch-keystroke --keys="cC"
+  ret=$?
+  plymouth hide-message --text="$TXT1"
+else
+  # prompting without plymouth is hella horrible, abuse systemd's password helper as stand-in for plymouth
+  out=$(systemd-ask-password --echo --timeout=10 "Enter 'c' and hit enter to cancel system update...")
+  ret=$?
+  if [ "$out" != "" ]; then
+    # we do not actually care greatly about the input so long as it is not empty. hitting enter isn't really
+    # indicative of anything. could mean go away, could mean hurry up. who's to say.
+    ret=0
+  fi
+fi
+
+if [ "$ret" != "0" ]; then
+  echo "Continuing with update"
+  exit 0
+fi
+
+echo "Update cancelled."
+
+# undo systemd-system-update-generator and isolate into the real default.target
+# NB: /system-update must be removed! It is the file systemd-system-update-generator triggers on,
+#   leaving it behind would mean the daemon-reload again runs the generator and sets
+#   system-update.target as default.target effectively looping back in on the current state of affairs.
+rm -fv /system-update
+rm -fv /run/systemd/generator.early/default.target
+systemctl daemon-reload
+# This needs removing or discover gets confused as it only looks at the PK marker, not
+# the systemd marker file (which is a symlink to the PK one, mind you).
+rm -fv /var/lib/PackageKit/offline-update-action
+
+echo "Isolating into default.target ($(systemctl get-default)) instead..."
+systemctl isolate --no-block default.target



More information about the Neon-commits mailing list