From 6cd7818bed5801a49ae3db29a7be7a25cd93637a Mon Sep 17 00:00:00 2001 From: kleidis <167202775+kleidis@users.noreply.github.com> Date: Thu, 19 Sep 2024 04:34:42 +0200 Subject: [PATCH] Initial support for flathub management (#341) * Add flatpak / flathub setup & uninstall script * systemUpdate: Improve flatpak updates * Update docs * Fix order on uninstall script * Remove uninstall script --- docs/userguide.md | 1 + tabs/applications-setup/setup-flatpak.sh | 91 ++++++++++++++++++++++++ tabs/applications-setup/tab_data.toml | 4 ++ tabs/system-setup/system-update.sh | 13 +++- 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 tabs/applications-setup/setup-flatpak.sh diff --git a/docs/userguide.md b/docs/userguide.md index 57af97e10..d17155689 100644 --- a/docs/userguide.md +++ b/docs/userguide.md @@ -21,6 +21,7 @@ ## Applications Setup +- **Flathub**: Installs / Uninstalls Flatpak and Flathub. - **Alacritty Setup**: Installs and configures Alacritty for you. - **DwmTitus Setup**: Sets up the Dwm window manager. - **Kitty Setup**: Installs and configures Kitty for you. diff --git a/tabs/applications-setup/setup-flatpak.sh b/tabs/applications-setup/setup-flatpak.sh new file mode 100644 index 000000000..749ddf1ba --- /dev/null +++ b/tabs/applications-setup/setup-flatpak.sh @@ -0,0 +1,91 @@ +#!/bin/sh -e + +. ../common-script.sh + +# Used to detect the desktop environment, Only used for the If statement in the setup_flatpak function. +# Perhaps this should be moved to common-script.sh later on? +detect_de() { + if [ -n "$XDG_CURRENT_DESKTOP" ]; then + case "$XDG_CURRENT_DESKTOP" in + *GNOME*) + DE="GNOME" + ;; + *KDE*) + DE="KDE" + ;; + esac + fi +} + +# Install Flatpak if not already installed. +setup_flatpak() { + if ! command_exists flatpak; then + printf "%b\n" "${YELLOW}Installing Flatpak...${RC}" + case "$PACKAGER" in + pacman) + $ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm flatpak + ;; + apt-get|nala) + $ESCALATION_TOOL "$PACKAGER" install -y flatpak + ;; + dnf) + $ESCALATION_TOOL "$PACKAGER" install -y flatpak # Fedora should have flatpak already installed, this is just a failsafe + ;; + zypper) + $ESCALATION_TOOL "$PACKAGER" install -y flatpak + ;; + yum) + $ESCALATION_TOOL "$PACKAGER" install -y flatpak + ;; + xbps-install) + $ESCALATION_TOOL "$PACKAGER" install -S flatpak + ;; + *) + printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}" + exit 1 + ;; + esac + printf "%b\n" "Adding Flathub remote..." + $ESCALATION_TOOL flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo + else + if command -v flatpak >/dev/null 2>&1; then + if ! flatpak remotes | grep -q "flathub"; then + printf "%b\n" "${YELLOW}Detected Flatpak package manager but Flathub remote is not added. Would you like to add it? (y/n)${RC}" + read add_remote + case "$add_remote" in + [Yy]*) + printf "%b\n" "Adding Flathub remote..." + $ESCALATION_TOOL flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo + ;; + esac + else + # Needed mostly for systems without a polkit agent running (Error: updating: Unable to connect to system bus) + printf "%b\n" "${GREEN}Flathub already setup. You can quit.${RC}" + fi + fi + fi + + if [ "$PACKAGER" = "apt-get" ] || [ "$PACKAGER" = "nala" ]; then + detect_de + # Only used for Ubuntu GNOME. Ubuntu GNOME doesnt allow flathub to be added as a remote to their store. + # So in case the user wants to use a GUI siftware manager they can setup it here + if [ "$DE" = "GNOME" ]; then + printf "%b\n" "${YELLOW}Detected GNOME desktop environment. Would you like to install GNOME Software plugin for Flatpak? (y/n)${RC}" + read install_gnome + if [ "$install_gnome" = "y" ] || [ "$install_gnome" = "Y" ]; then + $ESCALATION_TOOL "$PACKAGER" install -y gnome-software-plugin-flatpak + fi + # Useful for Debian KDE spin as well + elif [ "$DE" = "KDE" ]; then + printf "%b\n" "${YELLOW}Detected KDE desktop environment. Would you like to install KDE Plasma Discover backend for Flatpak? (y/n)${RC}" + read install_kde + if [ "$install_kde" = "y" ] || [ "$install_kde" = "Y" ]; then + $ESCALATION_TOOL "$PACKAGER" install -y plasma-discover-backend-flatpak + fi + fi + fi +} + +checkEnv +checkEscalationTool +setup_flatpak diff --git a/tabs/applications-setup/tab_data.toml b/tabs/applications-setup/tab_data.toml index 0a9be9fbf..fad13af50 100644 --- a/tabs/applications-setup/tab_data.toml +++ b/tabs/applications-setup/tab_data.toml @@ -1,5 +1,9 @@ name = "Applications Setup" +[[data]] +name = "Setup Flatpak / Flathub" +script = "setup-flatpak.sh" + [[data]] name = "Alacritty" description = "Alacritty is a modern terminal emulator that comes with sensible defaults, but allows for extensive configuration. By integrating with other applications, rather than reimplementing their functionality, it manages to provide a flexible set of features with high performance. The supported platforms currently consist of BSD, Linux, macOS and Windows.\nThis command installs and condifures alacritty terminal emulator." diff --git a/tabs/system-setup/system-update.sh b/tabs/system-setup/system-update.sh index d5dcf08aa..6bcaf99ae 100755 --- a/tabs/system-setup/system-update.sh +++ b/tabs/system-setup/system-update.sh @@ -93,7 +93,18 @@ updateSystem() { updateFlatpaks() { if command_exists flatpak; then - flatpak update -y + printf "%b\n" "${YELLOW}Updating installed Flathub apps...${RC}" + installed_apps=$(flatpak list --app --columns=application) + + if [ -z "$installed_apps" ]; then + printf "%b\n" "${RED}No Flathub apps are installed.${RC}" + return + fi + + for app in $installed_apps; do + printf "%b\n" "${YELLOW}Updating $app...${RC}" + flatpak update -y "$app" + done fi }