From ede688a8b2b34aa13f903f5ebd1a58dad71485fb Mon Sep 17 00:00:00 2001 From: bobslept <38557801+bobslept@users.noreply.github.com> Date: Sat, 14 Oct 2023 00:40:44 +0200 Subject: [PATCH] fix: improve flatpak-manager to use less commands (#591) --- usr/bin/ublue-system-flatpak-manager | 26 +++++++------------------- usr/bin/ublue-user-flatpak-manager | 18 +++++------------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/usr/bin/ublue-system-flatpak-manager b/usr/bin/ublue-system-flatpak-manager index 64208fa4162..d50a82167a9 100755 --- a/usr/bin/ublue-system-flatpak-manager +++ b/usr/bin/ublue-system-flatpak-manager @@ -23,23 +23,15 @@ REMOVE_LIST=$(cat /etc/flatpak/system/remove) # Install flatpaks in list if [[ -n $INSTALL_LIST ]]; then - for flatpak in $INSTALL_LIST; do - if grep -qvz $flatpak <<< $FLATPAK_LIST; then - if ! flatpak install --system --noninteractive flathub $flatpak; then - # exit on error - exit 1 - fi - fi - done + if ! flatpak install --system --noninteractive flathub ${INSTALL_LIST[@]}; then + # exit on error + exit 1 + fi fi # Remove flatpaks in list if [[ -n $REMOVE_LIST ]]; then - for flatpak in $REMOVE_LIST; do - if grep -qz $flatpak <<< $FLATPAK_LIST; then - flatpak remove --system --noninteractive $flatpak - fi - done + flatpak remove --system --noninteractive ${REMOVE_LIST[@]} fi # Opt out of and remove Fedora's flatpak repo @@ -50,15 +42,11 @@ if grep -qz 'fedora' <<< $(flatpak remotes); then # Remove flatpak apps from origin fedora FEDORA_FLATPAKS=$(flatpak list --app --columns=application,origin | grep -w 'fedora' | awk '{print $1}') - for flatpak in $FEDORA_FLATPAKS; do - flatpak remove --system --noninteractive $flatpak - done + flatpak remove --system --noninteractive ${FEDORA_FLATPAKS[@]} # Remove flatpak runtimes from origin fedora FEDORA_FLATPAKS=$(flatpak list --runtime --columns=application,arch,branch,origin | grep -w 'fedora' | awk '{print $1"/"$2"/"$3}') - for flatpak in $FEDORA_FLATPAKS; do - flatpak remove --system --noninteractive $flatpak - done + flatpak remove --system --noninteractive ${FEDORA_FLATPAKS[@]} fi # Disable the system variant of the flathub repo diff --git a/usr/bin/ublue-user-flatpak-manager b/usr/bin/ublue-user-flatpak-manager index 21abfafa427..66b47f71733 100755 --- a/usr/bin/ublue-user-flatpak-manager +++ b/usr/bin/ublue-user-flatpak-manager @@ -21,23 +21,15 @@ REMOVE_LIST=$(cat /etc/flatpak/user/remove) # Install flatpaks in list if [[ -n $INSTALL_LIST ]]; then - for flatpak in $INSTALL_LIST; do - if grep -qvz $flatpak <<< $FLATPAK_LIST; then - if ! flatpak install --user --noninteractive flathub $flatpak; then - # exit on error - exit 1 - fi - fi - done + if ! flatpak install --user --noninteractive flathub ${INSTALL_LIST[@]}; then + # exit on error + exit 1 + fi fi # Remove flatpaks in list if [[ -n $REMOVE_LIST ]]; then - for flatpak in $REMOVE_LIST; do - if grep -qz $flatpak <<< $FLATPAK_LIST; then - flatpak remove --user --noninteractive $flatpak - fi - done + flatpak remove --user --noninteractive ${REMOVE_LIST[@]} fi notify-send "Flatpak installer" "Finished installing user flatpaks" --app-name="Flatpak installer" -u NORMAL