Skip to content

Commit f5d58da

Browse files
update
1 parent 9435930 commit f5d58da

File tree

20 files changed

+316
-772
lines changed

20 files changed

+316
-772
lines changed

.spinner/spinner.sh

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

bin/lamp

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/usr/bin/env bash
2+
3+
MENU=(
4+
"Start Apache"
5+
"Start MySQL"
6+
"Stop Apache"
7+
"Stop MySQL"
8+
)
9+
10+
COLOR_BASED="\e[39m"
11+
COLOR_DANGER="\e[91m"
12+
COLOR_WARNING="\e[93m"
13+
COLOR_SUCCESS="\e[92m"
14+
COLOR_SKY="\e[34m"
15+
COLOR_DEFAULT="\e[39m"
16+
COLOR_RESET="\033[0m"
17+
18+
OK="\u2714"
19+
FAIL="\u2718"
20+
COG="\u2699"
21+
22+
_spinner() {
23+
# $1 start/stop
24+
#
25+
# on start: $2 display message
26+
# on stop : $2 process exit status
27+
# $3 spinner function pid (supplied from stop_spinner)
28+
29+
local on_success="done"
30+
local on_fail="fail"
31+
local white="\e[1;37m"
32+
local green="\e[1;32m"
33+
local red="\e[1;31m"
34+
local nc="\e[0m"
35+
36+
case $1 in
37+
start)
38+
# calculate the column where spinner and status msg will be displayed
39+
let column=$(tput cols)-${#2}-32
40+
# display message and position the cursor in $column column
41+
echo -ne " ${2}"
42+
printf "%${column}s"
43+
44+
# start spinner
45+
i=1
46+
sp='\|/-'
47+
delay=${SPINNER_DELAY:-0.2}
48+
49+
while :
50+
do
51+
printf "\b${sp:i++%${#sp}:1}"
52+
sleep $delay
53+
done
54+
;;
55+
stop)
56+
if [[ -z ${3} ]]; then
57+
echo "spinner is not running.."
58+
exit 1
59+
fi
60+
61+
kill $3 > /dev/null 2>&1
62+
63+
# inform the user uppon success or failure
64+
echo -en "\b["
65+
if [[ $2 -eq 0 ]]; then
66+
echo -en "${green}${OK}${nc}"
67+
else
68+
echo -en "${red}${FAIL}${nc}"
69+
fi
70+
echo -e "]"
71+
;;
72+
*)
73+
echo "invalid argument, try {start/stop}"
74+
exit 1
75+
;;
76+
esac
77+
}
78+
79+
start_spinner() {
80+
# $1 : msg to display
81+
_spinner "start" "${1}" &
82+
# set global spinner pid
83+
_sp_pid=$!
84+
disown
85+
}
86+
87+
stop_spinner() {
88+
# $1 : command exit status
89+
_spinner "stop" $1 $_sp_pid
90+
unset _sp_pid
91+
}
92+
93+
banner() {
94+
if [ $1 == "enable" ]; then
95+
echo -e "
96+
╭────────────────────╮
97+
${COG} Enable Service │
98+
╰────────────────────╯
99+
"
100+
else
101+
echo -e "
102+
╭─────────────────────╮
103+
${COG} Disable Service │
104+
╰─────────────────────╯
105+
"
106+
fi
107+
}
108+
109+
service() {
110+
if sv-${1} ${2}; then
111+
stop_spinner $?
112+
else
113+
stop_spinner $?
114+
fi
115+
}
116+
117+
run() {
118+
banner ${1}
119+
start_spinner "· ${2} ${COLOR_WARNING}${3}${COLOR_DEFAULT} Service"
120+
sleep 1s
121+
service ${1} ${4}
122+
}
123+
124+
switchCase() {
125+
126+
read -p " ${1}: " SWITCH_CASE
127+
128+
case "$SWITCH_CASE" in
129+
130+
"0" )
131+
if [ -f $PREFIX/var/run/apache2/httpd.pid ]; then
132+
rm $PREFIX/var/run/apache2/httpd.pid
133+
fi
134+
run "enable" "Start" "Apache" "httpd"
135+
;;
136+
137+
"1" )
138+
run "enable" "Start" "MySQL" "mysqld"
139+
;;
140+
141+
"2" )
142+
run "disable" "Stop" "Apache" "httpd"
143+
;;
144+
145+
"3" )
146+
run "disable" "Stop" "MySQL" "mysqld"
147+
;;
148+
149+
esac
150+
151+
}
152+
153+
menu() {
154+
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]}"
161+
done
162+
echo -e " │ │"
163+
echo -e " ╰─────────────────────╯\n"
164+
}
165+
166+
menu
167+
switchCase "Choose"

bin/lamp-check

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
3+
HOST="127.0.0.1"
4+
PORT="8080"
5+
6+
response() {
7+
8+
PROTOCOL=`curl -I ${1} 2> /dev/null | sed -n 1p | awk '{printf $1}'`
9+
STATUS=`curl -I ${1} 2> /dev/null | sed -n 1p | awk '{printf $2}'`
10+
SERVER=`curl -I ${1} 2> /dev/null | sed -n 3p | awk '{print $2" "$3}'`
11+
CONTENT=`curl -I ${1} 2> /dev/null | grep Content-Type: | awk '{printf $2" "$3}'`
12+
13+
echo -e "
14+
╭─ LAMP CHECK ──────────────────────────────────────────╮"
15+
echo -e " │ │"
16+
17+
echo -e " │ Request URL: http://${HOST}:${PORT}"
18+
echo -e " │ │"
19+
printf " │ %-10s %-8s %-29s │\n" "PATH" "Header" "Value"
20+
printf " │ %-10s %-8s %-29s │\n" "──────────" "────────" "─────────────────────────────"
21+
echo -e " │ │"
22+
23+
printf " │ %-11s %-8s %-29s │\n" ${2} "Protocol" ${PROTOCOL}
24+
25+
if [ ${STATUS} == "200" ]; then
26+
printf " │ %-10s %-8s %-31s│\n" "" "Status" "${STATUS} OK"
27+
elif [ ${STATUS} == "301" ]; then
28+
printf " │ %-10s %-8s %-31s│\n" "" "Status" "${STATUS} Moved Permanently"
29+
elif [ ${STATUS} == "403" ]; then
30+
printf " │ %-10s %-8s %-31s│\n" "" "Status" "${STATUS} Forbidden"
31+
fi
32+
33+
# printf " │ %-10s %-8s %b │\n" "" "Server" ${SERVER}
34+
echo -e " │ Server ${SERVER}"
35+
echo -e " │ Content ${CONTENT}"
36+
# printf " │ %-10s %-8s %-21s %-20s %-29s" ${2} ${PROTOCOL} ${STATUS} ${SERVER} ${CONTENT}
37+
echo -e " │ │"
38+
echo -e " ╰───────────────────────────────────────────────────────╯\n"
39+
}
40+
41+
response "http://${HOST}:${PORT}/phpmyadmin" "/phpmyadmin"
42+
response "http://${HOST}:${PORT}" "/"

dump.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
HELPERS=(
4+
colors config cursor finish htdocs
5+
icon packages screen signal shortcutexec
6+
spinner stat switchcase
7+
)
8+
9+
for HELPER in ${HELPERS[@]}; do
10+
source helper/${HELPER}.sh
11+
done
12+
13+
# clear
14+
printInfoPackages
15+
# echo -e ""
16+
# switchCase "Do you want to install" "packages" installPackages
17+
# config
18+
# htdocs
19+
# shortcutexec

0 commit comments

Comments
 (0)