forked from xiangrui120/v2ray-heroku-undone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
129 lines (115 loc) · 2.96 KB
/
entrypoint.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
#! /bin/bash
if [[ -z "${UUID}" ]]; then
UUID="4890bd47-5180-4b1c-9a5d-3ef686543112"
fi
if [[ -z "${AlterID}" ]]; then
AlterID="10"
fi
if [[ -z "${V2_Path}" ]]; then
V2_Path="/FreeApp"
fi
if [[ -z "${V2_QR_Path}" ]]; then
V2_QR_Code="1234"
fi
rm -rf /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date -R
SYS_Bit="$(getconf LONG_BIT)"
[[ "$SYS_Bit" == '32' ]] && BitVer='_linux_386.tar.gz'
[[ "$SYS_Bit" == '64' ]] && BitVer='_linux_amd64.tar.gz'
if [ "$VER" = "latest" ]; then
V_VER=`wget -qO- "https://api.github.com/repos/v2ray/v2ray-core/releases/latest" | grep 'tag_name' | cut -d\" -f4`
else
V_VER="v$VER"
fi
mkdir /v2raybin
cd /v2raybin
wget --no-check-certificate -qO 'v2ray.zip' "https://github.com/v2ray/v2ray-core/releases/download/$V_VER/v2ray-linux-$SYS_Bit.zip"
unzip v2ray.zip
rm -rf v2ray.zip
chmod +x /v2raybin/v2ray-$V_VER-linux-$SYS_Bit/*
C_VER=`wget -qO- "https://api.github.com/repos/mholt/caddy/releases/latest" | grep 'tag_name' | cut -d\" -f4`
mkdir /caddybin
cd /caddybin
wget --no-check-certificate -qO 'caddy.tar.gz' "https://github.com/mholt/caddy/releases/download/$C_VER/caddy_$C_VER$BitVer"
tar xvf caddy.tar.gz
rm -rf caddy.tar.gz
chmod +x caddy
cd /root
mkdir /wwwroot
cd /wwwroot
wget --no-check-certificate -qO 'demo.tar.gz' "https://github.com/ki8852/v2ray-heroku-undone/raw/master/demo.tar.gz"
tar xvf demo.tar.gz
rm -rf demo.tar.gz
cat <<-EOF > /v2raybin/v2ray-$V_VER-linux-$SYS_Bit/config.json
{
"log":{
"loglevel":"warning"
},
"inbound":{
"protocol":"vmess",
"listen":"127.0.0.1",
"port":2333,
"settings":{
"clients":[
{
"id":"${UUID}",
"level":1,
"alterId":${AlterID}
}
]
},
"streamSettings":{
"network":"ws",
"wsSettings":{
"path":"${V2_Path}"
}
}
},
"outbound":{
"protocol":"freedom",
"settings":{
}
}
}
EOF
cat <<-EOF > /caddybin/Caddyfile
http://0.0.0.0:${PORT}
{
root /wwwroot
index index.html
timeouts none
proxy ${V2_Path} localhost:2333 {
websocket
header_upstream -Origin
}
}
EOF
cat <<-EOF > /v2raybin/vmess.json
{
"v": "2",
"ps": "${AppName}.herokuapp.com",
"add": "${AppName}.herokuapp.com",
"port": "443",
"id": "${UUID}",
"aid": "${AlterID}",
"net": "ws",
"type": "none",
"host": "",
"path": "${V2_Path}",
"tls": "tls"
}
EOF
if [ "$AppName" = "no" ]; then
echo "不生成二维码"
else
mkdir /wwwroot/$V2_QR_Path
vmess="vmess://$(cat /v2raybin/vmess.json | base64 -w 0)"
Linkbase64=$(echo -n "${vmess}" | tr -d '\n' | base64 -w 0)
echo "${Linkbase64}" | tr -d '\n' > /wwwroot/$V2_QR_Path/index.html
echo -n "${vmess}" | qrencode -s 6 -o /wwwroot/$V2_QR_Path/v2.png
fi
cd /v2raybin/v2ray-$V_VER-linux-$SYS_Bit
./v2ray &
cd /caddybin
./caddy -conf="Caddyfile"