Browse Source

split listflash and configure-node, adding more inline help

Helge Jung 9 years ago
parent
commit
8e5a1ea181
3 changed files with 81 additions and 46 deletions
  1. 55 0
      configure-node.sh
  2. 3 0
      list.txt.example
  3. 23 46
      listflash.sh

+ 55 - 0
configure-node.sh

@@ -0,0 +1,55 @@
+#!/bin/bash
+
+function cmd()
+{
+	echo "$@" | nc -q1 192.168.1.1 23 > /dev/null
+}
+
+hostname=$1
+owner=$2
+latitude=$3
+longitude=$4
+
+[ -z "$hostname" ] && { echo "USAGE: $0 <hostname> <owner> [<latitude> <longitude>]"; exit 1; }
+[ -z "$owner" ] && { echo "ERROR: need at least hostname and owner as params"; exit 1; }
+
+if [ "$IDid" != "ReadTheScript" ]; then
+	echo "WORK IN PROGRESS: Dieses Skript ist noch nicht fertig und tut nicht was es soll."
+	echo "Die uci-set Kommandos werden scheinbar nicht ausgeführt!"
+	exit 42
+fi
+
+mac=`echo "lua -e 'print(require(\"gluon.sysconfig\").primary_mac)'" | nc -q1 192.168.1.1 23 | grep -o '^[0-9a-fA-F\:]\{17\}'`
+
+cmd 'uci set fastd.mesh_vpn.enabled=1'
+cmd 'uci set fastd.mesh_vpn.secret=$(fastd --generate-key --machine-readable)'
+cmd 'uci commit fastd'
+public_key=$(echo '/etc/init.d/fastd show_key mesh_vpn' | nc -q1 192.168.1.1 23 | grep -o "[0-9a-f]\{64\}")
+
+cmd "uci set system.@system[0].hostname=${hostname}"
+cmd "uci commit system"
+
+loc_string=""
+[ "$latitude" == "0" ] && latitude=""
+[ "$longitude" == "0" ] && longitude=""
+if [ ! -z "$latitude" -a ! -z "$longitude" ]; then
+	cmd "uci set gluon-node-info.@location[0].share_location=1"
+	cmd "uci set gluon-node-info.@location[0].latitude=$latitude"
+	cmd "uci set gluon-node-info.@location[0].longitude=$longitude"
+	loc_string="# Location: $latitude $longitude"
+else
+	cmd "uci set gluon-node-info.@location[0].share_location=0"
+fi
+cmd 'uci commit gluon-node-info'
+
+cmd 'uci set gluon-config-mode.@setup-mode[0].configured=1'
+cmd 'uci commit gluon-config-mode'
+
+cmd 'uci commit'
+#cmd "poweroff"
+
+echo "# Owner: $owner"
+echo "# MAC: $mac"
+[ ! -z "$loc_string" ] && echo $loc_string
+echo "key \"${public_key/\r/}\";"
+

+ 3 - 0
list.txt.example

@@ -0,0 +1,3 @@
+foo=8.100 52.200
+bar=
+

+ 23 - 46
listflash.sh

@@ -1,55 +1,32 @@
-#!/bin/bash
+#!/bin/sh
 
-function cmd()
-{
-	echo "$@" | nc -q1 192.168.1.1 23 > /dev/null
-}
-
-hostname=$1
+listfile=$1
 owner=$2
-latitude=$3
-longitude=$4
-
-[ -z "$hostname" ] && { echo "USAGE: $0 <hostname> <owner> [<latitude> <longitude>]"; exit 1; }
-[ -z "$owner" ] && { echo "ERROR: need at least hostname and owner as params"; exit 1; }
-
-if [ "$IDid" != "ReadTheScript" ]; then
-	echo "WORK IN PROGRESS: Dieses Skript ist noch nicht fertig und tut nicht was es soll."
-	echo "Die uci-set Kommandos werden scheinbar nicht ausgeführt!"
-	exit 42
+peersdir=$3
+if [ -z "$listfile" -o -z "$owner" -o -z "$peersdir" ]; then
+	echo "USAGE: $0 <listfile> <owner> <peers-dir>"
+	echo "<listfile> is a list containing lines of the format 'name' or 'name=lat lon'"
+	echo "<owner> is a free text which will be embedded into the peers git"
+	echo "<peersdir> is the path to the peers git's working copy"
+	exit 1
 fi
 
-mac=`echo "lua -e 'print(require(\"gluon.sysconfig\").primary_mac)'" | nc -q1 192.168.1.1 23 | grep -o '^[0-9a-fA-F\:]\{17\}'`
-
-cmd 'uci set fastd.mesh_vpn.enabled=1'
-cmd 'uci set fastd.mesh_vpn.secret=$(fastd --generate-key --machine-readable)'
-cmd 'uci commit fastd'
-public_key=$(echo '/etc/init.d/fastd show_key mesh_vpn' | nc -q1 192.168.1.1 23 | grep -o "[0-9a-f]\{64\}")
-
-cmd "uci set system.@system[0].hostname=${hostname}"
-cmd "uci commit system"
-
-loc_string=""
-[ "$latitude" == "0" ] && latitude=""
-[ "$longitude" == "0" ] && longitude=""
-if [ ! -z "$latitude" -a ! -z "$longitude" ]; then
-	cmd "uci set gluon-node-info.@location[0].share_location=1"
-	cmd "uci set gluon-node-info.@location[0].latitude=$latitude"
-	cmd "uci set gluon-node-info.@location[0].longitude=$longitude"
-	loc_string="# Location: $latitude $longitude"
-else
-	cmd "uci set gluon-node-info.@location[0].share_location=0"
+if [ ! -r "$listfile" ]; then
+	echo "The listfile is not readable (does it exist?)."
+	exit 2
 fi
-cmd 'uci commit gluon-node-info'
 
-cmd 'uci set gluon-config-mode.@setup-mode[0].configured=1'
-cmd 'uci commit gluon-config-mode'
+if [ ! -d "$peersdir" ]; then
+	echo "The peers dir does not exist."
+	exit 2
+fi
 
-cmd 'uci commit'
-#cmd "poweroff"
+cat $listfile | while read line; do
+	[ -z "$line" ] && continue
 
-echo "# Owner: $owner"
-echo "# MAC: $mac"
-[ ! -z "$loc_string" ] && echo $loc_string
-echo "key \"${public_key/\r/}\";"
+	name=`echo $line | cut -d"=" -f 1`
+	latlon=`echo $line | cut -d"=" -f 2`
+	echo "$name { $latlon }"
 
+	./configure-node.sh $name $owner $latlon > "${peersdir}/${name}"
+done