particle-os-modules/files/usr/bin/user-flatpak-setup
fiftydinar bd92e7e5c5
feat(default-flatpaks): Add info about which flatpaks are installed (#85)
* feat(default-flatpaks): Add info about which flatpaks are installed & uninstalled in notification. Also implement notification enable/disable config support.

* feat(default-flatpaks): Add support for configuring notifications in recipe file

* fix(default-flatpaks): Formatting fixes

* fix(default-flatpaks): Fix "enabling" typo instead of "configuring" notifications

* chore(default-flatpaks): Remove unused yq command

* fix(default-flatpaks): There is no need for 2 double quotes
2023-12-21 20:34:33 +00:00

60 lines
2 KiB
Bash

#!/usr/bin/env bash
# Remove Fedora's flatpak repo, if it exists
if grep -qz 'fedora' <<< "$(flatpak remotes)"; then
flatpak remote-delete --user fedora --force
flatpak remote-delete --user fedora-testing --force
fi
REPO_INFO="/etc/flatpak/user/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 per-user Flatpak repository
if [[ ! $REPO_URL == "null" && ! $REPO_NAME == "null" ]]; then
flatpak remote-add --if-not-exists --user "$REPO_NAME" "$REPO_URL"
echo "Adding remote $REPO_NAME from $REPO_URL"
fi
# Change repository title to configured title, if not null
if [[ ! $REPO_TITLE == "null" ]]; then
flatpak remote-modify --user "$REPO_NAME" --title="$REPO_TITLE"
echo "Setting title $REPO_TITLE for remote $REPO_NAME"
fi
# Notifications config
NOTIFICATIONS=$(cat /etc/flatpak/notifications)
# Installed flatpaks
FLATPAK_LIST=$(flatpak list --columns=application)
# Flatpak list files
INSTALL_LIST_FILE="/etc/flatpak/user/install"
REMOVE_LIST_FILE="/etc/flatpak/user/remove"
# Install flatpaks in list
if [[ -f $INSTALL_LIST_FILE ]]; then
if [[ -n $FLATPAK_LIST ]]; then
INSTALL_LIST=$(echo "$FLATPAK_LIST" | grep -vf - "$INSTALL_LIST_FILE")
else
INSTALL_LIST=$(cat $INSTALL_LIST_FILE)
fi
if [[ -n $INSTALL_LIST ]]; then
flatpak install --user --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
if [[ $NOTIFICATIONS == "true" ]]; then
notify-send "Flatpak Installer" "Finished install of user flatpaks:\n$INSTALL_LIST" --app-name="Flatpak Installer" -u NORMAL
fi
fi
fi
# Remove flatpaks in list
if [[ -f $REMOVE_LIST_FILE ]]; then
REMOVE_LIST=$(echo "$FLATPAK_LIST" | grep -o -f - "$REMOVE_LIST_FILE")
if [[ -n $REMOVE_LIST ]]; then
flatpak uninstall --user --noninteractive ${REMOVE_LIST[@]}
if [[ $NOTIFICATIONS == "true" ]]; then
notify-send "Flatpak Installer" "Finished uninstall of user flatpaks:\n$REMOVE_LIST" --app-name="Flatpak Installer" -u NORMAL
fi
fi
fi