forked from saitamasahil/LinuxAppsManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnap.sh
More file actions
executable file
·178 lines (162 loc) · 6.12 KB
/
snap.sh
File metadata and controls
executable file
·178 lines (162 loc) · 6.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
#!/usr/bin/env bash
# Define some color variables
BLUE='\e[1;1;34m'
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="Snap App Manager"
printf "${BLUE}%*s\n${NC}" $(((${#t1} + $COLUMNS) / 2)) "$t1"
printf "${BLUE}%*s\n${NC}" $(((${#t2} + $COLUMNS) / 2)) "$t2"
printf "${BLUE}%*s\n${NC}" $(((${#t1} + $COLUMNS) / 2)) "$t1"
echo ""
echo -e "${PEACH}Select Your Choice:${NC}"
echo "1. Setup Snap"
echo "2. List All Apps Including Core Components"
echo "3. List Installed Apps Excluding Core Components"
echo "4. Update All Apps"
echo "5. Search and Install App"
echo "6. Uninstall App"
echo "7. Downgrade App"
echo "8. Go Back To Main Menu"
echo ""
echo -n "Enter your choice: "
}
# Function to install or uninstall snap system in a distro
setup_snap() {
# Detect the distro name using lsb_release command
distro=$(lsb_release -si)
echo "Your distro is $distro."
sleep 1
# Check if snap is already installed using command -v
if command -v snap >/dev/null; then
echo "Snap is already installed."
sleep 1
# Ask the user if they want to uninstall snap
read -rp "Do you want to uninstall snap? (y/n): " choice
case $choice in
[yY]*) # If yes, then use the appropriate command for the distro
echo "Uninstalling snap..."
sleep 1
case $distro in
Ubuntu | Debian) # For Ubuntu or Debian based distros, use apt remove
sudo apt remove --purge snapd -y ;;
Fedora) # For Fedora based distros, use dnf remove
sudo dnf remove snapd -y ;;
Arch | Manjaro) # For Arch or Manjaro based distros, use pacman -R
sudo pacman -R snapd ;;
*) # For other distros, show an error message
echo "Sorry, I don't know how to uninstall snap on your distro." ;;
esac
;;
[nN]*) # If no, then do nothing and exit the function
echo "OK, keeping snap." ;;
*) # If invalid input, show an error message and exit the function
echo "Invalid input. Please enter y or n." ;;
esac
else # If snap is not installed, then use the appropriate command for the distro to install it
echo "Snap is not installed."
sleep 1
echo "Installing snap..."
sleep 1
case $distro in
Ubuntu | Debian) # For Ubuntu or Debian based distros, use apt install
sudo apt update && sudo apt install snapd -y ;;
Fedora) # For Fedora based distros, use dnf install
sudo dnf install snapd -y ;;
Arch | Manjaro) # For Arch or Manjaro based distros, use pacman -S
sudo pacman -S snapd ;;
*) # For other distros, show an error message and exit the function
echo "Sorry, I don't know how to install snap on your distro." ;;
esac
# Add sudo snap install core command to activate snap on some distros
echo "Activating snap..."
sleep 1
sudo snap install core
fi
sleep 1
read -rp "Press Enter to continue..."
}
# Function to list all installed Snap apps
list_all_apps() {
echo "Listing All Apps Including Core Components:"
sleep 1
echo "-----------------------"
snap list # Use snap command to list apps
sleep 1
read -rp "Press Enter to continue..."
}
# Function to list installed apps excluding core components
list_user_apps() {
echo "Listing Installed Apps Excluding Core Component:"
sleep 1
echo "-----------------------"
snap list | grep -v "^core" # Use snap command to list apps
sleep 1
read -rp "Press Enter to continue..."
}
# Function to update all installed Snap apps
update_apps() {
echo "Updating All Apps..."
sleep 1
echo "-----------------------"
snap refresh # Use snap command to update all apps
sleep 1
read -rp "Press Enter to continue..."
}
# Function to search and install a specific Snap app
install_app() {
read -rp "Enter the app name to search: " app_name
echo "Searching for $app_name..."
sleep 1
echo "-----------------------"
snap find "$app_name" # Use snap command to search for app name
sleep 1
echo "-----------------------"
read -rp "Enter the exact app name from above shown list to install: " app_install
snap install "$app_install" # Use snap command to install app
sleep 1
read -rp "Press Enter to continue..."
}
# Function to uninstall a specific Snap app
uninstall_app() {
read -rp "Enter the app name to uninstall: " app_name
snap remove --purge "$app_name" # Use snap command to uninstall app
sleep 1
read -rp "Press Enter to continue..."
}
# Function to downgrade a specific Snap app
downgrade_app() {
read -rp "Enter the app name to downgrade: " app_name
snap list "$app_name" --all # List the installed versions of the app
read -rp "Enter the revision number to downgrade to: " rev_num
snap revert "$app_name" --revision "$rev_num" # Revert to the specified revision
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_snap ;; # Install or uninstall snap system in a distro
2) list_all_apps ;; # List apps
3) list_user_apps ;; # List installed apps excluding core 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) main_menu ;; # Exit to main menu
*) echo "Invalid choice. Please try again." ;; # Invalid choice
esac
done