-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.sh
169 lines (133 loc) · 8.21 KB
/
Setup.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
#!/bin/bash
echo "Thanks for using this script. You need to use the ROOT account to run this script. Wait 2 seconds to continue..."
sleep 2
echo "--------------------------------------------------------------- "
echo "Please type the path that you want to install and set up sing-box in:"
echo "--------------------------------------------------------------- "
read installationpath
echo " "
echo "--------------------------------------------------------------- "
echo "Please type the domain used on this server as the proxy server name:"
echo "--------------------------------------------------------------- "
read servername
echo " "
echo "--------------------------------------------------------------- "
echo "Please type the user you want use for installation:"
echo "--------------------------------------------------------------- "
read usr
echo " "
homepath="/home/$usr"
rm -r $installationpath/Hysteria #remove the previous installation if exists
mkdir $installationpath/Hysteria
mkdir $installationpath/Hysteria/cert
certpath=$installationpath/Hysteria/cert
mkdir $installationpath/Hysteria/config
mkdir $installationpath/Hysteria/site #The site to redirect to when hysteria authentication is failed
sitepath=$installationpath/Hysteria/site
touch $installationpath/Hysteria/installation.log
# the log file that will be created to record the installation results and errors,
# btw installation.log can be manually deleted
usrtype=$(whoami)
echo $usrtype
if [ "$usrtype"==root ];
then
version=$(cat /etc/*-release | grep -oP '(?<=^ID=).+' | tr -d '"')
version_id=$(cat /etc/*-release | grep -oP '(?<=^VERSION_ID=).+' | tr -d '"')
echo $version+$version_id
#version=$(cat /proc/version)
# sed a\ $version ~/Hysteria/installation.log
echo $version+$version_id \n >> $installationpath/Hysteria/installation.log
if [ $version = "ubuntu" ] || [ $version = "debian" ];
then
apt update
apt install nginx -y
apt upgrade curl && apt install curl -y
apt upgrade iptables && apt install iptables -y
#update basic modules
bash <(curl -fsSL https://sing-box.app/deb-install.sh)
echo "sing-box core installed" >> ~/Hysteria/installation.log
#install sing-box core
wget -P $installationpath/Hysteria/config/ https://raw.githubusercontent.com/G-ORKY/Proxy-server-initiallizer/main/Hysteriaconfig.json
wget -P $installationpath/Hysteria/site/ https://raw.githubusercontent.com/G-ORKY/Proxy-server-initiallizer/main/re.html
sudo chmod +777 $installationpath/Hysteria/site/re.html
#download the configuration file and the site to redirect to when hysteria authentication is failed
echo "fetched basic web components for hysteria config and fallback site" \n >> ~/Hysteria/installation.log
$logpath=$installationpath/Hysteria/config/Hysteriaconfig.json
sed -i s/!singbox-log/$logpath/g $installationpath/Hysteria/config/Hysteriaconfig.json
#set the log path in the configuration file
echo "sing-box log path has been set" \n >> $installationpath/Hysteria/installation.log
echo "--------------------------------------------------------------- "
echo "Choose username you want to use:"
echo "--------------------------------------------------------------- "
read username
sed -i s/!usrname/$username/g $installationpath/Hysteria/config/Hysteriaconfig.json
#set the username in the configuration file
echo "--------------------------------------------------------------- "
echo "Enterthe password you want to use:"
echo "--------------------------------------------------------------- "
read password
sed -i s/!usrpassword/$password/g $installationpath/Hysteria/config/Hysteriaconfig.json
echo "User information has been set" \n >> $installationpath/Hysteria/installation.log
#set the password in the configuration file
wget -P /home/$usr -O - https://get.acme.sh | sh
. .bashrc
/root/.acme.sh/acme.sh --upgrade --auto-upgrade
#install and turn on the auto upgrade for acme.sh
echo "--------------------------------------------------------------- "
echo "Choose the option you want to use to obtain the certificate :"
echo "Option 2 will replace the privious nginx.conf file, so if you have any custom configuration, please choose option 1 or make sure that you have the backup of the nginx.conf and you need to re-add your privious config after configuration!!!"
echo "--------------------------------------------------------------- "
echo "1."I have the site privious run on this server!""
echo "2."I have the domain but it is not related to any site on this server and I AGREE to use the default site!""
read siteoption
if $siteoption=="1"
then
echo "Use the privious site to obtain a certificate"
else
rm -f /etc/nginx/nginx.conf
wget -P /etc/nginx/ "https://raw.githubusercontent.com/G-ORKY/Proxy-server-initiallizer/main/nginx.conf"
sleep 3
sed -i "s/!servername!/"$servername"/g" /etc/nginx/nginx.conf
# sed -i "s/!sitepath!/"$sitepath"/g" /etc/nginx/nginx.conf
sed -i "s|!sitepath!|"$sitepath"|g" /etc/nginx/nginx.conf
sudo systemctl reload nginx
fi
chmod +777 $sitepath
deploystate=$(/root/.acme.sh/acme.sh --issue --server letsencrypt --test -d $servername -w $sitepath --keylength ec-256)
echo $deploystate >> $installationpath/Hysteria/installation.log
testoutcome=$(cat $installationpath/Hysteria/installation.log | grep 'error')
# if [ $testoutcome=="error" ];
# then
# echo "--------------------------------------------------------------- "
# echo "Failed to obtain the certificate, please check the log file for more details."
# echo "--------------------------------------------------------------- "
# else
/root/.acme.sh/acme.sh --set-default-ca --server letsencrypt
/root/.acme.sh/acme.sh --issue -d $servername -w $sitepath --keylength ec-256 --force
/root/.acme.sh/acme.sh --installcert -d $servername --key-file /$certpath/$servername.key --fullchain-file /$certpath/$servername.crt --ecc
sudo chmod +r /$certpath/$servername.key
sed -i "s|!keypath|"$certpath"/"$servername".key|g" $installationpath/Hysteria/config/Hysteriaconfig.json
sed -i "s|!fullchainpath|"$certpath"/"$servername".crt|g" $installationpath/Hysteria/config/Hysteriaconfig.json
wget -P $certpath https://raw.githubusercontent.com/G-ORKY/Proxy-server-initiallizer/main/certrenew.sh
sed -i s#!homepath#home/$usr#g $certpath/certrenew.sh
sed -i s#!servername#$servername#g $certpath/certrenew.sh
sed -i s#!certpath#$certpath#g $certpath/certrenew.sh
sed -i s#!installationpath#$installationpath#g $certpath/certrenew.sh
sed '$a 0 1 1 * * '$usr' bash '$certpath'/certrenew.sh' /etc/crontab
sudo chmod +x $certpath/certrenew.sh
nohup sudo sing-box run -c $installationpath/Hysteria/config/Hysteriaconfig.json
sudo iptables -t nat -A PREROUTING -i eth0 -p udp --dport 3000:30000 -j DNAT --to-destination :443
echo "--------------------------------------------------------------- "
echo "Congratulations! All done! Please enter your password to start the sing-box. Feel free to use your proxy server!"
echo "--------------------------------------------------------------- "
else
echo "--------------------------------------------------------------- "
echo "This script is currently not supported on your OS, please contact us to request support for your Operating System."
echo "--------------------------------------------------------------- "
fi
else
echo "--------------------------------------------------------------- "
echo "please use the root account to run this script."
echo "btw you can use "sudo -i" and then run this script to set up."
echo "--------------------------------------------------------------- "
fi