mirror of
https://github.com/KDE/kde-linux.git
synced 2026-07-31 09:16:51 -04:00
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:
@@ -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
|
||||
|
||||
31
mkosi.extra/usr/lib/seed-preinstalled-flatpak-list
Executable file
31
mkosi.extra/usr/lib/seed-preinstalled-flatpak-list
Executable 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
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
/usr/lib/systemd/system/kde-linux-seed-preinstalled-flatpak-list.service
|
||||
Reference in New Issue
Block a user