olsr: init-script: minor style changes

1) echo -n -> printf
2) do not 'return 0' in functions where rc is 0 anyway
3) calc with $(( $var + $x )) -> $(( var + x ))
This commit is contained in:
Bastian Bittorf 2017-02-12 20:19:16 +01:00
parent f4bc87dc65
commit 0e71dbfba6

View file

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