diverse Aenderungen an Shell-Scripten

- Klammern um if-Statements
  - == als Vergleichsoperator gibts nur in der Bash, wir haben aber nur sh (ash) verfuegbar

es ist nicht auszuschliessen, dass die Aenderungen nun andere Fehler zur Folge haben, wo vorher keine waren, da das Script doch irgendwie die "richtigen" Werte hatte.
Die bourne shell (sh) ist nicht so umfangreich wie die bourne again shell (bash).
This commit is contained in:
Oliver Voelker 2014-11-10 15:53:03 +01:00 committed by Tim Niemeyer
parent e2e67b31fc
commit 7778ce70ed
3 changed files with 22 additions and 22 deletions

View File

@ -28,13 +28,13 @@ fi
API_RETRY=$(($API_RETRY - 1)) API_RETRY=$(($API_RETRY - 1))
if [[ $API_IPV4_ADRESS != "1" ]]; then if [ "$API_IPV4_ADRESS" != "1" ]; then
netmon_api=$API_IPV4_ADRESS netmon_api=$API_IPV4_ADRESS
else else
netmon_api="[$API_IPV6_ADRESS"%"$API_IPV6_INTERFACE]" netmon_api="[$API_IPV6_ADRESS"%"$API_IPV6_INTERFACE]"
fi fi
if [ $SCRIPT_ERROR_LEVEL -gt "1" ]; then if [ "$SCRIPT_ERROR_LEVEL" -gt "1" ]; then
err() { err() {
echo "$(date) [configurator]: $1" >> $SCRIPT_LOGFILE echo "$(date) [configurator]: $1" >> $SCRIPT_LOGFILE
} }
@ -59,7 +59,7 @@ sync_hostname() {
#see http://stackoverflow.com/a/3824105 #see http://stackoverflow.com/a/3824105
regex='^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])' regex='^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])'
regex=$regex'(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$' regex=$regex'(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$'
if [ ${#netmon_hostname} -le 255 ]; then if [ "${#netmon_hostname}" -le "255" ]; then
if echo -n $netmon_hostname | egrep -q "$regex"; then if echo -n $netmon_hostname | egrep -q "$regex"; then
if [ "$netmon_hostname" != "`cat /proc/sys/kernel/hostname`" ]; then if [ "$netmon_hostname" != "`cat /proc/sys/kernel/hostname`" ]; then
err "Setting new hostname: $netmon_hostname" err "Setting new hostname: $netmon_hostname"
@ -140,7 +140,7 @@ autoadd_ipv6_address() {
err "IPv6 Autoadd has been disabled cause it is no longer necesarry" err "IPv6 Autoadd has been disabled cause it is no longer necesarry"
else else
routerid=${ergebnis##*,} routerid=${ergebnis##*,}
if [ "$routerid" == "$CRAWL_ROUTER_ID" ]; then if [ "$routerid" = "$CRAWL_ROUTER_ID" ]; then
err "The IPv6 address already exists in Netmon on this router. Maybe because of a previos assignment" err "The IPv6 address already exists in Netmon on this router. Maybe because of a previos assignment"
uci set configurator.@netmon[0].autoadd_ipv6_address='0' uci set configurator.@netmon[0].autoadd_ipv6_address='0'
uci commit uci commit
@ -151,12 +151,12 @@ autoadd_ipv6_address() {
fi fi
} }
if [ $CRAWL_METHOD == "login" ]; then if [ "$CRAWL_METHOD" = "login" ]; then
err "Authentification method is: username and passwort" err "Authentification method is: username and passwort"
elif [ $CRAWL_METHOD == "hash" ]; then elif [ "$CRAWL_METHOD" = "hash" ]; then
err "Authentification method: autoassign and hash" err "Authentification method: autoassign and hash"
err "Checking if the router is already assigned to a router in Netmon" err "Checking if the router is already assigned to a router in Netmon"
if [ $CRAWL_UPDATE_HASH == "1" ]; then if [ "$CRAWL_UPDATE_HASH" = "1" ]; then
err "The router is not assigned to a router in Netmon" err "The router is not assigned to a router in Netmon"
err "Trying to assign the router" err "Trying to assign the router"
assign_router assign_router
@ -165,10 +165,10 @@ elif [ $CRAWL_METHOD == "hash" ]; then
fi fi
fi fi
if [[ $AUTOADD_IPV6_ADDRESS = "1" ]]; then if [ "$AUTOADD_IPV6_ADDRESS" = "1" ]; then
autoadd_ipv6_address autoadd_ipv6_address
fi fi
if [[ $SCRIPT_SYNC_HOSTNAME = "1" ]]; then if [ "$SCRIPT_SYNC_HOSTNAME" = "1" ]; then
sync_hostname sync_hostname
fi fi

View File

@ -8,7 +8,7 @@ project="${VPN_PROJECT}"
test_internet_host1="mastersword.de" test_internet_host1="mastersword.de"
test_internet_host2="109.163.229.254" test_internet_host2="109.163.229.254"
if [ "$SERVER" == "no" ]; then if [ "$SERVER" = "no" ]; then
test -f /tmp/started || exit test -f /tmp/started || exit
fi fi
@ -17,14 +17,14 @@ if ping -w5 -c3 "$test_internet_host1" &>/dev/null ||
ping -w5 -c3 "$test_internet_host2" &>/dev/null || ping -w5 -c3 "$test_internet_host2" &>/dev/null ||
ping6 -w5 -c3 heise.de &>/dev/null; then ping6 -w5 -c3 heise.de &>/dev/null; then
mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null) mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null)
if [ "$SERVER" == "no" ]; then if [ "$SERVER" = "no" ]; then
hostname=$(cat /proc/sys/kernel/hostname) hostname=$(cat /proc/sys/kernel/hostname)
if [ "$hostname" == "OpenWrt" ]; then if [ "$hostname" = "OpenWrt" ]; then
hostname="" hostname=""
fi fi
if [ "$hostname" == "" ]; then if [ "$hostname" = "" ]; then
hostname=$mac hostname=$mac
fi fi
else else
@ -68,7 +68,7 @@ if ping -w5 -c3 "$test_internet_host1" &>/dev/null ||
# fire up # fire up
if [ "$(/sbin/ifconfig -a | grep -i ethernet | grep $project)" == "" ]; then if [ "$(/sbin/ifconfig -a | grep -i ethernet | grep $project)" = "" ]; then
/bin/rm /var/run/fastd.$project.pid /bin/rm /var/run/fastd.$project.pid
fastd -c /etc/fastd/$project/$project.conf -d --pid-file /var/run/fastd.$project.pid fastd -c /etc/fastd/$project/$project.conf -d --pid-file /var/run/fastd.$project.pid
fi fi

View File

@ -126,7 +126,7 @@ fsm_entry() {
scan_wlan scan_wlan
;; ;;
error) error)
if [ -n "$DEBUG" ] && [ $DEBUG -eq 1 ]; then if [ -n "$DEBUG" ] && [ "$DEBUG" -eq "1" ]; then
debug_output | gzip > ${DEBUGFILE} debug_output | gzip > ${DEBUGFILE}
fi fi
reboot reboot
@ -140,28 +140,28 @@ fsm_transition() {
local OLDSTATE=$STATE local OLDSTATE=$STATE
case $STATE in case $STATE in
working) working)
if [ $(count_neighbours) -eq 0 ] && [ $(count_clients) -eq 0 ]; then if [ "$(count_neighbours)" -eq "0" ] && [ "$(count_clients)" -eq "0" ]; then
STATE=pending STATE=pending
fi fi
;; ;;
pending) pending)
if [ $AGE -ge $TIMEOUT_MEDIUM ]; then if [ "$AGE" -ge "$TIMEOUT_MEDIUM" ]; then
STATE=error STATE=error
elif [ $(count_originators) -eq 0 ] && [ $AGE -ge $TIMEOUT_SHORT ]; then elif [ "$(count_originators)" -eq "0" ] && [ "$AGE" -ge "$TIMEOUT_SHORT" ]; then
STATE=error STATE=error
elif [ $(count_neighbours) -gt 0 ] || [ $(count_clients) -gt 0 ]; then elif [ "$(count_neighbours)" -gt "0" ] || [ "$(count_clients)" -gt "0" ]; then
STATE=working STATE=working
fi fi
;; ;;
*) *)
if [ $AGE -ge $TIMEOUT_LONG ]; then if [ "$AGE" -ge "$TIMEOUT_LONG" ]; then
STATE=error STATE=error
elif [ $(count_neighbours) -gt 0 ] || [ $(count_clients) -gt 0 ]; then elif [ "$(count_neighbours)" -gt "0" ] || [ "$(count_clients)" -gt "0" ]; then
STATE=working STATE=working
fi fi
;; ;;
esac esac
if [ ! "$OLDSTATE" == "$STATE" ]; then if [ ! "$OLDSTATE" = "$STATE" ]; then
echo "$(date) '$OLDSTATE' -> '$STATE'" echo "$(date) '$OLDSTATE' -> '$STATE'"
fsm_entry fsm_entry
fi fi