-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathtest.sh
172 lines (153 loc) · 5.5 KB
/
test.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# Initial Installation Dependencies
install_dependencies() {
packages="gawk curl openssl"
install=""
for pkg in $packages; do
if ! command -v $pkg &>/dev/null; then
install="$install $pkg"
fi
done
if [ -z "$install" ]; then
echo -e "\e[1;32mAll packages are already installed\e[0m"
return
fi
if command -v apt &>/dev/null; then
pm="apt-get install -y -q"
elif command -v dnf &>/dev/null; then
pm="dnf install -y"
elif command -v yum &>/dev/null; then
pm="yum install -y"
elif command -v apk &>/dev/null; then
pm="apk add"
else
echo -e "\e[1;33m暂不支持的系统!\e[0m"
exit 1
fi
$pm $install
}
install_dependencies
# Define Environment Variables
export NEZHA_SERVER=${NEZHA_SERVER:-'nz.f4i.cn'}
export NEZHA_PORT=${NEZHA_PORT:-'5555'}
export NEZHA_KEY=${NEZHA_KEY:-''}
export PORT=${PORT:-$(shuf -i 2000-65000 -n 1)}
export FILE_PATH=${FILE_PATH:-'./app'}
export SNI=${SNI:-'www.yahoo.com'}
export UUID=$(openssl rand -hex 16 | awk '{print substr($0,1,8)"-"substr($0,9,4)"-"substr($0,13,4)"-"substr($0,17,4)"-"substr($0,21,12)}')
echo -e "\e[1;32mInstallation is in progress, please wait...\e[0m"
# Download Dependency Files
ARCH=$(uname -m) && DOWNLOAD_DIR="${FILE_PATH}" && mkdir -p "$DOWNLOAD_DIR" && FILE_INFO=()
if [ "$ARCH" == "arm" ] || [ "$ARCH" == "arm64" ] || [ "$ARCH" == "aarch64" ]; then
FILE_INFO=("https://github.com/eooce/test/releases/download/arm64/xray web" "https://github.com/eooce/test/releases/download/ARM/swith npm")
elif [ "$ARCH" == "amd64" ] || [ "$ARCH" == "x86_64" ] || [ "$ARCH" == "x86" ]; then
FILE_INFO=("https://github.com/eooce/test/releases/download/amd64/xray web" "https://github.com/eooce/test/releases/download/bulid/swith npm")
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
for entry in "${FILE_INFO[@]}"; do
URL=$(echo "$entry" | cut -d ' ' -f 1)
NEW_FILENAME=$(echo "$entry" | cut -d ' ' -f 2)
FILENAME="$DOWNLOAD_DIR/$NEW_FILENAME"
if [ -e "$FILENAME" ]; then
echo -e "\e[1;32m$FILENAME already exists,Skipping download\e[0m"
else
curl -L -sS -o "$FILENAME" "$URL"
echo -e "\e[1;32mDownloading $FILENAME\e[0m"
fi
chmod +x $FILENAME
done
wait
# Generating Configuration Files
generate_config() {
X25519Key=$(./"${FILE_PATH}/web" x25519)
PrivateKey=$(echo "${X25519Key}" | head -1 | awk '{print $3}')
PublicKey=$(echo "${X25519Key}" | tail -n 1 | awk '{print $3}')
shortid=$(openssl rand -hex 8)
cat > ${FILE_PATH}/config.json << EOF
{
"inbounds": [
{
"port": $PORT,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "$UUID",
"flow": "xtls-rprx-vision"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"show": false,
"dest": "1.1.1.1:443",
"xver": 0,
"serverNames": [
"$SNI"
],
"privateKey": "$PrivateKey",
"minClientVer": "",
"maxClientVer": "",
"maxTimeDiff": 0,
"shortIds": [
"$shortid"
]
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"tag": "direct"
},
{
"protocol": "blackhole",
"tag": "blocked"
}
]
}
EOF
}
generate_config
# running files
run() {
if [ -e "${FILE_PATH}/npm" ]; then
tlsPorts=("443" "8443" "2096" "2087" "2083" "2053")
if [[ "${tlsPorts[*]}" =~ "${NEZHA_PORT}" ]]; then
NEZHA_TLS="--tls"
else
NEZHA_TLS=""
fi
if [ -n "$NEZHA_SERVER" ] && [ -n "$NEZHA_PORT" ] && [ -n "$NEZHA_KEY" ]; then
nohup ${FILE_PATH}/npm -s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY} ${NEZHA_TLS} >/dev/null 2>&1 &
sleep 1
ps aux | grep "[n]pm" > /dev/null && echo -e "\e[1;32mnpm is running\e[0m" || { echo -e "\e[1;35mnpm is not running, restarting...\e[0m"; pkill -x "npm"; nohup "${FILE_PATH}/npm" -s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY} ${NEZHA_TLS} >/dev/null 2>&1 & sleep 2; echo -e "\e[1;32mnpm restarted\e[0m"; }
else
echo -e "\e[1;35mNEZHA variable is empty,skiping runing\e[0m"
fi
fi
if [ -e "${FILE_PATH}/web" ]; then
nohup "${FILE_PATH}/web" -c ${FILE_PATH}/config.json >/dev/null 2>&1 &
sleep 1
ps aux | grep "[w]eb" > /dev/null && echo -e "\e[1;32mweb is running\e[0m" || { echo -e "\e[1;35mweb is not running, restarting...\e[0m"; pkill -x "web"; nohup ${FILE_PATH}/web -c ${FILE_PATH}/config.json >/dev/null 2>&1 & sleep 2; echo -e "\e[1;32mweb restarted\e[0m"; }
fi
}
run
# get ip
IP=$(curl -s ipv4.ip.sb)
# get ipinfo
ISP=$(curl -s https://speed.cloudflare.com/meta | awk -F\" '{print $26"-"$18}' | sed -e 's/ /_/g')
cat > ${FILE_PATH}/list.txt <<EOF
vless://${UUID}@${IP}:${PORT}?encryption=none&flow=xtls-rprx-vision&security=reality&sni=${SNI}&fp=chrome&pbk=${PublicKey}&sid=${shortid}&type=tcp&headerType=none#$ISP
EOF
cat ${FILE_PATH}/list.txt
echo -e "\n\e[1;32m${FILE_PATH}/list.txt saved successfully\e[0m"
echo ""
echo -e "\n\e[1;32mInstall success!\e[0m"
exit 0