mygmrs/MyGMRS_Configure.sh

105 lines
3.7 KiB
Bash
Executable File

#!/bin/bash
# Copyright 2022 Aaron Johnson ke0opk@ajserver.com based on works by Rich at MyGMRS.com (pending license information)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# End COPYRIGHT
echo -e "This script is for use with Aaron's MyGMRS OVA virtual machine image only, no other use is supported"
echo -e " use ctrl-c to exit\n"
read -p "What is your node number? " NODE
read -sp "What is your password? " PASSWORD
REG_SERVER=register.mygmrs.com
NODE_VERSION=12.18.3
DIFF=$((999999-100000+1))
RANDOM=$$
R=$(($(($RANDOM%$DIFF))+100000))
echo "RepeaterFinder Configuration Script"
echo "Node: $NODE"
cd /etc/asterisk
DATE=`date +%Y%m%d%H%M%S`
for FILE in rpt.conf extensions.conf iax.conf savenode.conf simpleusb.conf usbradio.conf
if [ -e ${FILE}.org-$0 ]
then
if [ -e ${FILE} ]
then
if [ -e ${FILE}_bak-$DATE ]
then
echo "Error: Backup file ${FILE}_bak-$DATE already exists, not handled by this script"
exit -1
fi
# Backup existing configuration file before overwritting it
mv ${FILE} ${FILE}_bak-$DATE
fi
# restore orginal config to template version
/bin/cp -f ${FILE}.org-$0 ${FILE}
else
# Org file before running this script not found, create one
/bin/cp -f ${FILE} ${FILE}.org-$0
fi
echo "Setting node number in rpt.conf..."
sed -i "s/1999/$NODE/g" rpt.conf
echo "Setting node number in extensions.conf..."
sed -i "s/1999/$NODE/" extensions.conf
echo "Setting node number in iax.conf..."
sed -i "s/; register = 1999:123456@register.allstarlink.org/register = $NODE:$PASSWORD@$REG_SERVER/" iax.conf
echo "Setting random password for iaxrpt and iaxclient accounts in iax.conf..."
sed -i "s/Your_Secret_Pasword_Here/$R/" iax.conf
sed -i "s/Your_Secret_Password_Here/$R/" iax.conf
echo "Setting node number in savenode.conf..."
sed -i "s/1999/$NODE/" savenode.conf
echo "Setting node number in simpleusb.conf..."
sed -i "s/1999/$NODE/" simpleusb.conf
echo "Setting node number in usbradio.conf..."
sed -i "s/1999/$NODE/" usbradio.conf
echo "Renaming simpleusb_tune_usb_1999.conf..."
[ -s simpleusb_tune_usb_1999.conf ] && mv simpleusb_tune_usb_1999.conf simpleusb_tune_usb_$NODE.conf
echo "Renaming usbradio_tune_usb_1999.conf..."
[ -s usbradio_tune_usb_1999.conf ] && mv usbradio_tune_usb_1999.conf usbradio_tune_usb_$NODE.conf
echo "Reloading asterisk configuration..."
service asterisk restart
echo "Running rpt-cmd..."
pm2 start /root/rpt-cmd/app.js --name "rpt-cmd-"$NODE"" -- --host nodemgr.mygmrs.com --port 443 --ssl --node $NODE
echo "Setting rpt-cmd to run at boot..."
pm2 save
pm2 startup
echo "Setting hostname..."
hostname node-$NODE
echo "node-"$NODE"" > /etc/hostname
echo "Updating hosts file..."
echo "127.0.1.1 node-"$NODE"" >> /etc/hosts
echo "Configuration complete! Restarting..."
reboot
exit 0