forked from saitamasahil/LinuxAppsManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflatpak.sh
More file actions
executable file
·198 lines (181 loc) · 7.12 KB
/
flatpak.sh
File metadata and controls
executable file
·198 lines (181 loc) · 7.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env bash
# Define some color variables
GREEN='\033[1m\033[32m'
PEACH='\e[1;38;2;255;204;153m'
NC='\033[0m' # No Color
# Function to display a menu with options
display_menu() {
# Show heading in middle
clear
echo ""
COLUMNS=$(tput cols)
t1="====================="
t2="Flatpak App Manager"
printf "${GREEN}%*s\n${NC}" $(((${#t1} + $COLUMNS) / 2)) "$t1"
printf "${GREEN}%*s\n${NC}" $(((${#t2} + $COLUMNS) / 2)) "$t2"
printf "${GREEN}%*s\n${NC}" $(((${#t1} + $COLUMNS) / 2)) "$t1"
echo ""
echo -e "${PEACH}Select Your Choice:${NC}"
echo "1. Setup Flatpak"
echo "2. List All Apps Including Runtimes"
echo "3. List User Installed Apps"
echo "4. Update All Apps"
echo "5. Search and Install App"
echo "6. Uninstall App"
echo "7. Downgrade App(Flathub Remote)"
echo "8. Delete Unused Runtime and Flatpak Cache"
echo "9. Go Back To Main Menu"
echo ""
echo -n "Enter your choice: "
}
# Function to install or uninstall flatpak system in a distro
setup_flatpak() {
# Detect the distro name using lsb_release command
distro=$(lsb_release -si)
echo "Your distro is $distro."
sleep 1
# Check if flatpak is already installed using command -v
if command -v flatpak >/dev/null; then
echo "Flatpak is already installed."
sleep 1
# Ask the user if they want to uninstall flatpak
read -rp "Do you want to uninstall flatpak? (y/n): " choice
case $choice in
[yY]*) # If yes, then use the appropriate command for the distro
echo "Uninstalling flatpak..."
sleep 1
case $distro in
Ubuntu | Debian) # For Ubuntu or Debian based distros, use apt remove
sudo apt remove --purge flatpak -y ;;
Fedora) # For Fedora based distros, use dnf remove
sudo dnf remove flatpak -y ;;
Arch | Manjaro) # For Arch or Manjaro based distros, use pacman -R
sudo pacman -R flatpak ;;
*) # For other distros, show an error message
echo "Sorry, I don't know how to uninstall flatpak on your distro." ;;
esac
;;
[nN]*) # If no, then do nothing and exit the function
echo "OK, keeping flatpak." ;;
*) # If invalid input, show an error message and exit the function
echo "Invalid input. Please enter y or n." ;;
esac
else # If flatpak is not installed, then use the appropriate command for the distro to install it
echo "Flatpak is not installed."
sleep 1
echo "Installing flatpak..."
sleep 1
case $distro in
Ubuntu | Debian) # For Ubuntu or Debian based distros, use apt install
sudo apt update && sudo apt install flatpak -y ;;
Fedora) # For Fedora based distros, use dnf install
sudo dnf install flatpak -y ;;
Arch | Manjaro) # For Arch or Manjaro based distros, use pacman -S
sudo pacman -S flatpak ;;
*) # For other distros, show an error message and exit the function
echo "Sorry, I don't know how to install flatpak on your distro." ;;
esac
# Add flathub repo
echo "Adding flathub repo..."
sleep 1
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
fi
sleep 1
read -rp "Press Enter to continue..."
}
# Function to list all installed Flatpak apps including runtimes
list_all_apps() {
echo "Listing All Apps Including Runtimes:"
sleep 1
echo "-----------------------"
flatpak list # Use flatpak command to list apps
sleep 1
read -rp "Press Enter to continue..."
}
# Function to list user installed flatpak apps
list_user_apps() {
echo "Listing User Installed Apps:"
sleep 1
echo "-----------------------"
flatpak list --app # Use flatpak command to list apps
sleep 1
read -rp "Press Enter to continue..."
}
# Function to update all installed Flatpak apps
update_apps() {
echo "Updating All Apps..."
sleep 1
echo "-----------------------"
flatpak update -y # Use flatpak command to update all apps with yes option
sleep 1
read -rp "Press Enter to continue..."
}
# Function to search and install a specific Flatpak app
install_app() {
read -rp "Enter the app name to search: " app_name
echo "Searching for $app_name..."
sleep 1
echo "-----------------------"
flatpak search "$app_name" # Use flatpak command to search for app name
sleep 1
echo "-----------------------"
read -rp "Enter the exact app name from above shown list to install: " app_install
flatpak install "$app_install" # Use flatpak command to install app
sleep 1
read -rp "Press Enter to continue..."
}
# Function to uninstall a specific Flatpak app
uninstall_app() {
read -rp "Enter the app name to uninstall: " app_name
flatpak uninstall "$app_name" # Use flatpak command to uninstall app
sleep 1
read -rp "Press Enter to continue..."
}
# Function to downgrade a specific Flatpak app
downgrade_app() {
echo "Find the application id in apps list."
sleep 3
echo ""
read -rp "Enter the application id of the app to downgrade: " app_id
flatpak remote-info --log flathub "$app_id" # Use flatpak command to show the commit history of the app
sleep 1
echo "-----------------------"
read -rp "Enter the commit ID of the version you want: " commit_id
sudo flatpak update --commit="$commit_id" "$app_id" # Use flatpak command to update the app to a specific commit
sleep 1
read -rp "Press Enter to continue..."
}
# Function to delete unused runtime and flatpak cache and other unnecessary things
delete_unused() {
echo "Deleting Unused Runtime and Flatpak Cache..."
sleep 1
echo "-----------------------"
flatpak uninstall --unused # Use flatpak command to uninstall unused runtime
flatpak repair --user # Use flatpak command to repair user installation
flatpak repair --system # Use flatpak command to repair system installation
rm -rf ~/.var/app/*/.cache # Use rm command to remove cache files
sleep 1
read -rp "Press Enter to continue..."
}
# Go back to main menu
main_menu() {
chmod +x manager.sh
./manager.sh
}
# Main loop
while true; do
display_menu # Display the menu
read -r choice
case $choice in # Handle the choice
1) setup_flatpak ;; # Install or uninstall flatpak system in a distro
2) list_all_apps ;; # List apps
3) list_user_apps ;; # List user apps
4) update_apps ;; # Update all apps
5) install_app ;; # Search and install app
6) uninstall_app ;; # Uninstall app
7) downgrade_app ;; # Downgrade app
8) delete_unused ;; # Delete unused runtime and flatpak cache
9) main_menu ;; # Exit to main menu
*) echo "Invalid choice. Please try again." ;; # Invalid choice
esac
done