Install newly-installed Flatpak apps if needed

Install newly-installed Flatpak apps if needed

- If we're the first boot, don't check
- If we already checked on the last boot and the OS image didn't change,
  don't check
- Otherwise check

"check" means look for flatpak apps in factory that aren't currently
installed and that haven't been manually uninstalled by the user. If we
find any, install them from the factory repo.

Resolves #434
This commit is contained in:
Nate Graham
2026-04-23 18:44:05 -06:00
parent 804434ed37
commit 95ee2c4930
3 changed files with 82 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2026 Nate Graham <nate@kde.org>
set -eu
. /usr/lib/os-release # gets us IMAGE_VERSION
VERSION_FILE="/var/lib/kde-linux/os-version-last-checked-for-new-preinstalled-apps"
if [ ! -f "$VERSION_FILE" ]; then
echo "$VERSION_FILE does not exist; creating it and doing nothing else."
echo "$IMAGE_VERSION" > "$VERSION_FILE"
exit 0
fi
PREVIOUSLY_CHECKED_OS_VERSION=$(cat "$VERSION_FILE")
echo "Previously checked OS version: $PREVIOUSLY_CHECKED_OS_VERSION"
echo "Currently booted OS version: $IMAGE_VERSION"
if [[ "$PREVIOUSLY_CHECKED_OS_VERSION" == "$IMAGE_VERSION" ]]; then
echo "Already checked for new apps on OS version $IMAGE_VERSION; not doing it again."
exit 0
fi
FACTORY_DIR="/usr/share/factory/var/lib/flatpak/app"
echo "Have not yet checked OS version $IMAGE_VERSION for new pre-installed apps. Looking in $FACTORY_DIR…"
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)
for APP in "$FACTORY_DIR"/*; do
# trim trailing slash
APP=$(basename "$APP")
# Skip if it's already installed
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)"
continue
fi
REMOTE="$DEFAULT_REMOTE"
# See if we have a special repo to install it from
NON_RDNS_NAME="${APP#*.*.}"
SPECIAL_APP_REMOTE=$(rg "$NON_RDNS_NAME" "$REPO_CONFIG" | head -n 1 | cut -d '"' -f 2 || true)
if [[ -n "$SPECIAL_APP_REMOTE" ]]; then
echo "$APP needs to be installed from a special repo: $SPECIAL_APP_REMOTE"
REMOTE="$SPECIAL_APP_REMOTE"
fi
echo "Installing $APP from $REMOTE…"
flatpak install --system --noninteractive --assumeyes --sideload-repo=/usr/share/factory/var/lib/flatpak/repo "$REMOTE" "$APP"
done
echo "$IMAGE_VERSION" > "$VERSION_FILE"
echo "Recording that we checked for new apps on OS version $IMAGE_VERSION."

View File

@@ -44,6 +44,7 @@ enable switcheroo-control.service
enable kde-linux-bootloader-visibility.service
enable kde-linux-btrfs.service
enable kde-linux-configure-firefox.path
enable kde-linux-install-new-flatpak-apps.service
enable kde-linux-iw-set-regdomain.path
enable kde-linux-live-setup.service
enable kde-linux-openqa-setup.service

View File

@@ -0,0 +1,12 @@
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2026 Nate Graham <nate@kde.org>
[Unit]
Description=Install any new Flatpak apps added to booted OS version
[Service]
Type=oneshot
ExecStart=/usr/lib/install-new-flatpaks
[Install]
WantedBy=multi-user.target