particle-os-modules/files/usr/bin/system-flatpak-setup

67 lines
No EOL
1.9 KiB
Bash
Executable file

#!/usr/bin/env bash
# Script Version
VER=1
VER_FILE="/etc/ublue-os/system-flatpak-configured"
VER_RAN=$(cat $VER_FILE)
# Run script if updated
if [[ -f $VER_FILE && $VER = $VER_RAN ]]; then
echo "Flatpak setup v$VER has already ran. Exiting..."
exit 0
fi
# Opt out of and remove Fedora's flatpak repo
if grep -qz 'fedora' <<< $(flatpak remotes); then
/usr/lib/fedora-third-party/fedora-third-party-opt-out
/usr/bin/fedora-third-party disable
flatpak remote-delete fedora --force
fi
REPO_INFO="/etc/flatpak/system/repo-info.yml"
REPO_URL=$(yq '.repo-url' $REPO_INFO)
REPO_NAME=$(yq '.repo-name' $REPO_INFO)
REPO_TITLE=$(yq '.repo-title' $REPO_INFO)
# Set up system-wide Flatpak repository
flatpak remote-add --if-not-exists --system $REPO_NAME $REPO_URL
# If configured remote is flathub, enable it here.
# Flathub is already installed on Fedora, but not enabled by default,
# so the above command won't add it again
if [[ $REPO_NAME == "flathub" ]]; then
flatpak remote-modify --system $REPO_NAME --enable
fi
# Change repository title to configured title, if not null
if [[ ! $REPO_TITLE == "null" ]]; then
flatpak remote-modify --system $REPO_NAME --title="$REPO_TITLE"
fi
# Lists of flatpaks
FLATPAK_LIST=$(flatpak list --columns=application)
INSTALL_LIST=$(cat /etc/flatpak/system/install)
REMOVE_LIST=$(cat /etc/flatpak/system/remove)
# Install flatpaks in list
if [[ -n $INSTALL_LIST ]]; then
for flatpak in $INSTALL_LIST; do
if grep -qvz $flatpak <<< $FLATPAK_LIST; then
flatpak install --system --noninteractive $REPO_NAME $flatpak
fi
done
fi
# Remove flatpaks in list
if [[ -n $REMOVE_LIST ]]; then
for flatpak in $REMOVE_LIST; do
if grep -qz $flatpak <<< $FLATPAK_LIST; then
flatpak remove --system --noninteractive $flatpak
fi
done
fi
# Prevent future executions
echo "Writing state file"
mkdir -p /etc/ublue-os
echo $VER > $VER_FILE