This commit is contained in:
Esteban Mackay Q 2023-09-03 22:35:43 -05:00
parent 06bfc17e90
commit 7935e67eb8
4 changed files with 87 additions and 210 deletions

View File

@ -625,231 +625,108 @@ EOF
#
#####################################################################################################################
cat > /opt/data-file.sh <<- "EOFXC"
#!/bin/bash
#########################################################
# #
# HostFilesUpdate.sh Updater #
# #
# Written for Pi-Star (http://www.pistar.uk/) #
# By Andy Taylor (MW0MWZ) #
# #
# Version 2.6 #
# #
# Based on the update script by Tony Corbett G0WFV #
# #
#########################################################
cat > /opt/data-mmdvm.py <<- "EOFXC"
import os
import subprocess
# 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=/opt/data-files/APRSHosts.txt
DCSHOSTS=/opt/data-files/DCS_Hosts.txt
DExtraHOSTS=/opt/data-files/DExtra_Hosts.txt
DMRIDFILE=/opt/data-files/DMRIds.dat
DMRHOSTS=/opt/data-files/DMR_Hosts.txt
DPlusHOSTS=/opt/data-files/DPlus_Hosts.txt
P25HOSTS=/opt/data-files/P25Hosts.txt
M17HOSTS=/opt/data-files/M17Hosts.txt
YSFHOSTS=/opt/data-files/YSFHosts.txt
FCSHOSTS=/opt/data-files/FCSHosts.txt
XLXHOSTS=/opt/data-files/XLXHosts.txt
NXDNIDFILE=/opt/data-files/NXDN.csv
NXDNHOSTS=/opt/data-files/NXDNHosts.txt
TGLISTBM=/opt/data-files/TGList_BM.txt
TGLISTDMR=/opt/data-files/TGList-DMR.txt
TGLISTP25=/opt/data-files/TGList_P25.txt
TGLISTNXDN=/opt/data-files/TGList_NXDN.txt
TGLISTYSF=/opt/data-files/TGList_YSF.txt
APRSHOSTS = "/opt/data-files/APRSHosts.txt"
DCSHOSTS = "/opt/data-files/DCS_Hosts.txt"
DExtraHOSTS = "/opt/data-files/DExtra_Hosts.txt"
DMRIDFILE = "/opt/data-files/DMRIds.dat"
DMRHOSTS = "/opt/data-files/DMR_Hosts.txt"
DPlusHOSTS = "/opt/data-files/DPlus_Hosts.txt"
P25HOSTS = "/opt/data-files/P25Hosts.txt"
M17HOSTS = "/opt/data-files/M17Hosts.txt"
YSFHOSTS = "/opt/data-files/YSFHosts.txt"
FCSHOSTS = "/opt/data-files/FCSHosts.txt"
XLXHOSTS = "/opt/data-files/XLXHosts.txt"
NXDNIDFILE = "/opt/data-files/NXDN.csv"
NXDNHOSTS = "/opt/data-files/NXDNHosts.txt"
TGLISTBM = "/opt/data-files/TGList_BM.txt"
TGLISTDMR = "/opt/data-files/TGList-DMR.txt"
TGLISTP25 = "/opt/data-files/TGList_P25.txt"
TGLISTNXDN = "/opt/data-files/TGList_NXDN.txt"
TGLISTYSF = "/opt/data-files/TGList_YSF.txt"
# How many backups
FILEBACKUP=1
FILEBACKUP = 1
# Check we are root
if [ "$(id -u)" != "0" ];then
echo "This script must be run as root" 1>&2
exit 1
fi
# Check if the script is running as root
if os.geteuid() != 0:
print("This script must be run as root")
exit(1)
# 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 ${TGLISTDMR} ${TGLISTDMR}.$(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
if FILEBACKUP != 0:
files_to_backup = [
APRSHOSTS, DCSHOSTS, DExtraHOSTS, DMRIDFILE, DMRHOSTS,
DPlusHOSTS, P25HOSTS, M17HOSTS, YSFHOSTS, FCSHOSTS,
XLXHOSTS, NXDNIDFILE, NXDNHOSTS, TGLISTBM, TGLISTDMR,
TGLISTP25, TGLISTNXDN, TGLISTYSF
]
for file in files_to_backup:
backup_filename = f"{file}.{subprocess.check_output(['date', '+%Y%m%d']).decode().strip()}"
subprocess.run(['cp', file, backup_filename])
# Prune backups
FILES="${APRSHOSTS}
${DCSHOSTS}
${DExtraHOSTS}
${DMRIDFILE}
${DMRHOSTS}
${DPlusHOSTS}
${P25HOSTS}
${M17HOSTS}
${YSFHOSTS}
${FCSHOSTS}
${XLXHOSTS}
${NXDNIDFILE}
${NXDNHOSTS}
${TGLISTBM}
${TGLISTDNR}
${TGLISTP25}
${TGLISTNXDN}
${TGLISTYSF}"
for file in files_to_backup:
backup_count = len([f for f in os.listdir() if f.startswith(f"{file}.")])
backups_to_delete = backup_count - FILEBACKUP
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
if backup_count > FILEBACKUP:
for backup_file in sorted(os.listdir(), key=lambda f: os.path.getctime(f)):
if backup_file.startswith(f"{file}.") and backups_to_delete > 0:
os.remove(backup_file)
backups_to_delete -= 1
# 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 --fail -o ${DMRIDFILE} -s http://www.pistar.uk/downloads/DMRIds.dat --user-agent "Pi-Star_${pistarCurVersion}"
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 -s http://www.pistar.uk/downloads/USTrust_Hosts.txt --user-agent "Pi-Star_${pistarCurVersion}" >> ${DExtraHOSTS}
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 ${TGLISTDMR} -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}"
files_to_generate = [
(APRSHOSTS, "http://www.pistar.uk/downloads/APRS_Hosts.txt"),
(DCSHOSTS, "http://www.pistar.uk/downloads/DCS_Hosts.txt"),
(DMRHOSTS, "http://www.pistar.uk/downloads/DMR_Hosts.txt"),
(DPlusHOSTS, "http://www.pistar.uk/downloads/DPlus_Hosts.txt"),
(DExtraHOSTS, "http://www.pistar.uk/downloads/DExtra_Hosts.txt"),
(DMRIDFILE, "http://www.pistar.uk/downloads/DMRIds.dat"),
(P25HOSTS, "http://www.pistar.uk/downloads/P25_Hosts.txt"),
(M17HOSTS, "http://www.pistar.uk/downloads/M17_Hosts.txt"),
(YSFHOSTS, "http://www.pistar.uk/downloads/YSF_Hosts.txt"),
(FCSHOSTS, "http://www.pistar.uk/downloads/FCS_Hosts.txt"),
(XLXHOSTS, "http://www.pistar.uk/downloads/XLXHosts.txt"),
(NXDNIDFILE, "http://www.pistar.uk/downloads/NXDN.csv"),
(NXDNHOSTS, "http://www.pistar.uk/downloads/NXDN_Hosts.txt"),
(TGLISTBM, "http://www.pistar.uk/downloads/TGList_BM.txt"),
(TGLISTDMR, "http://www.pistar.uk/downloads/TGList_BM.txt"),
(TGLISTP25, "http://www.pistar.uk/downloads/TGList_P25.txt"),
(TGLISTNXDN, "http://www.pistar.uk/downloads/TGList_NXDN.txt"),
(TGLISTYSF, "http://www.pistar.uk/downloads/TGList_YSF.txt")
]
# 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 [ -f "/root/P25Hosts.txt" ]; then
cat /root/P25Hosts.txt > /opt/data-files/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 [ ! -f "/root/NXDNHosts.txt" ]; then
touch /root/NXDNHosts.txt
fi
if [ ! -f "/opt/data-files/NXDNHostsLocal.txt" ]; then
touch /opt/data-files/NXDNHostsLocal.txt
fi
# Add custom NXDN Hosts
if [ -f "/root/NXDNHosts.txt" ]; then
cat /root/NXDNHosts.txt > /opt/data-files/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}" /opt/data-files/XLXHosts.txt | awk -F ";" '{print $2}'`
xlxroom=`echo $line | awk -F ";" '{print $3}'`
xlxNewLine="${xlxid};${xlxip};${xlxroom}"
/bin/sed -i "/^$xlxid\;/c\\$xlxNewLine" /opt/data-files/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
for dest_file, source_url in files_to_generate:
subprocess.run(['curl', '--fail', '-o', dest_file, '-s', source_url])
# Fix up ircDDBGateway Host Files on v4
if [ -d "/opt/data-files/ircddbgateway" ]; then
if [[ -f "/opt/data-files/ircddbgateway/DCS_Hosts.txt" && ! -L "/opt/data-files/ircddbgateway/DCS_Hosts.txt" ]]; then
rm -rf /opt/data-files/ircddbgateway/DCS_Hosts.txt
ln -s /opt/data-files/DCS_Hosts.txt /opt/data-files/ircddbgateway/DCS_Hosts.txt
fi
if [[ -f "/opt/data-files/ircddbgateway/DExtra_Hosts.txt" && ! -L "/opt/data-files/ircddbgateway/DExtra_Hosts.txt" ]]; then
rm -rf /opt/data-files/ircddbgateway/DExtra_Hosts.txt
ln -s /opt/data-files/DExtra_Hosts.txt /opt/data-files/ircddbgateway/DExtra_Hosts.txt
fi
if [[ -f "/opt/data-files/ircddbgateway/DPlus_Hosts.txt" && ! -L "/opt/data-files/ircddbgateway/DPlus_Hosts.txt" ]]; then
rm -rf /opt/data-files/ircddbgateway/DPlus_Hosts.txt
ln -s /opt/data-files/DPlus_Hosts.txt /opt/data-files/ircddbgateway/DPlus_Hosts.txt
fi
if [[ -f "/opt/data-files/ircddbgateway/CCS_Hosts.txt" && ! -L "/opt/data-files/ircddbgateway/CCS_Hosts.txt" ]]; then
rm -rf /opt/data-files/ircddbgateway/CCS_Hosts.txt
ln -s /opt/data-files/CCS_Hosts.txt /opt/data-files/ircddbgateway/CCS_Hosts.txt
fi
fi
if os.path.exists("/opt/data-files/ircddbgateway"):
ircddbgateway_files = [
("DCS_Hosts.txt", DCSHOSTS),
("DExtra_Hosts.txt", DExtraHOSTS),
("DPlus_Hosts.txt", DPlusHOSTS),
("CCS_Hosts.txt", "/opt/data-files/CCS_Hosts.txt"),
]
exit 0
for ircddbgateway_file, symlink_target in ircddbgateway_files:
ircddbgateway_path = f"/opt/data-files/ircddbgateway/{ircddbgateway_file}"
if os.path.exists(ircddbgateway_path) and not os.path.islink(ircddbgateway_path):
os.remove(ircddbgateway_path)
os.symlink(symlink_target, ircddbgateway_path)
exit(0)
EOFXC
###
chmod +x /opt/data-file.sh
mkdir /opt/data-files
chmod 777 /opt/data-files
sh /opt/data-file.sh
python3 /opt/data-mmdvm.py
###############################################################################################################################

View File

@ -48,7 +48,7 @@ sudo nano /opt/YSFGateway2/YSFGateway.ini;;
4)
sudo nano /opt/YSF2DMRGW/YSF2DMR.ini;;
5)
sh /opt/data-file.sh && cronedit.sh '* */24 * * *' 'sh /opt/data-file.sh' add
python3 /opt/data-mmdvm.py && cronedit.sh '* */24 * * *' 'python3 /opt/data-mmdvm.py' add
sudo systemctl stop mmdvmh.service
if cat /opt/MMDVMHost/MMDVM.ini | grep ServiceStart=0 >/dev/null 2>&1
then
@ -92,7 +92,7 @@ fi
6)
if systemctl status ysf2dmr.service | grep disable >/dev/null 2>&1
then
cronedit.sh '* */24 * * *' 'sh /opt/data-file.sh' remove
cronedit.sh '* */24 * * *' 'python3 /opt/data-mmdvm.py' remove
fi
sudo systemctl stop mmdvmh.service && sudo systemctl disable mmdvmh.service && systemctl stop ysf2dmrgw.service && sudo systemctl stop dmrgw.service ;;
7)

View File

@ -20,7 +20,7 @@ case $choix in
1)
sudo nano /opt/NXDN2DMR/NXDN2DMR.ini;;
2)
sh /opt/data-file.sh && (crontab -l; echo "* */24 * * * sh /opt/data-file.sh")|awk '!x[$0]++'|crontab - &&
python3 /opt/data-mmdvm.py && (crontab -l; echo "* */24 * * * python3 /opt/data-mmdvm.py")|awk '!x[$0]++'|crontab - &&
if systemctl status nxdn2dmr.service |grep active >/dev/null 2>&1
then sudo systemctl stop nxdn2dmr.service
@ -33,7 +33,7 @@ sudo systemctl start nxdn2dmr.service ;;
3)
if systemctl status mmdvmh.service | grep disable >/dev/null 2>&1
then
(crontab -l | grep -v "sh /opt/data-file.sh") | crontab -
(crontab -l | grep -v "python3 /opt/data-mmdvm.py") | crontab -
fi
sudo systemctl stop nxdn2dmr.service && sudo systemctl disable nxdn2dmr.service ;;
4)

View File

@ -20,7 +20,7 @@ case $choix in
1)
sudo nano /opt/YSF2DMR/YSF2DMR.ini;;
2)
sh /opt/data-file.sh && (crontab -l; echo "* */24 * * * sh /opt/data-file.sh")|awk '!x[$0]++'|crontab - &&
python3 /opt/data-mmdvm.py && (crontab -l; echo "* */24 * * * python3 /opt/data-mmdvm.py")|awk '!x[$0]++'|crontab - &&
if systemctl status ysf2dmr.service |grep active >/dev/null 2>&1
then sudo systemctl stop ysf2dmr.service
@ -33,7 +33,7 @@ sudo systemctl start ysf2dmr.service ;;
3)
if systemctl status mmdvmh.service | grep disable >/dev/null 2>&1
then
(crontab -l | grep -v "sh /opt/data-file.sh") | crontab -
(crontab -l | grep -v "python3 /opt/data-mmdvm.py") | crontab -
fi
sudo systemctl stop ysf2dmr.service && sudo systemctl disable ysf2dmr.service ;;
4)