forked from mayTermux/lampTermux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlamp
executable file
·195 lines (151 loc) · 4.19 KB
/
lamp
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
#!/bin/bash
df="\e[39m"
lrd="\e[91m"
lyw="\e[93m"
# Author: Tasos Latsas
# spinner.sh
#
# Display an awesome 'spinner' while running your long shell commands
#
# Do *NOT* call _spinner function directly.
# Use {start,stop}_spinner wrapper functions
# usage:
# 1. source this script in your's
# 2. start the spinner:
# start_spinner [display-message-here]
# 3. run your command
# 4. stop the spinner:
# stop_spinner [your command's exit status]
#
# Also see: test.sh
function _spinner() {
# $1 start/stop
#
# on start: $2 display message
# on stop : $2 process exit status
# $3 spinner function pid (supplied from stop_spinner)
local on_success="ok"
local on_fail="fail"
local white="\e[1;37m"
local green="\e[1;32m"
local red="\e[1;31m"
local nc="\e[0m"
case $1 in
start)
# calculate the column where spinner and status msg will be displayed
let column=$(tput cols)-${#2}-8
# display message and position the cursor in $column column
echo -ne ${2}
printf "%${column}s"
# start spinner
i=1
sp='\|/-'
delay=${SPINNER_DELAY:-0.2}
while :
do
printf "\b${sp:i++%${#sp}:1}"
sleep $delay
done
;;
stop)
if [[ -z ${3} ]]; then
echo "spinner is not running.."
exit 1
fi
kill $3 > /dev/null 2>&1
# inform the user uppon success or failure
echo -en "\b["
if [[ $2 -eq 0 ]]; then
echo -en "${green}${on_success}${nc}"
else
echo -en "${red}${on_fail}${nc}"
fi
echo -e "]"
;;
*)
echo "invalid argument, try {start/stop}"
exit 1
;;
esac
}
function start_spinner {
# $1 : msg to display
_spinner "start" "${1}" &
# set global spinner pid
_sp_pid=$!
disown
}
function stop_spinner {
# $1 : command exit status
_spinner "stop" $1 $_sp_pid
unset _sp_pid
}
function banner() {
echo -e " _ $lrd _______$df "
echo -e "| | $lrd (_______)$df "
echo -e "| | _____ ____ ____ _ _____ ____ ____ _ _ _ _ "
echo -e "| |(____ | \| _ \| | ___ |/ ___) \| | | ( \ / )"
echo -e "| |/ ___ | | | | |_| | | ____| | | | | | |_| |) X ( "
echo -e " \_)_____|_|_|_| __/|_|_____)_| |_|_|_|____/(_/ \_)"
echo -e " |_| \n"
echo -e " Version : 1.0"
echo -e " Build Date : 6 March 2021"
echo -e " Type : Shortcut\n"
echo -e "[1] Start Apache"
echo -e "[2] Start MySQL"
echo -e "[3] Stop Apache"
echo -e "[4] Stop MySQL\n"
}
function exec() {
banner
read -p "Choose : " Choose
if [[ $Choose == 1 ]]; then
start_spinner "Enable Apache Service"
sleep 2
if [[ -f $PREFIX/var/run/apache2/httpd.pid ]]; then
rm $PREFIX/var/run/apache2/httpd.pid
if sv-enable httpd; then
stop_spinner $?
else
stop_spinner $?
fi
else
if sv-enable httpd; then
stop_spinner $?
else
stop_spinner $?
fi
fi
echo ""
elif [[ $Choose == 2 ]]; then
start_spinner "Enable MySQL Service"
sleep 2
if sv-enable mysqld; then
stop_spinner $?
else
stop_spinner $?
fi
echo ""
elif [[ $Choose == 3 ]]; then
start_spinner "Disable Apache Service"
sleep 2
if sv-disable httpd; then
stop_spinner $?
else
stop_spinner $?
fi
echo ""
elif [[ $Choose == 4 ]]; then
start_spinner "Disable MySQL Service"
sleep 2
if sv-disable mysqld; then
stop_spinner $?
else
stop_spinner $?
fi
echo ""
else
echo -e $lyw"ERROR :$lrd Bad usage !\n$df"
fi
}
exec