olsr: init-script: minor style changes
authorBastian Bittorf <bb@npl.de>
Sun, 12 Feb 2017 19:19:16 +0000 (20:19 +0100)
committerBastian Bittorf <bb@npl.de>
Sun, 12 Feb 2017 19:19:16 +0000 (20:19 +0100)
1) echo -n -> printf
2) do not 'return 0' in functions where rc is 0 anyway
3) calc with $(( $var + $x )) -> $(( var + x ))

olsrd/files/olsrd.init

index 9018b2e380da166b2524cb5150d9769e7b5847ed..f5b866093f789b76331518852123077eff9059e9 100644 (file)
@@ -17,15 +17,15 @@ N='
 '
 
 log() {
-       logger -t olsrd -p daemon.info -s "${initscript}: $@"
+       logger -t olsrd -p daemon.info -s "${initscript}: $*"
 }
 
 error() {
-        logger -t olsrd -p daemon.err -s "${initscript}: ERROR: $@"
+        logger -t olsrd -p daemon.err -s "${initscript}: ERROR: $*"
 }
 
 warn() {
-        logger -t olsrd -p daemon.warn -s "${initscript}: WARNING: $@"
+        logger -t olsrd -p daemon.warn -s "${initscript}: WARNING: $*"
 }
 
 validate_varname() {
@@ -124,22 +124,21 @@ olsrd_write_option() {
                fi
        fi
 
-       echo -n "${N}$param$option $value"
-
-       return 0
+       printf '%s' "${N}$param$option $value"
 }
 
 olsrd_write_plparam() {
        local funcname="olsrd_write_plparam"
        local param="$1"
        local cfg="$2"
-       validate_varname "$cfg" || return 1
        local option="$3"
-       validate_varname "$option" || return 1
        local value="$4"
        local option_type="$5"
        local _option oldIFS
 
+       validate_varname "$cfg" || return 1
+       validate_varname "$option" || return 1
+
        if [ "$option_type" = bool ]; then
                case "$value" in
                        1|on|true|enabled|yes) value=yes;;
@@ -180,9 +179,7 @@ olsrd_write_plparam() {
                [ -z "$ifname" ] || value=$ifname
        fi
 
-       echo -n "${N}${param}PlParam \"$option\" \"$value\""
-
-       return 0
+       printf '%s' "${N}${param}PlParam \"$option\" \"$value\""
 }
 
 config_update_schema() {
@@ -274,7 +271,7 @@ config_write_options() {
        already_in_schema "speed" && {
                get_value_for_entry "speed"
 
-               if [ 2>/dev/null $value -gt 0 -a $value -le 20 ]; then
+               if test 2>/dev/null "$value" -gt 0 -a "$value" -le 20 ; then
                        speed="$value"
                else
                        log "$funcname() Warning: invalid speed-value: '$value' - allowed integers: 1...20, fallback to 6"
@@ -290,30 +287,30 @@ config_write_options() {
                if [ -n "$speed" ]; then                # like sven-ola freifunk firmware fff-1.7.4
                        case "$schema_entry" in
                                HelloInterval)
-                                       value="$(( $speed / 2 + 1 )).0"
+                                       value="$(( speed / 2 + 1 )).0"
                                ;;
                                HelloValidityTime)
-                                       value="$(( $speed * 25 )).0"
+                                       value="$(( speed * 25 )).0"
                                ;;
-                               TcInterval)     # todo: not fisheye? -> $(( $speed * 2 ))
-                                       value=$(( $speed / 2 ))
+                               TcInterval)     # todo: not fisheye? -> $(( speed * 2 ))
+                                       value=$(( speed / 2 ))
                                        [ $value -eq 0 ] && value=1
                                        value="$value.0"
                                ;;
                                TcValidityTime)
-                                       value="$(( $speed * 100 )).0"
+                                       value="$(( speed * 100 )).0"
                                ;;
                                MidInterval)
-                                       value="$(( $speed * 5 )).0"
+                                       value="$(( speed * 5 )).0"
                                ;;
                                MidValidityTime)
-                                       value="$(( $speed * 100 )).0"
+                                       value="$(( speed * 100 )).0"
                                ;;
                                HnaInterval)
-                                       value="$(( $speed * 2 )).0"
+                                       value="$(( speed * 2 )).0"
                                ;;
                                HnaValidityTime)
-                                       value="$(( $speed * 25 )).0"
+                                       value="$(( speed * 25 )).0"
                                ;;
                                *)
                                        get_value_for_entry "$schema_entry" || continue
@@ -413,12 +410,10 @@ olsrd_write_ipcconnect() {
 
        [ "$IPCCONNECT_COUNT" -gt 0 ] && return 0
 
-       echo -n "${N}IpcConnect${N}{"
+       printf '%s' "${N}IpcConnect${N}{"
        config_write_options "$OLSRD_IPCCONNECT_SCHEMA" "$cfg" olsrd_write_option "${T}"
        echo "${N}}"
        IPCCONNECT_COUNT=$((IPCCONNECT_COUNT + 1))
-
-       return 0
 }
 
 olsrd_write_hna4() {
@@ -441,11 +436,9 @@ olsrd_write_hna4() {
                return 0
        fi
 
-       [ "$HNA4_COUNT" -le 0 ] && echo -n "${N}Hna4${N}{"
-       echo -n "${N}${T}${T}$netaddr $netmask"
+       [ "$HNA4_COUNT" -le 0 ] && printf '%s' "${N}Hna4${N}{"
+       printf '%s' "${N}${T}${T}$netaddr $netmask"
        HNA4_COUNT=$((HNA4_COUNT + 1))
-
-       return 0
 }
 
 olsrd_write_hna6() {
@@ -468,11 +461,9 @@ olsrd_write_hna6() {
                return 0
        fi
 
-       [ "$HNA6_COUNT" -le 0 ] && echo -n "${N}Hna6${N}{"
-       echo -n "${N}${T}${T}$netaddr $prefix"
+       [ "$HNA6_COUNT" -le 0 ] && printf '%s' "${N}Hna6${N}{"
+       printf '%s' "${N}${T}${T}$netaddr $prefix"
        HNA6_COUNT=$((HNA6_COUNT + 1))
-
-       return 0
 }
 
 find_most_recent_plugin_libary()
@@ -548,7 +539,7 @@ olsrd_write_loadplugin()
                ;;
        esac
 
-       echo -n "${N}LoadPlugin \"$library\"${N}{"
+       printf '%s' "${N}LoadPlugin \"$library\"${N}{"
        config_write_options "$OLSRD_LOADPLUGIN_SCHEMA" "$cfg" olsrd_write_plparam "${T}"
        echo "${N}}"
 }
@@ -589,19 +580,17 @@ olsrd_write_interface() {
 
        [ -z "$ifnames" ] && return 0
 
-       echo -n "${N}Interface$ifnames${N}{"
+       printf '%s' "${N}Interface$ifnames${N}{"
        config_write_options "$OLSRD_INTERFACE_SCHEMA" "$cfg" olsrd_write_option "${T}"
        echo "${N}}"
        INTERFACES_COUNT=$((INTERFACES_COUNT + 1))
-
-       return 0
 }
 
 olsrd_write_interface_defaults() {
        local cfg="$1"
        validate_varname "$cfg" || return 0
 
-       echo -n "${N}InterfaceDefaults$ifnames${N}{"
+       printf '%s' "${N}InterfaceDefaults$ifnames${N}{"
        config_write_options "$OLSRD_INTERFACE_DEFAULTS_SCHEMA" "$cfg" olsrd_write_option "${T}"
        echo "${N}}"