From af7e79258099000fb08013a77e1e83680ca4a59f Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Fri, 24 May 2013 16:21:14 +0200 Subject: [PATCH] Disable default configuration in routersetup config file, use defaults in main scripts This allows setting confguration settings via environment more easily. --- man/grml-bridge.8 | 7 ++++--- routersetup | 12 ++++++------ sbin/grml-ap | 10 +++++----- sbin/grml-bridge | 26 +++++++++++--------------- sbin/grml-router | 27 +++++++++++---------------- sbin/grml-sniff | 15 +++++---------- 6 files changed, 42 insertions(+), 55 deletions(-) diff --git a/man/grml-bridge.8 b/man/grml-bridge.8 index f87b9ce..76ecb40 100644 --- a/man/grml-bridge.8 +++ b/man/grml-bridge.8 @@ -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: diff --git a/routersetup b/routersetup index ec1756f..18cbf15 100644 --- a/routersetup +++ b/routersetup @@ -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 diff --git a/sbin/grml-ap b/sbin/grml-ap index 1fc24b1..3c0b6d9 100755 --- a/sbin/grml-ap +++ b/sbin/grml-ap @@ -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 diff --git a/sbin/grml-bridge b/sbin/grml-bridge index 93e6686..0cfffc5 100755 --- a/sbin/grml-bridge +++ b/sbin/grml-bridge @@ -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 diff --git a/sbin/grml-router b/sbin/grml-router index ec37168..cd1e19d 100755 --- a/sbin/grml-router +++ b/sbin/grml-router @@ -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 diff --git a/sbin/grml-sniff b/sbin/grml-sniff index cf41833..d854f5d 100755 --- a/sbin/grml-sniff +++ b/sbin/grml-sniff @@ -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' -- 2.1.4