forked from a49v033/brook-heroku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
66 lines (58 loc) · 2.14 KB
/
build.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
#!/bin/bash
ver=$(wget -qO- "https://api.github.com/repos/txthinking/brook/releases/latest" | sed -n -r -e 's/.*"tag_name".+?"([vV0-9\.]+?)".*/\1/p')
[[ -z "${ver}" ]] && ver="v20210401"
brook_latest="https://github.com/txthinking/brook/releases/download/$ver/brook_linux_amd64"
wget --no-check-certificate $brook_latest
chmod +x brook_linux_amd64
./brook_linux_amd64 wsserver -l :12345 --path ${ws_path} -p $password &
[[ -z "${ws_path}" ]] && ws_path="/ws"
[[ -z "${url_redir}" ]] && url_redir="duma.gov.ru"
if [[ "${domain}" != "skip" ]]; then
# generate a Brook link and a QR code
mkdir /root/$password
brook_link=$(./brook_linux_amd64 link -s wss://${domain}:443${ws_path} -p $password | tr -d "\n")
echo -n "${brook_link}" >/root/$password/link.txt
echo -n "${brook_link}" | qrencode -s 6 -o /root/$password/qr.png
echo -n "The Brook link is ${brook_link}"
else
echo "skip generating"
fi
cat >/etc/nginx/conf.d/brook.conf <<EOF
server {
listen ${PORT};
listen [::]:${PORT};
root /root;
resolver 8.8.8.8:53;
location / {
proxy_pass https://${url_redir};
}
location = ${ws_path} {
if (\$http_upgrade != "websocket") {
return 404;
}
proxy_redirect off;
proxy_pass http://127.0.0.1:12345;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$http_host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location /$password {
root /root;
}
}
EOF
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo Nginx config: /etc/nginx/conf.d/brook.conf
cat /etc/nginx/conf.d/brook.conf
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo .
echo ////////////////////////////////////////////////////
echo "Brook wss client: remember replacing [app-name]!!!"
echo "Server: wss://${domain}:443${ws_path}"
echo "Password: $password"
echo ////////////////////////////////////////////////////
rm -rf /etc/nginx/sites-enabled/default
nginx -g 'daemon off;'