-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasl3-update-astdb
executable file
·94 lines (82 loc) · 2.19 KB
/
asl3-update-astdb
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
#!/usr/bin/bash
#
# AllStarLink astdb.txt generator
#
# Copyright (C) 2018-2024, AllStarLink, Inc.
#
# Written by:
# Jason McCormick, N8EI
#
# Adapted from a PHP version of the same name by
# Tim Sawyer WD6AWP
# with updates from WA3DSP, KK9ROB, KB4FX,
# WA3WCO, and others.
#
# See http://allstarlink.org for more information about
# this project. Please do not directly contact
# any of the maintainers of this project for assistance;
# the project provides a web site, and mailing lists
# for your use.
#
# This program is free software, distributed under the terms of
# the GNU General Public License Version 3. See the LICENSE file
# at the top of the source tree.
if [ ${EUID} -ne 0 ]; then
echo "ERROR: must run as root"
exit 1
fi
DB_HOST=allmondb.allstarlink.org
DB_URL="http://${DB_HOST}/"
USERAGENT="asl3-update-astdb/1.0"
PRIV_FILE="/etc/asterisk/privatenodes.txt"
DB_FILE="/var/lib/asterisk/astdb.txt"
function cleanup_files(){
rm -f ${TMP_FILE} ${TMP_DL}
}
function install_files(){
mv ${TMP_FILE} ${DB_FILE}
chown -R asterisk:asterisk ${DB_FILE}
chmod 644 ${DB_FILE}
for DIR in /var/log/asterisk /var/www/html/supermon /var/www/html/allscan; do
if [ -d ${DIR} ]; then
rm -f ${DIR}/astdb.txt
ln -s ${DB_FILE} ${DIR}/astdb.txt
fi
done
cleanup_files
}
# Store WIP here
TMP_FILE=$(mktemp)
# If there's a private file, process that
if [ -f ${PRIV_FILE} ]; then
cat ${PRIV_FILE} >> ${TMP_FILE}
fi
# If the variable PRIVATE_NODE is set, stop here
if [ ! -z "${PRIVATE_NODE}" ]; then
install_files
#echo "Updated ${DB_NODE} with private files only"
exit 0
fi
# Get the file from ASL
TMP_DL=$(mktemp)
wget -q -t 5 --user-agent="$USERAGENT" -O ${TMP_DL} "${DB_URL}"
RETVAL=$?
# If wget failed, stop
if [ ${RETVAL} -ne 0 ]; then
echo "ERROR: failed to download db file from ${DB_URL}"
cleanup_files
exit 1
fi
# If the file is likely junk, stop
DB_LINES=$(wc -l ${TMP_DL} | awk '{print $1}')
if [ ${DB_LINES} -lt 25 ]; then
echo "ERROR: file < 25 lines; likely garbage"
cleanup_files
exit 1
fi
# Combine and process
cat ${TMP_DL} >> ${TMP_FILE}
perl -pi -e 's/[\x00-\x09\x0B-\x0C\x0E-\x1F\x7F-\xFF]//g' ${TMP_FILE}
install_files
#echo "Updated ${DB_FILE} with new database of ${DB_LINES} lines"
exit 0