forked from xiangrui120/v2ray-heroku-undone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
144 lines (125 loc) · 3.27 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#! /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
root_dir=/root/workplace/proxy/
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'
# download v2ray core
if [ "$VER" = "latest" ]; then
V_VER=`curl -s -L "https://api.github.com/repos/v2ray/v2ray-core/releases/latest" | jq -r ".tag_name"`
else
V_VER="v$VER"
fi
v2raydir=${root_dir}/v2raybin
if [ -d ${v2raydir} ]; then
mkdir -p ${v2raydir}
fi
cd ${v2raydir}
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 -d ${v2raydir}/v2ray-$V_VER-linux-$SYS_Bit/
rm -rf v2ray.zip
chmod +x ${v2raydir}/v2ray-$V_VER-linux-$SYS_Bit/*
# download caddy
C_VER=`wget -qO- "https://api.github.com/repos/mholt/caddy/releases/latest" | jq -r ".tag_name"`
caddydir=${root_dir}/v2raybin
if [ -d ${caddydir} ]; then
mkdir -p ${caddydir}
fi
cd ${caddydir}
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
wwwdir=${root_dir}/wwwroot
if [ -d ${wwwdir} ]; then
mkdir -p ${wwwdir}
fi
cd ${wwwdir}
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 > ${v2raydir}/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 > ${caddydir}/Caddyfile
http://0.0.0.0:${PORT}
{
root ${wwwdir}
index index.html
timeouts none
proxy ${V2_Path} localhost:2333 {
websocket
header_upstream -Origin
}
}
EOF
cat <<-EOF > ${v2raydir}/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 ${wwwdir}/$V2_QR_Path
vmess="vmess://$(cat ${v2raydir}/vmess.json | base64 -w 0)"
Linkbase64=$(echo -n "${vmess}" | tr -d '\n' | base64 -w 0)
echo "${Linkbase64}" | tr -d '\n' > ${wwwdir}/$V2_QR_Path/index.html
echo -n "${vmess}" | qrencode -s 6 -o ${wwwdir}/$V2_QR_Path/v2.png
fi
cd ${v2raydir}/v2ray-$V_VER-linux-$SYS_Bit && ./v2ray &
cd ${caddydir} && ./caddy -conf="Caddyfile"