-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
xamp
293 lines (222 loc) · 6.33 KB
/
xamp
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/bash
rd="\e[1;31m"
gr="\e[1;32m"
yl="\e[1;33m"
cy="\e[1;36m"
wht="\e[0m"
banner(){
clear
echo -e ${rd}
echo " ██ ██ █████ ███ ███ ██████ "
echo " ██ ██ ██ ██ ████ ████ ██ ██ "
echo " ███ ███████ ██ ████ ██ ██████ "
echo " ██ ██ ██ ██ ██ ██ ██ ██ "
echo " ██ ██ ██ ██ ██ ██ ██ "
echo -e " ${cy} -By Adarsh Addee"
echo
echo -e "${yl} ) --------------- ${gr}Start${yl} --------------- ("
echo -e "${yl} ) --------------- ${gr}Your Own${yl} --------------- ("
echo -e "${yl} ) -------------- ${gr}Server${yl} --------------- ("
echo -e "${wht}\n"
}
help(){
banner
cat << EOF
[*] XAMP: Start Your Own Server with XAMP in Android!!!!
usage: xamp [argss]
args:
-h, --help show help message and exit
-b, --banner show banner and exit
-py, --pyserver start python server
-php, --phpserver start php server
-sql, --mysql start mysql server
-ap2, --apache2 start apache2 server
-ng, --nginx start nginx server
-s, --stop stop serving localhost and exit
-v, --version show version and exit
stop service:
-s, --stop stop serving localhost service
[!] Note: Just Type xamp to start xamp in GUI Mode!!!
[!] Type localhost:8080 in browser to start local server!!!
[!] Xamp is a localserver hosting script which is very useful & made for android users (Termux)!!!
EOF
}
version(){
banner
echo "[*] xamp v1.0"
echo
}
loading(){
echo
echo -ne "${rd}[${yl}?${rd}]${cy} Starting Server...###"
for i in $( seq 15 ); do
echo -ne "#"
sleep 0.1
done
echo -e "${wht}"
}
start_mysql(){
banner
if [ ! -f ${HOME}/../usr/bin/mariadb ]; then
pkg install mariadb -y & sleep 1
start_mysql
else
echo -e "${rd}[${yl}!${rd}] ${yl}Mysql Found!!!"
loading
fi
if [ ! -d ${HOME}/../usr/etc/my.cnf.d ]; then
mkdir ${HOME}/../usr/etc/my.cnf.d
fi
sleep 1
mysqld_safe -u root & sleep 2
echo -e "\n${rd}[${yl}*${rd}]${gr} Mysql Server Started Successfully!!!\n"
mysql -h localhost
}
start_pyserver(){
banner
if [ ! -f ${HOME}/../usr/bin/python ]; then
pkg install python
start_pyserver
else
echo -e "${rd}[${yl}!${rd}] ${yl}Python Found!!!"
loading
fi
echo -e "\n${rd}[${yl}*${rd}]${gr} Python Server Started Successfully!!!\n"
sleep 0.5
echo -e "${rd}[${yl}!${rd}] ${wht}Serving Current Directory!\n"
echo -e "${rd}[${yl}!${rd}] ${yl}Type ${rd}127.0.0.1:8080 ${yl}in browser!!!\n"
sleep 0.5
python -m http.server 8080
}
start_phpserver(){
banner
if [ ! -f ${HOME}/../usr/bin/php ]; then
pkg install php
start_phpserver
else
echo -e "${rd}[${yl}!${rd}] ${yl}PHP Found!!!"
loading
fi
if [ ! -d ${PREFIX}/share/xamp ]; then
mkdir ${PREFIX}/share/xamp
fi
if [ ! -d ${PREFIX}/share/xamp/www ]; then
mkdir ${PREFIX}/share/xamp/www
fi
if [ ! -f ${PREFIX}/share/xamp/www/index.html ]; then
touch ${PREFIX}/share/xamp/www/index.html
fi
echo -e "\n${rd}[${yl}*${rd}]${gr} PHP Server Started Successfully!!!\n"
sleep 0.5
echo -e "${rd}[${yl}!${rd}] ${wht}You can make changes in ${cy}/share/xamp/www/index.html\n"
echo -e "${rd}[${yl}!${rd}] ${gr}Type 127.0.0.1:8080 in browser!!!\n\n"
sleep 0.5
php -S localhost:8080 ${PREFIX}/share/xamp/www/index.html
}
start_apache(){
banner
if [ ! -f ${HOME}/../usr/bin/apachectl ]; then
pkg install apache2
start_apache
else
echo -e "${rd}[${yl}!${rd}] ${yl}Apache Found!!!"
loading
fi
if [ -f ${HOME}/../usr/var/run/apache2/httpd.pid ]; then
rm ${HOME}/../usr/var/run/apache2/httpd.pid
fi
echo -e "\n${rd}[${yl}*${rd}]${gr} Apache Server Started Successfully!!!\n"
sleep 0.5
echo -e "${rd}[${yl}!${rd}] ${wht}You can make changes in ${cy}/share/apache2/default-site/htdocs/index.html\n"
echo -e "${rd}[${yl}!${rd}] ${gr}Type 127.0.0.1:8080 in browser!!!\n\n"
sleep 0.5
apachectl
}
start_nginx(){
banner
if [ ! -f ${HOME}/../usr/bin/nginx ]; then
pkg install nginx
start_nginx
else
echo -e "${rd}[${yl}!${rd}] ${yl}Nginx Found!!!"
loading
fi
# /usr/share/nginx/html/index.html
echo -e "\n${rd}[${yl}*${rd}]${gr} Nginx Server Started Successfully!!!\n"
sleep 0.5
echo -e "${rd}[${yl}!${rd}] ${wht}You can make changes in ${cy}/share/nginx/html/index.html\n"
echo -e "${rd}[${yl}!${rd}] ${gr}Type 127.0.0.1:8080 in browser!!!\n\n"
sleep 0.5
nginx
}
kill_pid(){
PID="php python mysql httpd nginx"
for process in ${PID};do
if [[ $(pidof ${process}) ]]; then
kill $(pidof ${process})
fi
done
}
gui(){
banner
clr=$gr
pkgs=( php nginx python mariadb apachectl )
echo -e "\n${cy}[!] Select any one option:\n"
for pack in $( seq ${#pkgs[@]} ); do
if [ ! -f $PREFIX/bin/${pkgs[${pack}-1]} ]; then
clr=$rd
fi
curpkg="${pkgs[${pack}-1]}"
echo -e "${rd}[${yl}0${pack}${rd}] ${clr}${curpkg}"
done
echo -e "${rd}[${yl}99${rd}] ${yl}Exit!!!"
echo -e "${rd}[${yl}00${rd}] ${yl}Stop Service(s)"
echo -e "${wht}"
read -p "[!] Enter your choice: " choice
case $choice in
"1" | "01" | "php" )
start_phpserver;;
"2" | "02" | "nginx" )
start_nginx;;
"3" | "03" | "python" )
start_pyserver;;
"4" | "04" | "sql" | "mysql" | "mariadb" )
start_mysql;;
"5" | "05" | "apachectl" | "apache2" | "apache" | "" )
start_apache;;
"0" | "00" | "stop" )
kill_pid;;
"99" | "exit" )
echo -e "Bye - Bye!!!\n";;
* )
help;;
esac
}
setup(){
if [ ! -f $PREFIX/bin/xamp ]; then
cp -f xamp $PREFIX/bin
fi
case $1 in
"-py" | "--pyserver" )
start_pyserver;;
"-php" | "--phpserver" )
start_phpserver;;
"-sql" | "--mysql" )
start_mysql;;
"-ap2" | "--apache" | "--apache2" )
start_apache;;
"-ng" | "--nginx" )
start_nginx;;
"-s" | "--stop" )
kill_pid;;
"-b" | "--banner" )
banner;;
"-v" | "--version" )
version;;
"" )
gui;;
"-h" | "--help" | *)
help;;
esac
}
setup $1