|
| 1 | +#!/bin/sh -e |
| 2 | + |
| 3 | +. ../common-script.sh |
| 4 | + |
| 5 | +# Used to detect the desktop environment, Only used for the If statement in the setup_flatpak function. |
| 6 | +# Perhaps this should be moved to common-script.sh later on? |
| 7 | +detect_de() { |
| 8 | + if [ -n "$XDG_CURRENT_DESKTOP" ]; then |
| 9 | + case "$XDG_CURRENT_DESKTOP" in |
| 10 | + *GNOME*) |
| 11 | + DE="GNOME" |
| 12 | + ;; |
| 13 | + *KDE*) |
| 14 | + DE="KDE" |
| 15 | + ;; |
| 16 | + esac |
| 17 | + fi |
| 18 | +} |
| 19 | + |
| 20 | +# Install Flatpak if not already installed. |
| 21 | +setup_flatpak() { |
| 22 | + if ! command_exists flatpak; then |
| 23 | + printf "%b\n" "${YELLOW}Installing Flatpak...${RC}" |
| 24 | + case "$PACKAGER" in |
| 25 | + pacman) |
| 26 | + $ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm flatpak |
| 27 | + ;; |
| 28 | + apt-get|nala) |
| 29 | + $ESCALATION_TOOL "$PACKAGER" install -y flatpak |
| 30 | + ;; |
| 31 | + dnf) |
| 32 | + $ESCALATION_TOOL "$PACKAGER" install -y flatpak # Fedora should have flatpak already installed, this is just a failsafe |
| 33 | + ;; |
| 34 | + zypper) |
| 35 | + $ESCALATION_TOOL "$PACKAGER" install -y flatpak |
| 36 | + ;; |
| 37 | + yum) |
| 38 | + $ESCALATION_TOOL "$PACKAGER" install -y flatpak |
| 39 | + ;; |
| 40 | + xbps-install) |
| 41 | + $ESCALATION_TOOL "$PACKAGER" install -S flatpak |
| 42 | + ;; |
| 43 | + *) |
| 44 | + printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}" |
| 45 | + exit 1 |
| 46 | + ;; |
| 47 | + esac |
| 48 | + printf "%b\n" "Adding Flathub remote..." |
| 49 | + $ESCALATION_TOOL flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo |
| 50 | + else |
| 51 | + if command -v flatpak >/dev/null 2>&1; then |
| 52 | + if ! flatpak remotes | grep -q "flathub"; then |
| 53 | + printf "%b\n" "${YELLOW}Detected Flatpak package manager but Flathub remote is not added. Would you like to add it? (y/n)${RC}" |
| 54 | + read add_remote |
| 55 | + case "$add_remote" in |
| 56 | + [Yy]*) |
| 57 | + printf "%b\n" "Adding Flathub remote..." |
| 58 | + $ESCALATION_TOOL flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo |
| 59 | + ;; |
| 60 | + esac |
| 61 | + else |
| 62 | + # Needed mostly for systems without a polkit agent running (Error: updating: Unable to connect to system bus) |
| 63 | + printf "%b\n" "${GREEN}Flathub already setup. You can quit.${RC}" |
| 64 | + fi |
| 65 | + fi |
| 66 | + fi |
| 67 | + |
| 68 | + if [ "$PACKAGER" = "apt-get" ] || [ "$PACKAGER" = "nala" ]; then |
| 69 | + detect_de |
| 70 | + # Only used for Ubuntu GNOME. Ubuntu GNOME doesnt allow flathub to be added as a remote to their store. |
| 71 | + # So in case the user wants to use a GUI siftware manager they can setup it here |
| 72 | + if [ "$DE" = "GNOME" ]; then |
| 73 | + printf "%b\n" "${YELLOW}Detected GNOME desktop environment. Would you like to install GNOME Software plugin for Flatpak? (y/n)${RC}" |
| 74 | + read install_gnome |
| 75 | + if [ "$install_gnome" = "y" ] || [ "$install_gnome" = "Y" ]; then |
| 76 | + $ESCALATION_TOOL "$PACKAGER" install -y gnome-software-plugin-flatpak |
| 77 | + fi |
| 78 | + # Useful for Debian KDE spin as well |
| 79 | + elif [ "$DE" = "KDE" ]; then |
| 80 | + printf "%b\n" "${YELLOW}Detected KDE desktop environment. Would you like to install KDE Plasma Discover backend for Flatpak? (y/n)${RC}" |
| 81 | + read install_kde |
| 82 | + if [ "$install_kde" = "y" ] || [ "$install_kde" = "Y" ]; then |
| 83 | + $ESCALATION_TOOL "$PACKAGER" install -y plasma-discover-backend-flatpak |
| 84 | + fi |
| 85 | + fi |
| 86 | + fi |
| 87 | +} |
| 88 | + |
| 89 | +checkEnv |
| 90 | +checkEscalationTool |
| 91 | +setup_flatpak |
0 commit comments