diff --git a/flatpak-sync/README.org b/flatpak-sync/README.org new file mode 100644 index 0000000..689a84a --- /dev/null +++ b/flatpak-sync/README.org @@ -0,0 +1,24 @@ +#+title: flatpak-sync + +=flatpak-sync.sh= is a rudimentary Bash(!) script for keeping the installed flatpak apps (only apps, not runtimes) in sync with what is declared in a simple file. + +* Usage + +1. Download the =flatpak-sync.sh= script and make it executable (~chmod +x flatpak-sync.sh~) +2. Create an app list file at =~/.config/flatpak-sync/apps.list= following the format in the next section. +3. Run the script with ~./flatpak-sync.sh~ (given it is in your current working directory) + +* App List Format + +The =apps.list= is a list of application IDs (e.g. =org.kde.kdenlive=), each on their own line. Empty lines and lines starting with a hash sign (~#~) are ignored. + +You may have a look at the =example.list= for a quick overview of what is achievable. + +* Advanced usage + +It is possible to use a different app list file by setting the =APP_LIST_PATH= environment variable, e.g. if your app list it at =~/dotfiles/flatpaks.list= then you might call the script with ~APPS_LIST_PATH=$HOME/dotfiles/flatpaks.list ./flatpak-sync.sh~ (again assuming the script is in the current working directory). + +* Next possible steps + +- Add a script for automatically syncing the file with a Git repository and executing it after a sync +- Add a SystemD service/timer for the automatic syncing script diff --git a/flatpak-sync/example.list b/flatpak-sync/example.list new file mode 100644 index 0000000..1ee8868 --- /dev/null +++ b/flatpak-sync/example.list @@ -0,0 +1,10 @@ +# Productivity +org.mozilla.Thunderbird +org.libreoffice.LibreOffice + +# Graphics +org.gimp.GIMP +org.inkscape.Inkscape + +# Utilities +# com.github.tchx84.Flatseal diff --git a/flatpak-sync/flatpak-sync.sh b/flatpak-sync/flatpak-sync.sh new file mode 100755 index 0000000..3787028 --- /dev/null +++ b/flatpak-sync/flatpak-sync.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +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) + +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 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