Disable default configuration in routersetup config file, use defaults in main scripts
authorMichael Prokop <mika@grml.org>
Fri, 24 May 2013 14:21:14 +0000 (16:21 +0200)
committerMichael Prokop <mika@grml.org>
Fri, 24 May 2013 14:21:14 +0000 (16:21 +0200)
This allows setting confguration settings via environment more easily.

man/grml-bridge.8
routersetup
sbin/grml-ap
sbin/grml-bridge
sbin/grml-router
sbin/grml-sniff

index f87b9ce..76ecb40 100644 (file)
@@ -12,9 +12,10 @@ command.
 Configure setup via configuration file /etc/grml/routersetup.
 To specify which DEVICES should be bridged, use BRIDGE_DEVICES, e.g.
 
-  BRIDGE_DEVICES="eth0 eth1"
+  BRIDGE_DEVICES="eth0 eth2"
 
-would bridge device eth0 and eth1. 
+would bridge device eth0 and eth2.
+If unconfigured then 'eth0 eth1' is assumed as default.
 Note: The auto interface name is not allowed here!
 
 To specify the name of the bridge, use BRIDGE_NAME, e.g.
@@ -27,7 +28,7 @@ If you want do disable Spanning Tree Protocol (STP) on your bridge, just set BRI
 
   BRIDGE_STP="no"
 
-Per default stp is on.
+Per default STP is set to 'on'.
 
 Example Configuration file:
 
index ec1756f..18cbf15 100644 (file)
@@ -7,15 +7,15 @@
 
 # configuration for grml-router:
 # IPTABLES=/sbin/iptables       # the iptables binary
-OUTDEV='auto'                   # outgoing device [auto|default|eth0|...]
+# OUTDEV='auto'                 # outgoing device [auto|default|eth0|...]
 
 # configuration for grml-bridge and grml-sniff:
 # BRCTL=/usr/sbin/brctl         # the brctl binary
-BRIDGE_NAME='br0'               # name used for the bridge
-BRIDGE_DEVICES='eth0 eth1'      # the devices used for bilding the bridge
-STP='on'                        # enable STP (Spanning-Tree Protocol)? on|off
-BRIDGE_CONFIG='DHCP'            # Use DHCP, Fixed IP or Ipless? DHCP|FIXED|NONE
-BRIDGE_IP="192.168.1.1/24"      # ip address used for bridge
+# BRIDGE_NAME='br0'             # name used for the bridge
+# BRIDGE_DEVICES='eth0 eth1'    # the devices used for bilding the bridge
+# BRIDGE_STP='on'               # enable STP (Spanning-Tree Protocol)? on|off
+# BRIDGE_CONFIG='DHCP'          # Use DHCP, Fixed IP or Ipless? DHCP|FIXED|NONE
+# BRIDGE_IP="192.168.1.1/24"    # IP address used for bridge
 
 # configuration for grml-ap:
 # AP_DEVICE='wlan0'             # device used as access point
index 1fc24b1..3c0b6d9 100755 (executable)
@@ -16,13 +16,13 @@ CONFIG_FILE=/etc/grml/routersetup
 
 check4root || exit 1
 
-if ! [ -r "$CONFIG_FILE" ] ; then
-        eerror "$CONFIG_FILE could not be read."
-        exit 1
+if [ -r "$CONFIG_FILE" ] ; then
+  . "$CONFIG_FILE"
+else
+  ewarn "Could not read $CONFIG_FILE"
 fi
 
-. "$CONFIG_FILE"
-
+# defaults if unconfigured
 [ -n "$AP_ESSID" ] || AP_ESSID=grml-ap
 [ -n "$AP_ENC" ]   || AP_ENC=off
 
index 93e6686..0cfffc5 100755 (executable)
@@ -12,21 +12,17 @@ CONFIG_FILE=/etc/grml/routersetup
 
 check4root || exit 1
 
-if ! [ -r "$CONFIG_FILE" ] ; then
-  eerror "$CONFIG_FILE could not be read."
-  exit 1
+if [ -r "$CONFIG_FILE" ] ; then
+  . "$CONFIG_FILE"
+else
+  ewarn "Could not read $CONFIG_FILE"
 fi
 
-. "$CONFIG_FILE"
-
-if [ -z "$BRIDGE_DEVICES" ] ; then
-   eerror "Bridge devices (\$BRIDGE_DEVICES) not set in $CONFIG_FILE"
-   exit 1
-fi
-
-[ -n "$BRCTL" ] || BRCTL=brctl
-[ -n "$STP"   ] || STP=on
-[ -n "$BRIDGE_NAME" ] || BRIDGE_NAME=br0
+# defaults if unconfigured
+[ -n "$BRCTL" ]          || BRCTL=brctl
+[ -n "$BRIDGE_STP"   ]   || BRIDGE_STP=on
+[ -n "$BRIDGE_NAME" ]    || BRIDGE_NAME=br0
+[ -n "$BRIDGE_DEVICES" ] || BRIDGE_DEVICES='eth0 eth1'
 
 check4progs $BRCTL || exit 1
 
@@ -41,8 +37,8 @@ case "$1" in
                 no|false)
                     ;;
                 *)
-                    einfo "Setting Spanning-Tree Protocol (STP) to status $STP"
-                    brctl stp "$BRIDGE_NAME" $STP
+                    einfo "Setting Spanning-Tree Protocol (STP) to status $BRIDGE_STP"
+                    brctl stp "$BRIDGE_NAME" "$BRIDGE_STP"
                     eend $?
                     ;;
             esac
index ec37168..cd1e19d 100755 (executable)
@@ -13,32 +13,27 @@ CONFIG_FILE=/etc/grml/routersetup
 
 check4root || exit 1
 
-if ! [ -r $CONFIG_FILE ] ; then
-  eerror "$CONFIG_FILE could not be read."
-  exit 1
+if [ -r "$CONFIG_FILE" ] ; then
+  . "$CONFIG_FILE"
+else
+  ewarn "Could not read $CONFIG_FILE"
 fi
 
-. $CONFIG_FILE
-
-if [ -z "$OUTDEV" ] ; then
-    eewarn "Outgoing device is not set in $CONFIG_FILE"
-    eewarn "Setting Outgoing device to auto"
-    OUTDEV=auto
-fi
+# defaults if unconfigured
+[ -n "$OUTDEV" ]   || OUTDEV=auto
+[ -n "$IPTABLES" ] || IPTABLES=/sbin/iptables
 
 case "$OUTDEV" in
-    auto|default)
+  auto|default)
     OUTDEV=$(defaultGWDev)
     if [ -z "$OUTDEV" ] ; then
-           eerror "The outgoing device could not be determined."
-           eerror "Please adjust OUTDEV in $CONFIG_FILE"
-           exit 1
+      eerror "The outgoing device could not be determined."
+      eerror "Please adjust OUTDEV in $CONFIG_FILE or set OUTDEV as environment variable"
+      exit 1
     fi
     ;;
 esac
 
-[ -n "$IPTABLES" ] || IPTABLES=/sbin/iptables
-
 check4progs $IPTABLES || exit 1
 
 case "$1" in
index cf41833..d854f5d 100755 (executable)
@@ -16,18 +16,13 @@ usage_info()
    einfo "Configure via $CONFIG_FILE - see man 8 grml-sniff" ; eend 0
 }
 
-if ! [ -r "$CONFIG_FILE" ] ; then
-  eerror "$CONFIG_FILE could not be read."
-  exit 1
-fi
-
-. "$CONFIG_FILE"
-
-if [ -z "$BRIDGE_DEVICES" ] ; then
-   eerror "Bridge devices (\$BRIDGE_DEVICES) not set in $CONFIG_FILE"
-   exit 1
+if [ -r "$CONFIG_FILE" ] ; then
+  . "$CONFIG_FILE"
+else
+  ewarn "Could not read $CONFIG_FILE"
 fi
 
+# defaults if unconfigured
 [ -n "$BRCTL" ]          || BRCTL='brctl'
 [ -n "$BRIDGE_NAME" ]    || BRIDGE_NAME='br0'
 [ -n "$BRIDGE_DEVICES" ] || BRIDGE_DEVICES='eth0 eth1'