Skip to content

Commit 7bb571b

Browse files
update shortcut LAMP
1 parent 42ab725 commit 7bb571b

File tree

2 files changed

+74
-68
lines changed

2 files changed

+74
-68
lines changed

bin/lamp

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
#!/usr/bin/env bash
22

3-
MENU=(
4-
"Start Apache"
5-
"Start MySQL"
6-
"Stop Apache"
7-
"Stop MySQL"
8-
)
3+
HOST=127.0.0.1
4+
PORT=8080
95

6+
COLOR_DEFAULT="\e[39m"
7+
COLOR_RESET="\033[0m"
108
COLOR_BASED="\e[39m"
119
COLOR_DANGER="\e[91m"
1210
COLOR_WARNING="\e[93m"
1311
COLOR_SUCCESS="\e[92m"
1412
COLOR_SKY="\e[34m"
15-
COLOR_DEFAULT="\e[39m"
16-
COLOR_RESET="\033[0m"
13+
14+
MENU=(
15+
"Start Apache"
16+
"Start MySQL"
17+
"Stop Apache"
18+
"Stop MySQL"
19+
"Check Apache"
20+
"Check Phpmyadmin"
21+
)
1722

1823
OK="\u2714"
1924
FAIL="\u2718"
@@ -114,13 +119,52 @@ service() {
114119
fi
115120
}
116121

117-
run() {
122+
runService() {
118123
banner ${1}
119124
start_spinner "· ${2} ${COLOR_WARNING}${3}${COLOR_DEFAULT} Service"
120125
sleep 1s
121126
service ${1} ${4}
122127
}
123128

129+
response() {
130+
if curl -I ${1} &>/dev/null; then
131+
PROTOCOL=`curl -I ${1} 2> /dev/null | sed -n 1p | awk '{printf $1}'`
132+
STATUS=`curl -I ${1} 2> /dev/null | sed -n 1p | awk '{printf $2}'`
133+
SERVER=`curl -I ${1} 2> /dev/null | sed -n 3p | awk '{print $2" "$3}'`
134+
CONTENT=`curl -I ${1} 2> /dev/null | grep Content-Type: | awk '{printf $2" "$3}'`
135+
136+
echo -e "
137+
╭─ LAMP CHECK ───────────────────────────────────╮"
138+
echo -e " │ │"
139+
140+
echo -e " │ Request URL: http://${HOST}:${PORT}"
141+
echo -e " │ │"
142+
printf " │ %-11s %-8s %-21s │\n" "PATH" "Header" "Value"
143+
printf " │ %-11s %-8s %-20s │\n" "───────────" "────────" "─────────────────────"
144+
echo -e " │ │"
145+
146+
printf " │ %-11s %-8s %-21s │\n" ${2} "Protocol" ${PROTOCOL}
147+
148+
if [[ ${STATUS} == "200" ]]; then
149+
printf " │ %-10s %-8s ${COLOR_SUCCESS}%-23s${COLOR_DEFAULT}│\n" "" "Status" "${STATUS} OK"
150+
elif [[ ${STATUS} == "301" ]]; then
151+
printf " │ %-10s %-8s ${COLOR_SUCCESS}%-23s${COLOR_DEFAULT}│\n" "" "Status" "${STATUS} Moved Permanently"
152+
elif [[ ${STATUS} == "403" ]]; then
153+
printf " │ %-10s %-8s ${COLOR_DANGER}%-23s${COLOR_DEFAULT}│\n" "" "Status" "${STATUS} Forbidden"
154+
fi
155+
156+
echo -e " │ Server ${SERVER}"
157+
echo -e " │ │"
158+
echo -e " ╰────────────────────────────────────────────────╯\n"
159+
else
160+
echo -e "
161+
╭──────────────────╮
162+
│ Server Stopped │
163+
╰──────────────────╯
164+
"
165+
fi
166+
}
167+
124168
switchCase() {
125169

126170
read -p " ${1}: " SWITCH_CASE
@@ -131,19 +175,27 @@ switchCase() {
131175
if [ -f $PREFIX/var/run/apache2/httpd.pid ]; then
132176
rm $PREFIX/var/run/apache2/httpd.pid
133177
fi
134-
run "enable" "Start" "Apache" "httpd"
178+
runService "enable" "Start" "Apache" "httpd"
135179
;;
136180

137181
"1" )
138-
run "enable" "Start" "MySQL" "mysqld"
182+
runService "enable" "Start" "MySQL" "mysqld"
139183
;;
140184

141185
"2" )
142-
run "disable" "Stop" "Apache" "httpd"
186+
runService "disable" "Stop" "Apache" "httpd"
143187
;;
144188

145189
"3" )
146-
run "disable" "Stop" "MySQL" "mysqld"
190+
runService "disable" "Stop" "MySQL" "mysqld"
191+
;;
192+
193+
"4" )
194+
response "${HOST}:${PORT}" "/"
195+
;;
196+
197+
"5" )
198+
response "${HOST}:${PORT}/phpmyadmin" "/phpmyadmin"
147199
;;
148200

149201
esac
@@ -152,15 +204,16 @@ switchCase() {
152204

153205
menu() {
154206
echo -e "
155-
╭─ MENU ──────────────╮"
156-
echo -e " │ │"
157-
printf " │ %-3s %-12s │\n" "No." "Name"
158-
printf " │ %-3s %-20s │\n" "───" "────────────"
159-
for (( i=0; i<4; i++ )); do
160-
printf " │ %-3s %-12s │\n" "[$i]" "${MENU[$i]}"
207+
╭─ MENU ──────────────────╮"
208+
echo -e " │ │"
209+
printf " │ %-3s %-16s │\n" "No." "Name"
210+
printf " │ %-3s %-24s │\n" "───" "────────────────"
211+
echo -e " │ │"
212+
for (( i=0; i<6; i++ )); do
213+
printf " │ %-3s %-16s │\n" "[$i]" "${MENU[$i]}"
161214
done
162-
echo -e " │ │"
163-
echo -e " ╰─────────────────────╯\n"
215+
echo -e " "
216+
echo -e " ╰─────────────────────────╯\n"
164217
}
165218

166219
menu

bin/lamp-check

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)