-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup
executable file
·139 lines (123 loc) · 3.88 KB
/
setup
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
#!/usr/bin/env bash
# Define some color variables
TOMATO='\e[1;38;2;255;99;71m'
PEACH='\e[1;38;2;255;204;153m'
GREEN='\033[1m\033[38;2;0;255;0m'
RED='\033[1m\033[38;5;196m'
AQUA='\e[1;38;2;0;255;255m'
NC='\033[0m' # No Color
# Define a function to exit the script
exit_script() {
clear
cd ~ # Change directory to home
# Get the name of the current shell
shell_name=$(basename "$SHELL")
# Run the exec command according to the shell
case $shell_name in
bash) exec bash ;;
zsh) exec zsh ;;
ksh) exec ksh ;;
csh) exec csh ;;
tcsh) exec tcsh ;;
fish) exec fish ;;
*) echo "Unknown shell: $shell_name" ;;
esac
}
# Set a trap to call the function when SIGTSTP(ctrl + z) & SIGINT(ctrl + c) is received
trap exit_script SIGTSTP
trap exit_script SIGINT
# Go back to main menu
main_menu() {
chmod +x manager
./manager
}
# Get the name of the current shell
shell=$(basename "$SHELL")
# Get the current working directory of the script
pwd=$(pwd)
# Show heading in middle
clear
echo ""
COLUMNS=$(tput cols)
t1="=========================="
t2="Linux Apps Manager Setup"
printf "${TOMATO}%*s\n${NC}" $(((${#t1} + $COLUMNS) / 2)) "$t1"
printf "${TOMATO}%*s\n${NC}" $(((${#t2} + $COLUMNS) / 2)) "$t2"
printf "${TOMATO}%*s\n${NC}" $(((${#t1} + $COLUMNS) / 2)) "$t1"
echo ""
# Ask user what option they want to choose
echo -e "${PEACH}Select Your Choice:${NC}"
echo " 1. Install Linux Apps Manager In System"
echo " 2. Uninstall Linux Apps Manager From System"
echo " 3. Go Back To Main Menu"
read -p "Enter your choice: " choice
if [ $choice -eq 1 ]; then
echo ""
# This script adds the lam function definition to the appropriate shell configuration file
# Check if the configuration file exists
if [ -f ~/."$shell"rc ]; then
# Check if the lam function is already defined in the file
if grep -q "lam ()" ~/."$shell"rc; then
# Delete the existing lam function
sed -i '/lam ()/,/^}/d' ~/."$shell"rc
fi
# Append the function definition to the end of the file
tail -c1 ~/."$shell"rc | read -r _ || echo "" >>~/."$shell"rc && cat >>~/."$shell"rc <<EOF
lam () {
# Go to the saved directory
cd "$pwd"
# Check if manager exists
if [ -f manager ]; then
chmod +x manager && ./manager
else
echo "Linux Apps Manager is not available in your system."
fi
}
EOF
echo -e "${AQUA}Linux Apps Manager has been successfully installed on your system. Important notes:${NC}"
echo "• To run Linux Apps Manager, type 'lam' in terminal."
echo "• Don't delete the directory where you cloned the repository."
echo ""
read -n 1 -s -r -p "Press any key to continue..."
echo
clear
cd ~
$shell
else
# Print an error message & make ."$shell"rc file
echo -e "${RED}."$shell"rc file not found.${NC}"
sleep 1
echo -e "${GREEN}Fixing this issue...${NC}"
sleep 3
touch ~/."$shell"rc
echo -e "${AQUA}Issue fixed. Try option 1 again.${NC}"
sleep 3
chmod +x setup && ./setup
fi
elif [ $choice -eq 2 ]; then
echo ""
# Check if the lam function is defined in the .shellrc file
if grep -q "lam ()" ~/."$shell"rc; then
# Delete function and directory
sed -i '/lam ()/,/^}/d' ~/."$shell"rc
rm -rf "$pwd"
if [ $? -eq 0 ]; then # check the exit status of rm command
echo -e "${GREEN}Uninstalled successfully.${NC}"
sleep 3
exit_script
else
echo -e "${RED}Failed to uninstall!${NC}"
fi
else
echo -e "${AQUA}Linux Apps Manager isn't available in your system.${NC}"
sleep 3
chmod +x setup && ./setup
fi
elif [ $choice -eq 3 ]; then
main_menu
else
echo ""
echo -e "${RED}Invalid choice. Please try again.${NC}"
sleep 3
chmod +x setup && ./setup
fi