Skip to content

Commit 6cd7818

Browse files
author
kleidis
authored
Initial support for flathub management (ChrisTitusTech#341)
* Add flatpak / flathub setup & uninstall script * systemUpdate: Improve flatpak updates * Update docs * Fix order on uninstall script * Remove uninstall script
1 parent 23156bc commit 6cd7818

File tree

4 files changed

+108
-1
lines changed

4 files changed

+108
-1
lines changed

docs/userguide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
## Applications Setup
2323

24+
- **Flathub**: Installs / Uninstalls Flatpak and Flathub.
2425
- **Alacritty Setup**: Installs and configures Alacritty for you.
2526
- **DwmTitus Setup**: Sets up the Dwm window manager.
2627
- **Kitty Setup**: Installs and configures Kitty for you.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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

tabs/applications-setup/tab_data.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name = "Applications Setup"
22

3+
[[data]]
4+
name = "Setup Flatpak / Flathub"
5+
script = "setup-flatpak.sh"
6+
37
[[data]]
48
name = "Alacritty"
59
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."

tabs/system-setup/system-update.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,18 @@ updateSystem() {
9393

9494
updateFlatpaks() {
9595
if command_exists flatpak; then
96-
flatpak update -y
96+
printf "%b\n" "${YELLOW}Updating installed Flathub apps...${RC}"
97+
installed_apps=$(flatpak list --app --columns=application)
98+
99+
if [ -z "$installed_apps" ]; then
100+
printf "%b\n" "${RED}No Flathub apps are installed.${RC}"
101+
return
102+
fi
103+
104+
for app in $installed_apps; do
105+
printf "%b\n" "${YELLOW}Updating $app...${RC}"
106+
flatpak update -y "$app"
107+
done
97108
fi
98109
}
99110

0 commit comments

Comments
 (0)