2023-07-18 23:35:27 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-07-20 21:01:00 +02:00
|
|
|
#
|
|
|
|
# flatpak-sync is an easy approach for declaring the installed flatpak apps.
|
|
|
|
#
|
|
|
|
# 2023 (c) Marcel Kapfer <opensource@mmk2410.org>
|
|
|
|
# Licensed under the MIT License
|
2023-07-18 23:35:27 +02:00
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
APPS_LIST_PATH="${APPS_LIST_PATH:=$HOME/.config/flatpak-sync/apps.list}"
|
|
|
|
|
2023-07-20 21:06:42 +02:00
|
|
|
function sync() {
|
|
|
|
readarray -t requested_apps < <(cat "$APPS_LIST_PATH")
|
|
|
|
readarray -t installed_apps < <(flatpak list --app --columns app | tail -n +1)
|
2023-07-18 23:35:27 +02:00
|
|
|
|
2023-07-20 21:06:42 +02:00
|
|
|
declare -a requested_apps_cleaned=()
|
2023-07-18 23:35:27 +02:00
|
|
|
|
2023-07-20 21:06:42 +02:00
|
|
|
echo "Checking for apps to install."
|
|
|
|
for app in "${requested_apps[@]}"; do
|
|
|
|
if [[ -z "$app" ]] || [[ "$app" =~ ^#.* ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
requested_apps_cleaned+=("$app")
|
2023-07-20 21:07:51 +02:00
|
|
|
# shellcheck disable=SC2076
|
2023-07-20 21:06:42 +02:00
|
|
|
if [[ ! "${installed_apps[*]}" =~ "${app}" ]]; then
|
|
|
|
echo "$app not installed. Installing it."
|
|
|
|
flatpak install -y "$app"
|
|
|
|
fi
|
|
|
|
done
|
2023-07-18 23:35:27 +02:00
|
|
|
|
2023-07-20 21:06:42 +02:00
|
|
|
echo "Checking for apps to remove."
|
|
|
|
for app in "${installed_apps[@]}"; do
|
2023-07-20 21:07:51 +02:00
|
|
|
# shellcheck disable=SC2076
|
2023-07-20 21:06:42 +02:00
|
|
|
if [[ ! "${requested_apps_cleaned[*]}" =~ "${app}" ]]; then
|
|
|
|
echo "$app no found in apps list. Removing it.";
|
|
|
|
flatpak uninstall -y "$app"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
sync
|