-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
135 lines (127 loc) · 4.61 KB
/
install.sh
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
#!/bin/bash
# Compatible with Ubuntu ≥ 18 || Debian ≥ 10
# https://github.com/jalalsaberi/BrookServer
BOLD="\e[1m"
UNDERLINE="\e[4m"
WHITE="\e[37m"
YELLOW="\e[33m"
BRIGHT_YELLOW="\e[93m"
MAGENTA="\e[35m"
CYAN="\e[36m"
RED="\e[31m"
END="\e[0m"
version='v2.0.2'
github='https://github.com/jalalsaberi/BrookServer'
brook=("brook.service" "brookws.service" "brookwss.service")
banner() {
echo -e " ${MAGENTA}╔╗ ┬─┐┌─┐┌─┐┬┌─ ╔═╗┌─┐┬─┐┬ ┬┌─┐┬─┐${END}"
echo -e " ${MAGENTA}╠╩╗├┬┘│ ││ │├┴┐ ╚═╗├┤ ├┬┘└┐┌┘├┤ ├┬┘${END}"
echo -e " ${MAGENTA}╚═╝┴└─└─┘└─┘┴ ┴ ╚═╝└─┘┴└─ └┘ └─┘┴└─${END}"
echo -e "${YELLOW}──────────────────────────────────────────${END}"
echo -e " ${WHITE}$version${END}"
echo -e "${YELLOW}──────────────────────────────────────────${END}"
echo -e "${CYAN}${UNDERLINE}$github${END}"
echo -e "${YELLOW}──────────────────────────────────────────${END}\n"
}
blink_str() {
clear
banner
local msg=$1
for i in {1..2}; do
clear && echo -e "${YELLOW}$msg${END}"&& sleep 0.2
clear && echo -e "${RED}$msg${END}" && sleep 0.2
clear && echo -e "${YELLOW}$msg${END}"&& sleep 0.2
clear && echo -e "${RED}$msg${END}" && sleep 0.2
done
}
add_var() {
local protocol="$1"
local status="$2"
if [ -f "$HOME/.brook-cli" ]; then
source "$HOME/.brook-cli" > /dev/null
fi
if [[ $protocol == "br" ]]; then
export "BROOK=$status"
sed -i '/^export BROOK=/d' "$HOME/.brook-cli" && echo "export BROOK=$status" >> "$HOME/.brook-cli"
elif [[ $protocol == "ws" ]]; then
export "BROOKWS=$status"
sed -i '/^export BROOKWS=/d' "$HOME/.brook-cli" && echo "export BROOKWS=$status" >> "$HOME/.brook-cli"
elif [[ $protocol == "wss" ]]; then
export "BROOKWSS=$status"
sed -i '/^export BROOKWSS=/d' "$HOME/.brook-cli" && echo "export BROOKWSS=$status" >> "$HOME/.brook-cli"
elif [[ $protocol == "all" ]]; then
export "BROOK=$status"
export "BROOKWS=$status"
export "BROOKWSS=$status"
export "BROOKALL=$status"
sed -i '/^export BROOK=/d' "$HOME/.brook-cli" && echo "export BROOK=$status" >> "$HOME/.brook-cli"
sed -i '/^export BROOKWS=/d' "$HOME/.brook-cli" && echo "export BROOKWS=$status" >> "$HOME/.brook-cli"
sed -i '/^export BROOKWSS=/d' "$HOME/.brook-cli" && echo "export BROOKWSS=$status" >> "$HOME/.brook-cli"
sed -i '/^export BROOKALL=/d' "$HOME/.brook-cli" && echo "export BROOKALL=$status" >> "$HOME/.brook-cli"
else
blink_str "Invalid Input!!!"
menu_cli
fi
if [ -f "$HOME/.brook-cli" ]; then
source "$HOME/.brook-cli" > /dev/null
fi
}
stop_service() {
add_var "all" "9"
count=0
for service in "${brook[@]}"; do
service_status=$(systemctl is-active $service)
if [ "$service_status" = "active" ]; then
systemctl stop "${brook[$count]}" && systemctl disable "${brook[$count]}"
echo -e "${BOLD}${BRIGHT_YELLOW}$service_status${END} ${BRIGHT_YELLOW}Stopped Successfully.${END}"
count+=1
else
continue
fi
echo -e "${BOLD}${BRIGHT_YELLOW}No Service${END} ${BRIGHT_YELLOW}is running.${END}"
done
systemctl reset-failed && systemctl daemon-reload
}
apt_up() {
clear
banner
echo -e "${MAGENTA}${BOLD}[APT Update]${END}"
sleep 0.5
apt update -y
apt install curl -y
}
nami_brook() {
clear
banner
echo -e "${MAGENTA}${BOLD}[Installing Nami & Brook]${END}"
sleep 0.5
curl https://bash.ooo/nami.sh > nami.sh
sed -i '/exec -l \$SHELL/d' nami.sh
chmod +x nami.sh
bash nami.sh
rm -f nami.sh
clear
banner
echo -e "${MAGENTA}${BOLD}[Installing Brook Server]${END}"
sleep 0.5
stop_service
nami install brook
}
# Start
touch $HOME/.brook-cli
chmod +x $HOME/.brook-cli
cat > $HOME/.brook-cli <<EOF
export BROOK=9
export BROOKWS=9
export BROOKWSS=9
export BROOKALL=0
EOF
if [ -f "$HOME/.brook-cli" ]; then
source "$HOME/.brook-cli" > /dev/null
fi
apt_up
curl -Ls https://raw.githubusercontent.com/jalalsaberi/BrookServer/main/cli.sh -o /usr/bin/brook-cli
chmod +x /usr/bin/brook-cli
nami_brook
source $HOME/.bashrc
brook-cli