-
Notifications
You must be signed in to change notification settings - Fork 41
/
HostFilesUpdate.sh
executable file
·235 lines (215 loc) · 9.79 KB
/
HostFilesUpdate.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
#!/bin/bash
#########################################################
# #
# HostFilesUpdate.sh Updater #
# #
# Written for Pi-Star (http://www.pistar.uk/) #
# By Andy Taylor (MW0MWZ) #
# #
# Version 2.7 #
# #
# Based on the update script by Tony Corbett G0WFV #
# #
#########################################################
# Check that the network is UP and die if its not
if [ "$(expr length `hostname -I | cut -d' ' -f1`x)" == "1" ]; then
exit 0
fi
# Get the Pi-Star Version
pistarCurVersion=$(awk -F "= " '/Version/ {print $2}' /etc/pistar-release)
APRSHOSTS=/usr/local/etc/APRSHosts.txt
DCSHOSTS=/usr/local/etc/DCS_Hosts.txt
DExtraHOSTS=/usr/local/etc/DExtra_Hosts.txt
DMRIDFILE=/usr/local/etc/DMRIds.dat
DMRHOSTS=/usr/local/etc/DMR_Hosts.txt
DPlusHOSTS=/usr/local/etc/DPlus_Hosts.txt
P25HOSTS=/usr/local/etc/P25Hosts.txt
M17HOSTS=/usr/local/etc/M17Hosts.txt
YSFHOSTS=/usr/local/etc/YSFHosts.txt
FCSHOSTS=/usr/local/etc/FCSHosts.txt
XLXHOSTS=/usr/local/etc/XLXHosts.txt
NXDNIDFILE=/usr/local/etc/NXDN.csv
NXDNHOSTS=/usr/local/etc/NXDNHosts.txt
TGLISTBM=/usr/local/etc/TGList_BM.txt
TGLISTP25=/usr/local/etc/TGList_P25.txt
TGLISTNXDN=/usr/local/etc/TGList_NXDN.txt
TGLISTYSF=/usr/local/etc/TGList_YSF.txt
NEXTIONGROUPS=/usr/local/etc/nextionGroups.txt
NEXTIONUSERS=/usr/local/etc/nextionUsers.csv
# How many backups
FILEBACKUP=1
# Check we are root
if [ "$(id -u)" != "0" ];then
echo "This script must be run as root" 1>&2
exit 1
fi
# Create backup of old files
if [ ${FILEBACKUP} -ne 0 ]; then
cp ${APRSHOSTS} ${APRSHOSTS}.$(date +%Y%m%d)
cp ${DCSHOSTS} ${DCSHOSTS}.$(date +%Y%m%d)
cp ${DExtraHOSTS} ${DExtraHOSTS}.$(date +%Y%m%d)
cp ${DMRIDFILE} ${DMRIDFILE}.$(date +%Y%m%d)
cp ${DMRHOSTS} ${DMRHOSTS}.$(date +%Y%m%d)
cp ${DPlusHOSTS} ${DPlusHOSTS}.$(date +%Y%m%d)
cp ${P25HOSTS} ${P25HOSTS}.$(date +%Y%m%d)
cp ${M17HOSTS} ${M17HOSTS}.$(date +%Y%m%d)
cp ${YSFHOSTS} ${YSFHOSTS}.$(date +%Y%m%d)
cp ${FCSHOSTS} ${FCSHOSTS}.$(date +%Y%m%d)
cp ${XLXHOSTS} ${XLXHOSTS}.$(date +%Y%m%d)
cp ${NXDNIDFILE} ${NXDNIDFILE}.$(date +%Y%m%d)
cp ${NXDNHOSTS} ${NXDNHOSTS}.$(date +%Y%m%d)
cp ${TGLISTBM} ${TGLISTBM}.$(date +%Y%m%d)
cp ${TGLISTP25} ${TGLISTP25}.$(date +%Y%m%d)
cp ${TGLISTNXDN} ${TGLISTNXDN}.$(date +%Y%m%d)
cp ${TGLISTYSF} ${TGLISTYSF}.$(date +%Y%m%d)
fi
# Prune backups
FILES="${APRSHOSTS}
${DCSHOSTS}
${DExtraHOSTS}
${DMRIDFILE}
${DMRHOSTS}
${DPlusHOSTS}
${P25HOSTS}
${M17HOSTS}
${YSFHOSTS}
${FCSHOSTS}
${XLXHOSTS}
${NXDNIDFILE}
${NXDNHOSTS}
${TGLISTBM}
${TGLISTP25}
${TGLISTNXDN}
${TGLISTYSF}"
for file in ${FILES}
do
BACKUPCOUNT=$(ls ${file}.* | wc -l)
BACKUPSTODELETE=$(expr ${BACKUPCOUNT} - ${FILEBACKUP})
if [ ${BACKUPCOUNT} -gt ${FILEBACKUP} ]; then
for f in $(ls -tr ${file}.* | head -${BACKUPSTODELETE})
do
rm $f
done
fi
done
# Generate Host Files
curl --fail -o ${APRSHOSTS} -s http://www.pistar.uk/downloads/APRS_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${DCSHOSTS} -s http://www.pistar.uk/downloads/DCS_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${DMRHOSTS} -s http://www.pistar.uk/downloads/DMR_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
if [ -f /etc/hostfiles.nodextra ]; then
# Move XRFs to DPlus Protocol
curl --fail -o ${DPlusHOSTS} -s http://www.pistar.uk/downloads/DPlus_WithXRF_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${DExtraHOSTS} -s http://www.pistar.uk/downloads/DExtra_NoXRF_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
else
# Normal Operation
curl --fail -o ${DPlusHOSTS} -s http://www.pistar.uk/downloads/DPlus_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${DExtraHOSTS} -s http://www.pistar.uk/downloads/DExtra_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
fi
curl -sSL http://www.pistar.uk/downloads/DMRIds.dat.gz --user-agent "Pi-Star_${pistarCurVersion}" | gunzip -c > ${DMRIDFILE}
curl --fail -o ${P25HOSTS} -s http://www.pistar.uk/downloads/P25_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${M17HOSTS} -s http://www.pistar.uk/downloads/M17_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${YSFHOSTS} -s http://www.pistar.uk/downloads/YSF_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${FCSHOSTS} -s http://www.pistar.uk/downloads/FCS_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${XLXHOSTS} -s http://www.pistar.uk/downloads/XLXHosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${NXDNIDFILE} -s http://www.pistar.uk/downloads/NXDN.csv --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${NXDNHOSTS} -s http://www.pistar.uk/downloads/NXDN_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${TGLISTBM} -s http://www.pistar.uk/downloads/TGList_BM.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${TGLISTP25} -s http://www.pistar.uk/downloads/TGList_P25.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${TGLISTNXDN} -s http://www.pistar.uk/downloads/TGList_NXDN.txt --user-agent "Pi-Star_${pistarCurVersion}"
curl --fail -o ${TGLISTYSF} -s http://www.pistar.uk/downloads/TGList_YSF.txt --user-agent "Pi-Star_${pistarCurVersion}"
# Download Nextion Groups
if [ -f ${NEXTIONGROUPS} ]; then
# Update ${NEXTIONGROUPS}
if [[ $(find "${NEXTIONGROUPS}" -mtime +7) ]]; then
curl --fail -o ${NEXTIONGROUPS} -s http://www.pistar.uk/downloads/groups.txt --user-agent "Pi-Star_${pistarCurVersion}"
fi
else
# Get ${NEXTIONGROUPS}
curl --fail -o ${NEXTIONGROUPS} -s http://www.pistar.uk/downloads/groups.txt --user-agent "Pi-Star_${pistarCurVersion}"
fi
# Download Nextion Users
if [ -f ${NEXTIONUSERS} ]; then
if [[ $(find "${NEXTIONUSERS}" -mtime +7) ]]; then
curl -sSL http://www.pistar.uk/downloads/nextionUsers.csv.gz --user-agent "Pi-Star_${pistarCurVersion}" | gunzip -c > ${NEXTIONUSERS}
fi
else
curl -sSL http://www.pistar.uk/downloads/nextionUsers.csv.gz --user-agent "Pi-Star_${pistarCurVersion}" | gunzip -c > ${NEXTIONUSERS}
fi
# If there is a DMR Over-ride file, add it's contents to DMR_Hosts.txt
if [ -f "/root/DMR_Hosts.txt" ]; then
cat /root/DMR_Hosts.txt >> ${DMRHOSTS}
fi
# Add custom YSF Hosts
if [ -f "/root/YSFHosts.txt" ]; then
cat /root/YSFHosts.txt >> ${YSFHOSTS}
fi
# Fix DMRGateway issues with brackets
if [ -f "/etc/dmrgateway" ]; then
sed -i '/Name=.*(/d' /etc/dmrgateway
sed -i '/Name=.*)/d' /etc/dmrgateway
fi
# Add some fixes for P25Gateway
if [[ $(/usr/local/bin/P25Gateway --version | awk '{print $3}' | cut -c -8) -gt "20180108" ]]; then
sed -i 's/Hosts=\/usr\/local\/etc\/P25Hosts.txt/HostsFile1=\/usr\/local\/etc\/P25Hosts.txt\nHostsFile2=\/usr\/local\/etc\/P25HostsLocal.txt/g' /etc/p25gateway
sed -i 's/HostsFile2=\/root\/P25Hosts.txt/HostsFile2=\/usr\/local\/etc\/P25HostsLocal.txt/g' /etc/p25gateway
fi
if [ -f "/root/P25Hosts.txt" ]; then
cat /root/P25Hosts.txt > /usr/local/etc/P25HostsLocal.txt
fi
# Add local over-ride for M17Hosts
if [ -f "/root/M17Hosts.txt" ]; then
cat /root/M17Hosts.txt >> ${M17HOSTS}
fi
# Fix up new NXDNGateway Config Hostfile setup
if [[ $(/usr/local/bin/NXDNGateway --version | awk '{print $3}' | cut -c -8) -gt "20180801" ]]; then
sed -i 's/HostsFile=\/usr\/local\/etc\/NXDNHosts.txt/HostsFile1=\/usr\/local\/etc\/NXDNHosts.txt\nHostsFile2=\/usr\/local\/etc\/NXDNHostsLocal.txt/g' /etc/nxdngateway
fi
if [ ! -f "/root/NXDNHosts.txt" ]; then
touch /root/NXDNHosts.txt
fi
if [ ! -f "/usr/local/etc/NXDNHostsLocal.txt" ]; then
touch /usr/local/etc/NXDNHostsLocal.txt
fi
# Add custom NXDN Hosts
if [ -f "/root/NXDNHosts.txt" ]; then
cat /root/NXDNHosts.txt > /usr/local/etc/NXDNHostsLocal.txt
fi
# If there is an XLX over-ride
if [ -f "/root/XLXHosts.txt" ]; then
while IFS= read -r line; do
if [[ $line != \#* ]] && [[ $line = *";"* ]]
then
xlxid=`echo $line | awk -F ";" '{print $1}'`
xlxip=`echo $line | awk -F ";" '{print $2}'`
#xlxip=`grep "^${xlxid}" /usr/local/etc/XLXHosts.txt | awk -F ";" '{print $2}'`
xlxroom=`echo $line | awk -F ";" '{print $3}'`
xlxNewLine="${xlxid};${xlxip};${xlxroom}"
/bin/sed -i "/^$xlxid\;/c\\$xlxNewLine" /usr/local/etc/XLXHosts.txt
fi
done < /root/XLXHosts.txt
fi
# Yaesu FT-70D radios only do upper case
if [ -f "/etc/hostfiles.ysfupper" ]; then
sed -i 's/\(.*\)/\U\1/' ${YSFHOSTS}
sed -i 's/\(.*\)/\U\1/' ${FCSHOSTS}
fi
# Fix up ircDDBGateway Host Files on v4
if [ -d "/usr/local/etc/ircddbgateway" ]; then
if [[ -f "/usr/local/etc/ircddbgateway/DCS_Hosts.txt" && ! -L "/usr/local/etc/ircddbgateway/DCS_Hosts.txt" ]]; then
rm -rf /usr/local/etc/ircddbgateway/DCS_Hosts.txt
ln -s /usr/local/etc/DCS_Hosts.txt /usr/local/etc/ircddbgateway/DCS_Hosts.txt
fi
if [[ -f "/usr/local/etc/ircddbgateway/DExtra_Hosts.txt" && ! -L "/usr/local/etc/ircddbgateway/DExtra_Hosts.txt" ]]; then
rm -rf /usr/local/etc/ircddbgateway/DExtra_Hosts.txt
ln -s /usr/local/etc/DExtra_Hosts.txt /usr/local/etc/ircddbgateway/DExtra_Hosts.txt
fi
if [[ -f "/usr/local/etc/ircddbgateway/DPlus_Hosts.txt" && ! -L "/usr/local/etc/ircddbgateway/DPlus_Hosts.txt" ]]; then
rm -rf /usr/local/etc/ircddbgateway/DPlus_Hosts.txt
ln -s /usr/local/etc/DPlus_Hosts.txt /usr/local/etc/ircddbgateway/DPlus_Hosts.txt
fi
if [[ -f "/usr/local/etc/ircddbgateway/CCS_Hosts.txt" && ! -L "/usr/local/etc/ircddbgateway/CCS_Hosts.txt" ]]; then
rm -rf /usr/local/etc/ircddbgateway/CCS_Hosts.txt
ln -s /usr/local/etc/CCS_Hosts.txt /usr/local/etc/ircddbgateway/CCS_Hosts.txt
fi
fi
exit 0