-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-lancache.sh
278 lines (235 loc) · 12.3 KB
/
install-lancache.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
#!/bin/bash
## Set variables
lc_nginx_version=1.13.9
lc_nginx_url=http://nginx.org/download/nginx-$lc_nginx_version.tar.gz
lc_base_folder=/usr/local/lancache
lc_git=/usr/local/temp
lc_nginx_loc=/usr/local/nginx
#lc_sniproxy_bin=/usr/local/sbin/sniproxy
lc_srv_loc=/srv/lancache
lc_unbound_loc=/etc/unbound
lc_date=$( date +"%m-%d-%y %T" )
lc_hn=$( hostname )
lc_int_log=interface_used.log
lc_list_int=$( ls /sys/class/net )
lc_ip_googledns1=8.8.8.8
lc_ip_googledns2=8.8.4.4
lc_ip_logfile=ip.log
lc_ip_gw=$( /sbin/ip route | awk '/default/ { print $3 }' )
apt-get install net-tools -y
#rm old lancache files
rm /usr/local/lancache -Rvf
rm /usr/local/lancache -Rvf
#Get Lancache Files from github keep track of the location where you download the files to
git clone -b master http://github.com/bntjah/lancache "$lc_git"
mv "$lc_git" "$lc_base_folder"
## Create the necessary folders
mkdir -p $lc_base_folder/config/
mkdir -p $lc_base_folder/data/
mkdir -p $lc_base_folder/logs/
#Get Lancache Files
chown -R $USER:$USER $lc_base_folder
#--------tested so far april 2nd 2018
#Make lancache user
#Create the user lancache
adduser --system --no-create-home lancache
addgroup --system lancache
usermod -aG lancache lancache
## Autostarting nginx
cp "$lc_base_folder/init.d/nginx" /etc/init.d/nginx
chmod +x /etc/init.d/nginx
systemctl enable nginx
## Autostarting sniproxy
cp "$lc_base_folder/init.d/sniproxy" /etc/init.d/sniproxy
chmod +x /etc/init.d/sniproxy
systemctl enable sniproxy
## Divide the ip in variables
lc_ip=$( ifconfig | sed -n '2 p' | awk '{print $2}')
lc_eth_int=$( ip route get 8.8.8.8 | awk '{print $5}' )
lc_eth_netmask=$( ifconfig eth0 | grep inet | grep netmask | cut -f13 -d ' ' )
lc_ip_p1=$(echo ${lc_ip} | tr "." " " | awk '{ print $1 }')
lc_ip_p2=$(echo ${lc_ip} | tr "." " " | awk '{ print $2 }')
lc_ip_p3=$(echo ${lc_ip} | tr "." " " | awk '{ print $3 }')
lc_ip_p4=$(echo ${lc_ip} | tr "." " " | awk '{ print $4 }')
## Increment the last IP digit for every Game
lc_incr_steam=$((lc_ip_p4+1))
lc_ip_steam=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_steam
lc_incr_riot=$((lc_ip_p4+2))
lc_ip_riot=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_riot
lc_incr_blizzard=$((lc_ip_p4+3))
lc_ip_blizzard=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_blizzard
lc_incr_hirez=$((lc_ip_p4+4))
lc_ip_hirez=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_hirez
lc_incr_origin=$((lc_ip_p4+5))
lc_ip_origin=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_origin
lc_incr_sony=$((lc_ip_p4+6))
lc_ip_sony=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_sony
lc_incr_microsoft=$((lc_ip_p4+7))
lc_ip_microsoft=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_microsoft
lc_incr_enmasse=$((lc_ip_p4+8))
lc_ip_enmasse=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_enmasse
lc_incr_gog=$((lc_ip_p4+9))
lc_ip_gog=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_gog
lc_incr_arena=$((lc_ip_p4+10))
lc_ip_arena=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_arena
lc_incr_wargaming=$((lc_ip_p4+11))
lc_ip_wargaming=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_wargaming
lc_incr_uplay=$((lc_ip_p4+12))
lc_ip_uplay=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_uplay
lc_incr_apple=$((lc_ip_p4+13))
lc_ip_apple=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_apple
lc_incr_glyph=$((lc_ip_p4+14))
lc_ip_glyph=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_glyph
lc_incr_zenimax=$((lc_ip_p4+15))
lc_ip_zenimax=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_zenimax
lc_incr_digitalextremes=$((lc_ip_p4+16))
lc_ip_digitalextremes=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_digitalextremes
lc_incr_pearlabyss=$((lc_ip_p4+17))
lc_ip_pearlabyss=$lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_incr_pearlabyss
## Put IP's in the log file
echo [ lc_date ] Information !!! > $lc_base_folder/logs/$lc_ip_logfile
echo IP addresses being used: >>$lc_base_folder/logs/$lc_ip_logfile
echo >>$lc_base_folder/logs/$lc_ip_logfile
echo IP for $lc_eth_int is $lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_ip_p4 >>$lc_base_folder/logs/$lc_ip_logfile
echo Netmask for $lc_eth_int is $lc_eth_netmask >>$lc_base_folder/logs/$lc_ip_logfile
echo >>$lc_base_folder/logs/$lc_ip_logfile
echo Arena: $lc_ip_arena >>$lc_base_folder/logs/$lc_ip_logfile
echo Apple: $lc_ip_apple >>$lc_base_folder/logs/$lc_ip_logfile
echo Blizzard: $lc_ip_blizzard >>$lc_base_folder/logs/$lc_ip_logfile
echo GOG: $lc_ip_glyph >>$lc_base_folder/logs/$lc_ip_logfile
echo GOG: $lc_ip_gog >>$lc_base_folder/logs/$lc_ip_logfile
echo Hirez: $lc_ip_hirez >>$lc_base_folder/logs/$lc_ip_logfile
echo Microsoft: $lc_ip_microsoft >>$lc_base_folder/logs/$lc_ip_logfile
echo Origin: $lc_ip_origin >>$lc_base_folder/logs/$lc_ip_logfile
echo Riot: $lc_ip_riot >>$lc_base_folder/logs/$lc_ip_logfile
echo Steam: $lc_ip_steam >>$lc_base_folder/logs/$lc_ip_logfile
echo Sony: $lc_ip_sony >>$lc_base_folder/logs/$lc_ip_logfile
echo Enmasse: $lc_ip_enmasse >>$lc_base_folder/logs/$lc_ip_logfile
echo Uplay: $lc_ip_uplay >>$lc_base_folder/logs/$lc_ip_logfile
echo Wargaming: $lc_ip_wargaming >>$lc_base_folder/logs/$lc_ip_logfile
echo Zenimax: $lc_ip_zenimax >>$lc_base_folder/logs/$lc_ip_logfile
echo Digitalextremes: $lc_ip_digitalextremes >>$lc_base_folder/logs/$lc_ip_logfile
echo Pearlabyss: $lc_ip_pearlabyss >>$lc_base_folder/logs/$lc_ip_logfile
#unbound setup
## Preparing configuration for unbound
sed -i 's|lc-host-ip|'$lc_ip'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-proxybind|'$lc_ip'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-gw|'$lc_ip_gw'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-arena|'$lc_ip_arena'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-apple|'$lc_ip_apple'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-blizzard|'$lc_ip_blizzard'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-hirez|'$lc_ip_hirez'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-gog|'$lc_ip_gog'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-glyph|'$lc_ip_glyph'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-microsoft|'$lc_ip_microsoft'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-origin|'$lc_ip_origin'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-riot|'$lc_ip_riot'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-steam|'$lc_ip_steam'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-sony|'$lc_ip_sony'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-enmasse|'$lc_ip_enmasse'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-wargaming|'$lc_ip_wargaming'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-uplay|'$lc_ip_uplay'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-zenimax|'$lc_ip_zenimax'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-digitalextremes|'$lc_ip_digitalextremes'|g' $lc_base_folder/unbound/unbound.conf
sed -i 's|lc-host-pearlabyss|'$lc_ip_pearlabyss'|g' $lc_base_folder/unbound/unbound.conf
#copy config for unbound
cp $lc_base_folder/unbound/unbound.conf /etc/unbound/unbound.conf
#Replace the interfaces: section with the normal ip (not the virtual ones)
#Replace all "A records" with the appropriate IPs (the virtual IPs for the appropriate caching service like in hosts file)
## Make the Necessary Changes For The New Host File
sed -i 's|lc-hostname|'$lc_hn'|g' $lc_base_folder/hosts
sed -i 's|lc-host-proxybind|'$lc_ip'|g' $lc_base_folder/hosts
sed -i 's|lc-host-arena|'$lc_ip_arena'|g' $lc_base_folder/hosts
sed -i 's|lc-host-apple|'$lc_ip_apple'|g' $lc_base_folder/hosts
sed -i 's|lc-host-blizzard|'$lc_ip_blizzard'|g' $lc_base_folder/hosts
sed -i 's|lc-host-hirez|'$lc_ip_hirez'|g' $lc_base_folder/hosts
sed -i 's|lc-host-glyph|'$lc_ip_glyph'|g' $lc_base_folder/hosts
sed -i 's|lc-host-gog|'$lc_ip_gog'|g' $lc_base_folder/hosts
sed -i 's|lc-host-microsoft|'$lc_ip_microsoft'|g' $lc_base_folder/hosts
sed -i 's|lc-host-origin|'$lc_ip_origin'|g' $lc_base_folder/hosts
sed -i 's|lc-host-riot|'$lc_ip_riot'|g' $lc_base_folder/hosts
sed -i 's|lc-host-steam|'$lc_ip_steam'|g' $lc_base_folder/hosts
sed -i 's|lc-host-sony|'$lc_ip_sony'|g' $lc_base_folder/hosts
sed -i 's|lc-host-enmasse|'$lc_ip_enmasse'|g' $lc_base_folder/hosts
sed -i 's|lc-host-uplay|'$lc_ip_uplay'|g' $lc_base_folder/hosts
sed -i 's|lc-host-wargaming|'$lc_ip_wargaming'|g' $lc_base_folder/hosts
sed -i 's|lc-host-zenimax|'$lc_ip_zenimax'|g' $lc_base_folder/hosts
sed -i 's|lc-host-digitalextremes|'$lc_ip_digitalextremes'|g' $lc_base_folder/hosts
sed -i 's|lc-host-pearlabyss|'$lc_ip_pearlabyss'|g' $lc_base_folder/hosts
## Make the Necessary Changes For The New Interfaces File
curl https://raw.githubusercontent.com/DPCools/LancacheUbuntu18.04/master/netplan.yaml --output $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-ip|'$lc_ip'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-gateway|'$lc_ip_gw'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-arena|'$lc_ip_arena'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-apple|'$lc_ip_apple'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-blizzard|'$lc_ip_blizzard'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-hirez|'$lc_ip_hirez'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-gog|'$lc_ip_gog'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-glyph|'$lc_ip_glyph'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-microsoft|'$lc_ip_microsoft'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-origin|'$lc_ip_origin'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-riot|'$lc_ip_riot'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-steam|'$lc_ip_steam'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-sony|'$lc_ip_sony'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-enmasse|'$lc_ip_enmasse'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-uplay|'$lc_ip_uplay'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-wargaming|'$lc_ip_wargaming'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-zenimax|'$lc_ip_zenimax'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-digitalextremes|'$lc_ip_digitalextremes'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-pearlabyss|'$lc_ip_pearlabyss'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-netmask|'$lc_eth_netmask'|g' $lc_base_folder/50-cloud-init.yaml
sed -i 's|lc-host-vint|'$lc_eth_int'|g' $lc_base_folder/50-cloud-init.yaml
#Making Directorys for Data and Logs
echo making srv directorys
mkdir -p /srv/lancache/data/{microsoft,installs,other,tmp,hirez,origin,riot,gog,sony,steam,wargaming,arenanetworks,uplay,glyph,zenimax,digitalextremes,pearlabyss}
mkdir -p /srv/lancache/logs/{Errors,Keys,Access}
#Change Ownership of folders
chown -R lancache:lancache /srv/lancache
chmod -R 777 /srv/lancache
#Copy the conf folder and contents (where you originally git cloned it to in step 3) to /usr/local/nginx/conf/
cp -R $lc_base_folder/conf /usr/local/nginx/
## Change the Proxy Bind in Lancache Configs
sed -i 's|lc-host-proxybind|'$lc_ip'|g' $lc_nginx_loc/conf/vhosts-enabled/*.conf
## Moving Base Files to The Correct Locations
if [ -f "$lc_base_folder/hosts" ]; then
mv /etc/hosts /etc/hosts.bak
cp $lc_base_folder/hosts /etc/hosts
fi
if [ -f "$lc_base_folder/interfaces" ]; then
rm -f /etc/netplan/*.yaml
cp $lc_base_folder/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml
netplan generate
netplan apply
fi
# Updating local DNS resolvers
echo "nameserver $lc_ip_googledns1" > /etc/resolv.conf
echo "nameserver $lc_ip_googledns2" >> /etc/resolv.conf
#IP address for services
## Put IP's in the log file
echo "##########################################################################"
echo Main network interface information
echo IP $lc_ip_p1.$lc_ip_p2.$lc_ip_p3.$lc_ip_p4
echo Netmask$lc_eth_netmask
echo "##########################################################################"
echo IP address used for services.
echo Arena: $lc_ip_arena
echo Apple: $lc_ip_apple
echo Blizzard: $lc_ip_blizzard
echo GOG: $lc_ip_glyph
echo GOG: $lc_ip_gog
echo Hirez: $lc_ip_hirez
echo Microsoft: $lc_ip_microsoft
echo Origin: $lc_ip_origin
echo Riot: $lc_ip_riot
echo Steam: $lc_ip_steam
echo Sony: $lc_ip_sony
echo Enmasse: $lc_ip_enmasse
echo Uplay: $lc_ip_uplay
echo Wargaming: $lc_ip_wargaming
echo Zenimax: $lc_ip_zenimax
echo Digitalextremes: $lc_ip_digitalextremes
echo Pearlabyss: $lc_ip_pearlabyss
echo "##########################################################################"
echo "##########################################################################"
echo Lancache Installed pleae reboot and check services ,nginx,unbound,sniproxy
echo "##########################################################################"