Last active
November 21, 2022 08:58
-
-
Save jurca/81fe57f341f8a814c7efc3f373efd526 to your computer and use it in GitHub Desktop.
Utility for updating flatpak apps on Ubuntu. GUI included.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Add this script to your "Startup apps" to run it every time you sign into your OS. | |
updates_available=$(flatpak update | grep --perl-regexp '^\s*\d+\.\s+' | wc -l) | |
if [ "$updates_available" = 0 ] | |
then | |
# This may be caused by a missing dependecy of a new version of an app to | |
# update, so we need to explicitly check for that. | |
</dev/null flatpak update >/dev/null 2>/dev/null | |
if [ "$?" != 0 ] | |
then | |
update_message=$(</dev/null flatpak update 2>/dev/null) | |
zenity \ | |
--question \ | |
--window-icon=question \ | |
--title="Flatpak updates available" \ | |
--width=480 \ | |
--text="$update_message" | |
if [ "$?" != 0 ] | |
then | |
exit | |
fi | |
# Unfortunately, we cannot determine the number of updates in this case | |
updates_available=1 | |
else | |
echo "There are no updates available" | |
exit | |
fi | |
else | |
if [ "$updates_available" = 1 ] | |
then | |
update_text="There is 1 flatpak update available. Install it now?" | |
else | |
update_text="There are $updates_available flatpak updates available. Install them now?" | |
fi | |
zenity \ | |
--question \ | |
--window-icon=question \ | |
--title="Flatpak updates available" \ | |
--width=480 \ | |
--text="$update_text" | |
if [ "$?" != 0 ] | |
then | |
exit | |
fi | |
fi | |
# Flatpak outputs a line on start of an update, so we need to count from -1 and | |
# add a "done" line at the end. | |
installed_updates=-1 | |
( flatpak update --noninteractive && echo "All done" ) | ( | |
while read -r line | |
do | |
installed_updates=$(echo "$installed_updates + 1" | bc) | |
echo "$installed_updates * 100 / $updates_available" | bc | |
done | |
) | zenity --progress --window-icon=info --text="Installing updates..." --no-cancel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment