(flatpak-sync) Add script for declaring flatpak apps

This commit is contained in:
Marcel Kapfer 2023-07-18 23:35:27 +02:00
parent 20b17be7b3
commit d1305cf574
Signed by: mmk2410
GPG Key ID: CADE6F0C09F21B09
3 changed files with 64 additions and 0 deletions

24
flatpak-sync/README.org Normal file
View File

@ -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

10
flatpak-sync/example.list Normal file
View File

@ -0,0 +1,10 @@
# Productivity
org.mozilla.Thunderbird
org.libreoffice.LibreOffice
# Graphics
org.gimp.GIMP
org.inkscape.Inkscape
# Utilities
# com.github.tchx84.Flatseal

30
flatpak-sync/flatpak-sync.sh Executable file
View File

@ -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