From 34456aea331b0875fc7299688e7b18d62581e4c8 Mon Sep 17 00:00:00 2001 From: Philip Grant Date: Fri, 19 Jun 2026 14:14:40 +0100 Subject: [PATCH] Maintain a list of all Flatpak apps ever successfully preinstalled on the system, and use it to avoid reinstalling user-deleted apps. --- mkosi.extra/usr/lib/install-new-flatpaks | 19 +++++++----- .../usr/lib/seed-preinstalled-flatpak-list | 31 +++++++++++++++++++ ...nux-seed-preinstalled-flatpak-list.service | 16 ++++++++++ ...nux-seed-preinstalled-flatpak-list.service | 1 + 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100755 mkosi.extra/usr/lib/seed-preinstalled-flatpak-list create mode 100644 mkosi.extra/usr/lib/systemd/system/kde-linux-seed-preinstalled-flatpak-list.service create mode 120000 mkosi.extra/usr/lib/systemd/system/multi-user.target.wants/kde-linux-seed-preinstalled-flatpak-list.service diff --git a/mkosi.extra/usr/lib/install-new-flatpaks b/mkosi.extra/usr/lib/install-new-flatpaks index e5de8ac..588717c 100755 --- a/mkosi.extra/usr/lib/install-new-flatpaks +++ b/mkosi.extra/usr/lib/install-new-flatpaks @@ -7,8 +7,9 @@ set -eu FACTORY_DIR="/usr/share/factory/var/lib/flatpak/app" REPO_CONFIG="/usr/share/factory/var/lib/flatpak/repo/config" DEFAULT_REMOTE="flathub" -INSTALLED_APPS=$(flatpak list --app --columns=application) -CHANGE_HISTORY=$(flatpak history --columns=change,application) +INSTALLED_APPS=$(tr '\n' ' ' <<< $(flatpak list --app --columns=application)) +EVER_PREINSTALLED_APPS_FILE="/var/lib/kde-linux/ever-preinstalled-flatpak-apps" +EVER_PREINSTALLED_APPS=$(tr '\n' ' ' < $EVER_PREINSTALLED_APPS_FILE) echo "Looking in $FACTORY_DIR for new pre-installed apps that need installing…" @@ -18,14 +19,15 @@ for APP in "$FACTORY_DIR"/*; do APP=$(basename "$APP") # Skip if it's already installed - if [[ "$INSTALLED_APPS" == *"$APP"* ]]; then + if [[ " $INSTALLED_APPS " == *" $APP "* ]]; then echo "Skipping $APP (already installed)" continue fi - # Skip if the user uninstalled it - if rg "$APP" <<<"$CHANGE_HISTORY" | tail -n 1 | rg uninstall >/dev/null; then - echo "Skipping $APP (previously uninstalled by user)" + # Skip it if it was ever preinstalled. (If so, then the user must have chosen + # to uninstall it, so we don't want to reinstall it.) + if [[ " $EVER_PREINSTALLED_APPS " == *" $APP "* ]]; then + echo "Skipping $APP (was preinstalled, but then uninstalled by user)" continue fi @@ -45,5 +47,8 @@ for APP in "$FACTORY_DIR"/*; do fi echo "Installing $APP from $REMOTE…" - flatpak install --system --noninteractive --assumeyes --sideload-repo=/usr/share/factory/var/lib/flatpak/repo "$REMOTE" "$APP" + # If the app is successfully installed, record that we preinstalled it, + # so that we know not to reverse a future uninstall by the user. + flatpak install --system --noninteractive --assumeyes --sideload-repo=/usr/share/factory/var/lib/flatpak/repo "$REMOTE" "$APP" && + echo $APP >> $EVER_PREINSTALLED_APPS_FILE done diff --git a/mkosi.extra/usr/lib/seed-preinstalled-flatpak-list b/mkosi.extra/usr/lib/seed-preinstalled-flatpak-list new file mode 100755 index 0000000..8dbf495 --- /dev/null +++ b/mkosi.extra/usr/lib/seed-preinstalled-flatpak-list @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +# SPDX-FileCopyrightText: 2026 Philip Grant + +set -eu + +EVER_PREINSTALLED_APPS_FILE="/var/lib/kde-linux/ever-preinstalled-flatpak-apps" + +if [[ -f /etc/plasma-setup-done ]]; then + # This is an "old" system that was installed without the "ever-preinstalled-flatpak-apps" + # file being created at first boot, We create it with a hardcoded list of the apps + # that were preinstalled before Nov 2025. (We exclude qrca and keepsecret, which + # should have been preinstalled before the "ever-preinstalled-flatpak-apps" file + # was created, but on many systems weren't, because the "kde-linux-install-new-flatpak-apps" + # service wasn't enabled.) + echo "Pre-existing KDE Linux install: using preinstalled app list as of Nov 2025" + cat < $EVER_PREINSTALLED_APPS_FILE +org.kde.gwenview +org.kde.okular +org.kde.kwrite +org.kde.haruna +org.kde.ark +org.kde.kcalc +org.mozilla.firefox +EOF +else + # This is a brand new system. The set of apps that have ever been preinstalled on the system + # is exactly those in /usr/share/factory/var/lib/flatpak/app + echo "New KDE Linux install: using preinstalled app list from factory directory" + ls /usr/share/factory/var/lib/flatpak/app > $EVER_PREINSTALLED_APPS_FILE +fi diff --git a/mkosi.extra/usr/lib/systemd/system/kde-linux-seed-preinstalled-flatpak-list.service b/mkosi.extra/usr/lib/systemd/system/kde-linux-seed-preinstalled-flatpak-list.service new file mode 100644 index 0000000..9dd7ad4 --- /dev/null +++ b/mkosi.extra/usr/lib/systemd/system/kde-linux-seed-preinstalled-flatpak-list.service @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +# SPDX-FileCopyrightText: 2026 Philip Grant + +[Unit] +Description=Write the initial list of ever preinstalled Flatpaks on older systems +ConditionPathExists=!/var/lib/kde-linux/ever-preinstalled-flatpak-apps +ConditionKernelCommandLine=!kde-linux.live=1 +DefaultDependencies=no +After=local-fs.target +Before=kde-linux-install-new-flatpak-apps.service plasma-setup.service +Conflicts=shutdown.target +Before=shutdown.target + +[Service] +Type=oneshot +ExecStart=/usr/lib/seed-preinstalled-flatpak-list diff --git a/mkosi.extra/usr/lib/systemd/system/multi-user.target.wants/kde-linux-seed-preinstalled-flatpak-list.service b/mkosi.extra/usr/lib/systemd/system/multi-user.target.wants/kde-linux-seed-preinstalled-flatpak-list.service new file mode 120000 index 0000000..f18f4dc --- /dev/null +++ b/mkosi.extra/usr/lib/systemd/system/multi-user.target.wants/kde-linux-seed-preinstalled-flatpak-list.service @@ -0,0 +1 @@ +/usr/lib/systemd/system/kde-linux-seed-preinstalled-flatpak-list.service \ No newline at end of file