Maintain a list of all Flatpak apps ever successfully preinstalled on the system, and use it to avoid reinstalling user-deleted apps.

This commit is contained in:
Philip Grant
2026-06-19 14:14:40 +01:00
parent a6672bee0d
commit 34456aea33
4 changed files with 60 additions and 7 deletions

View File

@@ -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

View File

@@ -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 <pg_kde_invent@runbox.com>
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 <<EOF > $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

View File

@@ -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 <pg_kde_invent@runbox.com>
[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

View File

@@ -0,0 +1 @@
/usr/lib/systemd/system/kde-linux-seed-preinstalled-flatpak-list.service