2024-09-19 03:34:42 +01:00
|
|
|
#!/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)
|
2024-09-19 19:05:36 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm flatpak
|
2024-09-19 03:34:42 +01:00
|
|
|
;;
|
|
|
|
apt-get|nala)
|
2024-09-19 19:05:36 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" install -y flatpak
|
2024-09-19 03:34:42 +01:00
|
|
|
;;
|
|
|
|
dnf)
|
2024-09-19 19:05:36 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" install -y flatpak # Fedora should have flatpak already installed, this is just a failsafe
|
2024-09-19 03:34:42 +01:00
|
|
|
;;
|
|
|
|
zypper)
|
2024-09-19 19:05:36 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" install -y flatpak
|
2024-09-19 03:34:42 +01:00
|
|
|
;;
|
|
|
|
yum)
|
2024-09-19 19:05:36 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" install -y flatpak
|
2024-09-19 03:34:42 +01:00
|
|
|
;;
|
|
|
|
xbps-install)
|
2024-09-19 19:05:36 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" install -S flatpak
|
2024-09-19 03:34:42 +01:00
|
|
|
;;
|
|
|
|
*)
|
2024-09-19 19:05:36 +01:00
|
|
|
printf "%b\n" "${RED}Unsupported package manager: "$PACKAGER"${RC}"
|
2024-09-19 03:34:42 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
printf "%b\n" "Adding Flathub remote..."
|
2024-09-19 19:05:36 +01:00
|
|
|
"$ESCALATION_TOOL" flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
|
2024-09-19 03:34:42 +01:00
|
|
|
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}"
|
2024-09-19 22:47:08 +01:00
|
|
|
read -r add_remote
|
2024-09-19 03:34:42 +01:00
|
|
|
case "$add_remote" in
|
|
|
|
[Yy]*)
|
|
|
|
printf "%b\n" "Adding Flathub remote..."
|
2024-09-19 19:05:36 +01:00
|
|
|
"$ESCALATION_TOOL" flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
|
2024-09-19 03:34:42 +01:00
|
|
|
;;
|
|
|
|
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}"
|
2024-09-19 22:47:08 +01:00
|
|
|
read -r install_gnome
|
2024-09-19 03:34:42 +01:00
|
|
|
if [ "$install_gnome" = "y" ] || [ "$install_gnome" = "Y" ]; then
|
2024-09-19 19:05:36 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" install -y gnome-software-plugin-flatpak
|
2024-09-19 03:34:42 +01:00
|
|
|
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}"
|
2024-09-19 22:47:08 +01:00
|
|
|
read -r install_kde
|
2024-09-19 03:34:42 +01:00
|
|
|
if [ "$install_kde" = "y" ] || [ "$install_kde" = "Y" ]; then
|
2024-09-19 19:05:36 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" install -y plasma-discover-backend-flatpak
|
2024-09-19 03:34:42 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkEnv
|
|
|
|
checkEscalationTool
|
|
|
|
setup_flatpak
|