forked from hiddify/Hiddify-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·298 lines (240 loc) · 10 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
cd $( dirname -- "$0"; )
echo "we are going to install :)"
export DEBIAN_FRONTEND=noninteractive
if [ "$(id -u)" -ne 0 ]; then
echo 'This script must be run by root' >&2
# exit 1
fi
source ./common/ticktick.sh
function set_config_from_hpanel(){
hiddify=`cd hiddify-panel;python3 -m hiddifypanel all-configs`
tickParse "$hiddify"
tickVars
function setenv () {
echo $1=$2
export $1="$2"
}
setenv GITHUB_USER hiddify
setenv GITHUB_REPOSITORY hiddify-config
setenv GITHUB_BRANCH_OR_TAG main
setenv TLS_PORTS ``hconfigs[tls_ports]``
setenv HTTP_PORTS ``hconfigs[http_ports]``
setenv FIRST_SETUP ``hconfigs[first_setup]``
setenv DB_VERSION ``hconfigs[db_version]``
TELEGRAM_SECRET=``hconfigs[shared_secret]``
setenv TELEGRAM_USER_SECRET ${TELEGRAM_SECRET//-/}
setenv BASE_PROXY_PATH ``hconfigs[proxy_path]``
setenv TELEGRAM_LIB ``hconfigs[telegram_lib]``
setenv ADMIN_SECRET ``hconfigs[admin_secret]``
setenv ENABLE_V2RAY ``hconfigs[v2ray_enable]``
setenv ENABLE_SS ``hconfigs[ssfaketls_enable]``
setenv SS_FAKE_TLS_DOMAIN ``hconfigs[ssfaketls_fakedomain]``
setenv DECOY_DOMAIN ``hconfigs[decoy_domain]``
setenv SHARED_SECRET ``hconfigs[shared_secret]``
setenv ENABLE_TELEGRAM ``hconfigs[telegram_enable]``
setenv TELEGRAM_FAKE_TLS_DOMAIN ``hconfigs[telegram_fakedomain]``
setenv TELEGRAM_AD_TAG ``hconfigs[telegram_adtag]``
setenv ENABLE_SHADOW_TLS ``hconfigs[shadowtls_enable]``
setenv SHADOWTLS_FAKEDOMAIN ``hconfigs[shadowtls_fakedomain]``
setenv FAKE_CDN_DOMAIN ``hconfigs[fake_cdn_domain]``
c=``hconfigs[country]``
if [[ "$c" == "" ]];then
c="ir"
fi
setenv COUNTRY $c
setenv ENABLE_SSR ``hconfigs[ssr_enable]``
setenv SSR_FAKEDOMAIN ``hconfigs[ssr_fakedomain]``
setenv ENABLE_VMESS ``hconfigs[vmess_enable]``
setenv ENABLE_MONITORING false
setenv ENABLE_FIREWALL ``hconfigs[firewall]``
setenv ENABLE_NETDATA ``hconfigs[netdata]``
setenv ENABLE_HTTP_PROXY ``hconfigs[http_proxy]`` # UNSAFE to enable, use proxy also in unencrypted 80 port
setenv ALLOW_ALL_SNI_TO_USE_PROXY ``hconfigs[allow_invalid_sni]`` #UNSAFE to enable, true=only MAIN domain is allowed to use proxy
setenv ENABLE_AUTO_UPDATE ``hconfigs[auto_update]``
setenv ENABLE_TROJAN_GO false
setenv ENABLE_SPEED_TEST ``hconfigs[speed_test]``
setenv BLOCK_IR_SITES ``hconfigs[block_iran_sites]``
setenv ONLY_IPV4 ``hconfigs[only_ipv4]``
setenv PATH_VMESS ``hconfigs[path_vmess]``
setenv PATH_VLESS ``hconfigs[path_vless]``
setenv PATH_SS ``hconfigs[path_v2ray]``
setenv PATH_TROJAN ``hconfigs[path_trojan]``
setenv PATH_TCP ``hconfigs[path_tcp]``
setenv PATH_WS ``hconfigs[path_ws]``
setenv PATH_GRPC ``hconfigs[path_grpc]``
setenv SERVER_IP `curl --connect-timeout 1 -s https://v4.ident.me/`
setenv SERVER_IPv6 `curl --connect-timeout 1 -s https://v6.ident.me/`
function get () {
group=$1
index=`printf "%012d" "$2"`
member=$3
var="__tick_data_${group}_${index}_${member}";
echo ${!var}
}
MAIN_DOMAIN=
for i in $(seq 0 ``domains.length()``); do
domain=$(get domains $i domain)
mode=$(get domains $i mode)
if [ "$mode" == "direct" ] || [ "$mode" == "cdn" ] || [ "$mode" == "relay" ] || [ "$mode" == "auto_cdn_ip" ];then
MAIN_DOMAIN="$domain;$MAIN_DOMAIN"
fi
if [ "$mode" = "ss_faketls" ];then
setenv SS_FAKE_TLS_DOMAIN $domain
fi
if [ "$mode" = "telegram_faketls" ];then
setenv TELEGRAM_FAKE_TLS_DOMAIN $domain
fi
if [ "$mode" = "fake_cdn" ];then
setenv FAKE_CDN_DOMAIN $domain
fi
done
setenv MAIN_DOMAIN $MAIN_DOMAIN
USER_SECRET=
for i in $(seq 0 ``users.length()``); do
uuid=$(get users $i uuid)
secret=${uuid//-/}
if [ "$secret" != "" ];then
USER_SECRET="$secret;$USER_SECRET"
fi
done
setenv USER_SECRET $USER_SECRET
}
function check_req(){
for req in hexdump dig curl git;do
which $req
if [[ "$?" != 0 ]];then
apt update
apt install -y dnsutils bsdmainutils curl git
break
fi
done
}
function runsh() {
command=$1
if [[ $3 == "false" ]];then
command=uninstall.sh
fi
pushd $2 >>/dev/null
# if [[ $? != 0]];then
# echo "$2 not found"
# fi
if [[ $? == 0 && -f $command ]];then
echo "==========================================================="
echo "===$command $2"
echo "==========================================================="
bash $command
fi
popd >>/dev/null
}
function do_for_all() {
#cd /opt/$GITHUB_REPOSITORY
bash common/replace_variables.sh
systemctl daemon-reload
if [ "$MODE" != "apply_users" ];then
runsh $1.sh common
#runsh $1.sh certbot
runsh $1.sh acme.sh
runsh $1.sh nginx
# runsh $1.sh sniproxy
runsh $1.sh haproxy
runsh $1.sh other/speedtest
runsh $1.sh other/telegram $ENABLE_TELEGRAM
runsh $1.sh other/ssfaketls $ENABLE_SS
runsh $1.sh other/v2ray $ENABLE_V2RAY
runsh $1.sh other/shadowtls $ENABLE_SHADOWTLS
runsh $1.sh other/clash-server $ENABLE_TUIC
# runsh $1.sh deprecated/vmess $ENABLE_VMESS
runsh uninstall.sh deprecated/vmess
# runsh $1.sh deprecated/monitoring $ENABLE_MONITORING
runsh uninstall.sh deprecated/monitoring
runsh $1.sh other/netdata false $ENABLE_NETDATA
runsh $1.sh deprecated/trojan-go $ENABLE_TROJAN_GO
fi
runsh $1.sh xray
}
function main(){
which hiddifypanel
if [[ "$?" != 0 ]];then
echo "/opt/hiddify-config/menu.sh">>~/.bashrc
echo "cd /opt/hiddify-config/">>~/.bashrc
fi
export MODE="$1"
if [ "$MODE" != "apply_users" ];then
runsh install.sh hiddify-panel
fi
# source common/set_config_from_hpanel.sh
set_config_from_hpanel
if [[ $DB_VERSION == "" ]];then
echo "ERROR!!!! There is an error in the installation of python panel. Exit...."
exit 1
fi
# check_req
# set_env_if_empty config.env.default
# set_env_if_empty config.env
# if [[ "$BASE_PROXY_PATH" == "" ]]; then
# replace_empty_env BASE_PROXY_PATH "" $USER_SECRET ".*"
# fi
# if [[ "$TELEGRAM_USER_SECRET" == "" ]]; then
# replace_empty_env TELEGRAM_USER_SECRET "" $USER_SECRET ".*"
# fi
# cd /opt/$GITHUB_REPOSITORY
# git pull
# if [[ -z "config.env $FIRST_SETUP" == "" ]];then
# replace_empty_env FIRST_SETUP "First Setup Detected!" false ".*"
# export FIRST_SETUP="true"
# fi
if [ "$MODE" == "install-docker" ];then
echo "install-docker"
export DO_NOT_RUN=true
export ENABLE_SS=true
export ENABLE_TELEGRAM=true
export ENABLE_FIREWALL=false
export ENABLE_AUTO_UPDATE=false
export ONLY_IPV4=false
fi
if [ "$MODE" == "apply_users" ];then
export DO_NOT_INSTALL=true
fi
if [[ -z "$DO_NOT_INSTALL" || "$DO_NOT_INSTALL" == false ]];then
do_for_all install
systemctl daemon-reload
fi
if [[ -z "$DO_NOT_RUN" || "$DO_NOT_RUN" == false ]];then
do_for_all run
if [ "$MODE" != "apply_users" ];then
echo ""
echo ""
bash status.sh
echo "==========================================================="
echo "Finished! Thank you for helping Iranians to skip filternet."
echo "Please open the following link in the browser for client setup"
cat use-link
fi
fi
for s in hiddify-xray hiddify-nginx haproxy;do
s=${s##*/}
s=${s%%.*}
if [[ "$(systemctl is-active $s)" != "active" ]];then
echo "an important service $s is not working yet"
sleep 5
echo "checking again..."
if [[ "$(systemctl is-active $s)" != "active" ]];then
echo "an important service $s is not working again"
echo "Installation Failed!"
exit 32
fi
fi
done
# if [[ $(/usr/local/bin/xray run -test -confdir xray/configs) ]];then
# echo "xray configuration failed "
# exit 33
# fi
echo "---------------------Finished!------------------------"
if [ "$MODE" != "apply_users" ];then
systemctl restart hiddify-panel
fi
systemctl start hiddify-panel
}
mkdir -p log/system/
main $@|& tee log/system/0-install.log