forked from hiddify/Hiddify-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·214 lines (176 loc) · 6.73 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
#!/bin/bash
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
.
function set_env_if_empty(){
echo "applying configs from $1========================================="
for line in $(sed 's/\#.*//g' $1 | grep '=');do
IFS=\= read k v <<< $line
# if [[ ! -z $k && -z "${!k}" ]]; then
export $k="$v"
echo $k="$v"
# fi
done
}
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() {
pushd $2;
if [[ -f $1 ]];then
echo "==========================================================="
echo "===$1 $2"
echo "==========================================================="
bash $1
fi
popd
}
function do_for_all() {
#cd /opt/$GITHUB_REPOSITORY
bash common/replace_variables.sh
runsh $1.sh common
runsh $1.sh ssl
runsh $1.sh nginx
runsh $1.sh sniproxy
runsh $1.sh xray
runsh $1.sh web
if [[ $ENABLE_TELEGRAM == true ]]; then
runsh $1.sh telegram
else
runsh uninstall.sh telegram
fi
if [[ $ENABLE_SS == true ]]; then
runsh $1.sh shadowsocks
else
runsh uninstall.sh shadowsocks
fi
if [[ $ENABLE_VMESS == true ]]; then
runsh $1.sh deprecated/vmess
else
runsh uninstall.sh deprecated/vmess
fi
if [[ $ENABLE_MONITORING == true ]]; then
runsh $1.sh deprecated/monitoring
else
runsh uninstall.sh deprecated/monitoring
fi
if [[ $ENABLE_NETDATA == true ]]; then
runsh $1.sh netdata
else
runsh uninstall.sh netdata
fi
if [[ $ENABLE_TROJAN_GO == true ]]; then
runsh $1.sh deprecated/trojan-go
else
runsh uninstall.sh deprecated/trojan-go
fi
runsh $1.sh admin_ui
}
function check_for_env() {
random_secret=$(hexdump -vn16 -e'4/4 "%08x" 1 "\n"' /dev/urandom)
replace_empty_env USER_SECRET "setting 32 char user secret" $random_secret "^([0-9A-Fa-f]{32})$"
random_path=$(tr -dc A-Za-z0-9 </dev/urandom | head -c $(shuf -i 10-32 -n 1))
replace_empty_env BASE_PROXY_PATH "setting proxy path" $random_path ".*"
random_tel_secret=$(hexdump -vn16 -e'4/4 "%08x" 1 "\n"' /dev/urandom)
replace_empty_env TELEGRAM_USER_SECRET "setting 32 char for TELEGRAM_USER_SECRET" $random_tel_secret ".*"
random_admin_secret=$(hexdump -vn16 -e'4/4 "%08x" 1 "\n"' /dev/urandom)
replace_empty_env ADMIN_SECRET "setting 32 char admin secret" $random_admin_secret "^([0-9A-Fa-f]{32})$"
export SERVER_IP=$(curl -Lso- https://api.ipify.org)
replace_empty_env MAIN_DOMAIN "please enter valid domain name to use " "$SERVER_IP.nip.io" "^([A-Za-z0-9\.]+\.[a-zA-Z]{2,})$"
# replace_empty_env CLOUD_PROVIDER "If you are using a cdn please enter the cdn domain " "" /^([a-z0-9\.]+\.[a-z]{2,})?$/i
}
function replace_empty_env() {
VAR=$1
DESCRIPTION=$2
DEFAULT=$3
REGEX=$4
if [[ -z "${!VAR}" ]]; then
echo ''
echo "============================"
echo "$DESCRIPTION"
if [[ -z "$DEFAULT" ]]; then
echo "Enter $VAR?"
else
# echo "Enter $VAR (default value='$DEFAULT' -> to confirm enter)"
echo "using '$DEFAULT' for $VAR"
fi
# read -p "> " RESPONSE
#if [[ -z "$RESPONSE" ]]; then
# RESPONSE=$DEFAULT
#fi
RESPONSE=$DEFAULT
if [[ ! -z "$REGEX" ]];then
if [[ "$RESPONSE" =~ $REGEX ]];then
sed -i "s|$1=|$1=$RESPONSE|g" config.env
cat config.env|grep -e "^$1"
if [[ "$!?" != "0" ]]; then
echo "$1=$RESPONSE">> config.env
fi
export $1=$RESPONSE
else
echo "!!!!!!!!!!!!!!!!!!!!!!"
echo "invalid response $RESPONSE -> regex= $REGEX"
echo "retry:"
replace_empty_env "$1" "$2" "$3" "$4"
fi
fi
fi
}
function main(){
check_req
set_env_if_empty config.env.default
if [ "$1" == "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
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
export ENABLE_AUTO_UPDATE=false
cd /opt/$GITHUB_REPOSITORY
git pull
if [[ "$FIRST_SETUP" == "" ]];then
replace_empty_env FIRST_SETUP "First Setup Detected!" false ".*"
export FIRST_SETUP="true"
fi
if [[ -z "$DO_NOT_RUN" || "$DO_NOT_RUN" == false ]];then
check_for_env
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
echo ""
echo ""
echo "==========================================================="
echo "Finished! Thank you for helping Iranians to skip filternet."
echo "Please open the following link in the browser for client setup"
bash status.sh
cat use-link
fi
systemctl restart hiddify-admin.service
}
mkdir -p log/system/
main $* |& tee log/system/0-install.log