From f900041f67335c22af24d57b6824e0c8204a0e1e Mon Sep 17 00:00:00 2001 From: Keith Whyte Date: Wed, 9 Sep 2020 00:52:37 +0200 Subject: [PATCH] BTS commissioning: Add script for network/interfaces Read this script before running it! --- .../rhizo_base/files/var/SysmoBTS/interfaces | 9 +++ .../rhizo_base/files/var/SysmoBTS/route.sh | 58 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 modules/rhizo_base/files/var/SysmoBTS/interfaces create mode 100644 modules/rhizo_base/files/var/SysmoBTS/route.sh diff --git a/modules/rhizo_base/files/var/SysmoBTS/interfaces b/modules/rhizo_base/files/var/SysmoBTS/interfaces new file mode 100644 index 0000000..d8c8012 --- /dev/null +++ b/modules/rhizo_base/files/var/SysmoBTS/interfaces @@ -0,0 +1,9 @@ + +auto lo +iface lo inet loopback + +auto eth0 +iface eth0 inet static + address _IP_ + netmask 255.255.255.0 + gateway 172.16.0.1 diff --git a/modules/rhizo_base/files/var/SysmoBTS/route.sh b/modules/rhizo_base/files/var/SysmoBTS/route.sh new file mode 100644 index 0000000..c3f0f7d --- /dev/null +++ b/modules/rhizo_base/files/var/SysmoBTS/route.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Script to add the default route to the networking +# configuration. + +# !!!!! WARNING !!!!! +# Be VERY careful with this one, as +# a messed up /etc/network/interfaces will lock +# you out of the unit and you'll have to physically +# connect with a serial cable. +# FIXME. Find a better way. + + +if [ "$1" != "reckless" ] ; then + echo "Do NOT run this script!" + exit 1 +fi + +SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" +. /home/rhizomatica/bin/vars.sh + + +CMD='grep -xF " gateway 172.16.0.1" /etc/network/interfaces || grep gateway\ :alpha: /etc/network/interfaces || echo " gateway 172.16.0.1" >> /etc/network/interfaces' + +for bts in "${!BTS[@]}" ; do + + awk 'BEGIN {while (x++<80) printf "-"}' ; echo + ssh $SSH_OPTS ${BTS[$bts]} "cat /etc/network/interfaces" + if [ $? != 0 ] ; then echo "Conx. Failed" ; exit ; fi + awk 'BEGIN {while (x++<80) printf "-"}' ; echo + + echo "Should we add a gateway line to the above? (y/n)" + read _ans + + if [ "$_ans" == "y" ] ; then + + ssh $SSH_OPTS ${BTS[$bts]} "$CMD" + + else + + echo "Copy interfaces file? (y/n)" + read _ans + if [ "$_ans" == "y" ] ; then + + _rfile=/tmp/interfaces-$RANDOM + cat interfaces | sed s/_IP_/${BTS[$bts]}/ > $_rfile + scp $_rfile ${BTS[$bts]}:/etc/network/interfaces + rm $_rfile + + fi + + fi + awk 'BEGIN {while (x++<80) printf "-"}' ; echo + ssh $SSH_OPTS ${BTS[$bts]} "cat /etc/network/interfaces" + awk 'BEGIN {while (x++<80) printf "-"}' ; echo + echo "If that does not look OK, fix it now manually, otherwise you might be locked out on reboot" + +done