-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVpnHoodServer-linux-x64.sh
159 lines (131 loc) · 3.5 KB
/
VpnHoodServer-linux-x64.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
#!/bin/bash
echo "VpnHood Server Installation for linux";
# Default arguments
packageUrl="https://github.com/vpnhood/VpnHood/releases/download/v3.0.414/VpnHoodServer-linux-x64.tar.gz";
versionTag="v3.0.413";
destinationPath="/opt/VpnHoodServer";
packageFile="";
# Read arguments
for i;
do
arg=$i;
if [ "$arg" = "-autostart" ]; then
autostart="y";
lastArg=""; continue;
elif [ "$arg" = "-q" ]; then
quiet="y";
lastArg=""; continue;
elif [ "$lastArg" = "-restBaseUrl" ]; then
restBaseUrl=$arg;
lastArg=""; continue;
elif [ "$lastArg" = "-restAuthorization" ]; then
restAuthorization=$arg;
lastArg=""; continue;
elif [ "$lastArg" = "-secret" ]; then
secret=$arg;
lastArg=""; continue;
elif [ "$lastArg" = "-packageUrl" ]; then
packageUrl=$arg;
lastArg=""; continue;
elif [ "$lastArg" = "-packageFile" ]; then
packageFile=$arg;
lastArg=""; continue;
elif [ "$lastArg" = "-versionTag" ]; then
versionTag=$arg;
lastArg=""; continue;
elif [ "$lastArg" != "" ]; then
echo "Unknown argument! argument: $lastArg";
exit 1;
fi;
lastArg=$arg;
done;
# validate $versionTag
if [ "$versionTag" == "" ]; then
echo "Could not find versionTag!";
exit 1;
fi
binDir="$destinationPath/$versionTag";
# User interaction
if [ "$quiet" != "y" ]; then
if [ "$autostart" == "" ]; then
read -p "Auto Start (y/n)?" autostart;
fi;
fi;
# point to latest version if $packageUrl is not set
if [ "$packageUrl" = "" ]; then
packageUrl="https://github.com/vpnhood/VpnHood/releases/latest/download/VpnHoodServer-linux.tar.gz";
fi
# download & install VpnHoodServer
if [ "$packageFile" = "" ]; then
echo "Downloading VpnHoodServer...";
packageFile="VpnHoodServer-linux.tar.gz";
wget -nv -O "$packageFile" "$packageUrl";
fi
# extract
echo "Extracting to $destinationPath";
mkdir -p $destinationPath;
tar -xzf "$packageFile" -C "$destinationPath"
# Updating shared files...
echo "Updating shared files...";
infoDir="$binDir/publish_info";
cp "$infoDir/vhupdate" "$destinationPath/" -f;
cp "$infoDir/vhserver" "$destinationPath/" -f;
cp "$infoDir/publish.json" "$destinationPath/" -f;
chmod +x "$binDir/VpnHoodServer";
chmod +x "$destinationPath/vhserver";
chmod +x "$destinationPath/vhupdate";
# Write AppSettingss
if [ "$restBaseUrl" != "" ]; then
appSettings="{
\"HttpAccessManager\": {
\"BaseUrl\": \"$restBaseUrl\",
\"Authorization\": \"$restAuthorization\"
},
\"Secret\": \"$secret\"
}
";
mkdir -p "$destinationPath/storage";
echo "$appSettings" > "$destinationPath/storage/appsettings.json"
fi
# init service
if [ "$autostart" = "y" ]; then
echo "creating autostart service... Name: VpnHoodServer";
service="
[Unit]
Description=VpnHood Server
After=network.target
[Service]
Type=simple
ExecStart="$binDir/VpnHoodServer"
ExecStop="$binDir/VpnHoodServer" stop
TimeoutStartSec=0
Restart=always
RestartSec=10
StandardOutput=null
[Install]
WantedBy=default.target
";
echo "$service" > "/etc/systemd/system/VpnHoodServer.service";
echo "creating VpnHood Updater service... Name: VpnHoodUpdater";
service="
[Unit]
Description=VpnHood Server Updater
After=network.target
[Service]
Type=simple
ExecStart="$destinationPath/vhupdate"
TimeoutStartSec=0
Restart=always
RestartSec=720min
[Install]
WantedBy=default.target
";
echo "$service" > "/etc/systemd/system/VpnHoodUpdater.service";
# Executing services
echo "Executing VpnHoodServer services...";
systemctl daemon-reload;
systemctl enable VpnHoodServer.service;
systemctl restart VpnHoodServer.service;
systemctl enable VpnHoodUpdater.service;
systemctl restart VpnHoodUpdater.service;
fi