Compare commits

...

2 Commits

Author SHA1 Message Date
Marcel Kapfer 921aa2e033
🚨 (flatpak-sync) Ignore two irrelevant shellcheck warnings 2023-07-20 21:07:51 +02:00
Marcel Kapfer 0a66eb9fb6
♻ (flatpak-sync) Put code in own method
The new method sync is at this point always called
2023-07-20 21:06:42 +02:00
1 changed files with 27 additions and 21 deletions

View File

@ -9,27 +9,33 @@ set -euo pipefail
APPS_LIST_PATH="${APPS_LIST_PATH:=$HOME/.config/flatpak-sync/apps.list}"
readarray -t requested_apps < <(cat "$APPS_LIST_PATH")
readarray -t installed_apps < <(flatpak list --app --columns app | tail -n +1)
function sync() {
readarray -t requested_apps < <(cat "$APPS_LIST_PATH")
readarray -t installed_apps < <(flatpak list --app --columns app | tail -n +1)
declare -a requested_apps_cleaned=()
declare -a requested_apps_cleaned=()
echo "Checking for apps to install."
for app in "${requested_apps[@]}"; do
if [[ -z "$app" ]] || [[ "$app" =~ ^#.* ]]; then
continue
fi
requested_apps_cleaned+=("$app")
if [[ ! "${installed_apps[*]}" =~ "${app}" ]]; then
echo "$app not installed. Installing it."
flatpak install -y "$app"
fi
done
echo "Checking for apps to install."
for app in "${requested_apps[@]}"; do
if [[ -z "$app" ]] || [[ "$app" =~ ^#.* ]]; then
continue
fi
requested_apps_cleaned+=("$app")
# shellcheck disable=SC2076
if [[ ! "${installed_apps[*]}" =~ "${app}" ]]; then
echo "$app not installed. Installing it."
flatpak install -y "$app"
fi
done
echo "Checking for apps to remove."
for app in "${installed_apps[@]}"; do
if [[ ! "${requested_apps_cleaned[*]}" =~ "${app}" ]]; then
echo "$app no found in apps list. Removing it.";
flatpak uninstall -y "$app"
fi
done
echo "Checking for apps to remove."
for app in "${installed_apps[@]}"; do
# shellcheck disable=SC2076
if [[ ! "${requested_apps_cleaned[*]}" =~ "${app}" ]]; then
echo "$app no found in apps list. Removing it.";
flatpak uninstall -y "$app"
fi
done
}
sync