♻ (flatpak-sync) Put code in own method
The new method sync is at this point always called
This commit is contained in:
parent
c514a973b9
commit
0a66eb9fb6
1 changed files with 25 additions and 21 deletions
|
@ -9,13 +9,14 @@ set -euo pipefail
|
||||||
|
|
||||||
APPS_LIST_PATH="${APPS_LIST_PATH:=$HOME/.config/flatpak-sync/apps.list}"
|
APPS_LIST_PATH="${APPS_LIST_PATH:=$HOME/.config/flatpak-sync/apps.list}"
|
||||||
|
|
||||||
readarray -t requested_apps < <(cat "$APPS_LIST_PATH")
|
function sync() {
|
||||||
readarray -t installed_apps < <(flatpak list --app --columns app | tail -n +1)
|
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."
|
echo "Checking for apps to install."
|
||||||
for app in "${requested_apps[@]}"; do
|
for app in "${requested_apps[@]}"; do
|
||||||
if [[ -z "$app" ]] || [[ "$app" =~ ^#.* ]]; then
|
if [[ -z "$app" ]] || [[ "$app" =~ ^#.* ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
@ -24,12 +25,15 @@ for app in "${requested_apps[@]}"; do
|
||||||
echo "$app not installed. Installing it."
|
echo "$app not installed. Installing it."
|
||||||
flatpak install -y "$app"
|
flatpak install -y "$app"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Checking for apps to remove."
|
echo "Checking for apps to remove."
|
||||||
for app in "${installed_apps[@]}"; do
|
for app in "${installed_apps[@]}"; do
|
||||||
if [[ ! "${requested_apps_cleaned[*]}" =~ "${app}" ]]; then
|
if [[ ! "${requested_apps_cleaned[*]}" =~ "${app}" ]]; then
|
||||||
echo "$app no found in apps list. Removing it.";
|
echo "$app no found in apps list. Removing it.";
|
||||||
flatpak uninstall -y "$app"
|
flatpak uninstall -y "$app"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
sync
|
||||||
|
|
Loading…
Reference in a new issue