script: run shellcheck on bash / sh scripts

Mostly fixed omitted double quotes, some conversion of $(eval ..) to $(()).
Left the echo -n untouched, shellcheck complains about not being standard in
/bin/sh. Also, seems like some code is dublicated in ethercatctl.in and
init.d/ethercat.in.

Signed-off-by: Matthias Schoepfer <m.schoepfer@rethinkrobotics.com>
This commit is contained in:
Matthias Schoepfer 2021-07-05 14:51:16 +02:00
parent cefb37944d
commit 66329e1fe1
3 changed files with 47 additions and 47 deletions

View File

@ -49,6 +49,7 @@ if [ ! -r ${ETHERCAT_CONFIG} ]; then
exit 6 exit 6
fi fi
# shellcheck source=/etc/ethercat.conf
. ${ETHERCAT_CONFIG} . ${ETHERCAT_CONFIG}
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -56,10 +57,10 @@ fi
parse_mac_address() { parse_mac_address() {
if [ -z "${1}" ]; then if [ -z "${1}" ]; then
MAC="" MAC=""
elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then elif echo "${1}" | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
MAC=${1} MAC=${1}
else else
echo Invalid MAC address \"${1}\" in ${ETHERCAT_CONFIG} echo Invalid MAC address \""${1}"\" in ${ETHERCAT_CONFIG}
exit 1 exit 1
fi fi
} }
@ -84,18 +85,18 @@ start)
BACKUPS=${BACKUPS}, BACKUPS=${BACKUPS},
fi fi
parse_mac_address ${DEVICE} parse_mac_address "${DEVICE}"
DEVICES=${DEVICES}${MAC} DEVICES=${DEVICES}${MAC}
parse_mac_address ${BACKUP} parse_mac_address "${BACKUP}"
BACKUPS=${BACKUPS}${MAC} BACKUPS=${BACKUPS}${MAC}
MASTER_INDEX=$(expr ${MASTER_INDEX} + 1) MASTER_INDEX=$(( "${MASTER_INDEX}" + 1))
done done
# load master module # load master module
if ! ${MODPROBE} ${MODPROBE_FLAGS} ec_master \ if ! ${MODPROBE} "${MODPROBE_FLAGS}" ec_master \
main_devices=${DEVICES} backup_devices=${BACKUPS}; then main_devices="${DEVICES}" backup_devices="${BACKUPS}"; then
exit 1 exit 1
fi fi
@ -104,25 +105,25 @@ start)
# check for modules to replace # check for modules to replace
for MODULE in ${DEVICE_MODULES}; do for MODULE in ${DEVICE_MODULES}; do
ECMODULE=ec_${MODULE} ECMODULE=ec_${MODULE}
if ! ${MODINFO} ${ECMODULE} > /dev/null; then if ! ${MODINFO} "${ECMODULE}" > /dev/null; then
continue # ec_* module not found continue # ec_* module not found
fi fi
if [ ${MODULE} != "generic" -a ${MODULE} != "ccat" ]; then if [ "${MODULE}" != "generic" ] && [ "${MODULE}" != "ccat" ]; then
# try to unload standard module # try to unload standard module
if ${LSMOD} | grep "^${MODULE} " > /dev/null; then if ${LSMOD} | grep "^${MODULE} " > /dev/null; then
if ! ${RMMOD} ${MODULE}; then if ! ${RMMOD} "${MODULE}"; then
${RMMOD} ${LOADED_MODULES} ${RMMOD} ${LOADED_MODULES}
exit 1 exit 1
fi fi
fi fi
fi fi
if ! ${MODPROBE} ${MODPROBE_FLAGS} ${ECMODULE}; then if ! ${MODPROBE} "${MODPROBE_FLAGS}" "${ECMODULE}"; then
if [ ${MODULE} != "generic" -a ${MODULE} != "ccat" ]; then if [ "${MODULE}" != "generic" ] && [ "${MODULE}" != "ccat" ]; then
${MODPROBE} ${MODPROBE_FLAGS} ${MODULE} # try to restore ${MODPROBE} "${MODPROBE_FLAGS}" "${MODULE}" # try to restore
fi fi
${RMMOD} ${LOADED_MODULES} ${RMMOD} "${LOADED_MODULES}"
exit 1 exit 1
fi fi
@ -141,7 +142,7 @@ stop)
if ! ${LSMOD} | grep -q "^${ECMODULE} "; then if ! ${LSMOD} | grep -q "^${ECMODULE} "; then
continue # ec_* module not loaded continue # ec_* module not loaded
fi fi
if ! ${RMMOD} ${ECMODULE}; then if ! ${RMMOD} "${ECMODULE}"; then
exit 1 exit 1
fi; fi;
done done
@ -150,10 +151,10 @@ stop)
# load standard modules again # load standard modules again
for MODULE in ${DEVICE_MODULES}; do for MODULE in ${DEVICE_MODULES}; do
if [ ${MODULE} == "generic" -o ${MODULE} == "ccat" ]; then if [ "${MODULE}" == "generic" ] || [ "${MODULE}" == "ccat" ]; then
continue continue
fi fi
${MODPROBE} ${MODPROBE_FLAGS} ${MODULE} ${MODPROBE} "${MODPROBE_FLAGS}" "${MODULE}"
done done
exit 0 exit 0
@ -177,16 +178,16 @@ status)
while true; do while true; do
DEVICE=$(eval echo "\${MASTER${MASTER_COUNT}_DEVICE}") DEVICE=$(eval echo "\${MASTER${MASTER_COUNT}_DEVICE}")
if [ -z "${DEVICE}" ]; then break; fi if [ -z "${DEVICE}" ]; then break; fi
MASTER_COUNT=$(expr ${MASTER_COUNT} + 1) MASTER_COUNT=$(( "${MASTER_COUNT}" + 1))
done done
RESULT=0 RESULT=0
for i in `seq 0 $(expr ${MASTER_COUNT} - 1)`; do for i in $(seq 0 "$(( "${MASTER_COUNT}" - 1))"); do
echo -n "Master${i} " echo -n "Master${i} "
# Check if the master is in idle or operation phase # Check if the master is in idle or operation phase
${ETHERCAT} master --master ${i} 2>/dev/null | \ ${ETHERCAT} master --master "${i}" 2>/dev/null | \
grep -qE 'Phase:[[:space:]]*Idle|Phase:[[:space:]]*Operation' grep -qE 'Phase:[[:space:]]*Idle|Phase:[[:space:]]*Operation'
EXITCODE=$? EXITCODE=$?

View File

@ -33,7 +33,6 @@
# this ifup.d script adds special network interfaces to a network bridge # this ifup.d script adds special network interfaces to a network bridge
CFGNAME=${1}
IFNAME=${2} IFNAME=${2}
# customize here # customize here
@ -43,7 +42,7 @@ BRCTL="/sbin/brctl"
LOGGER="logger -t ifup-eoe" LOGGER="logger -t ifup-eoe"
# if the current interface in the list of interfaces to bridge? # if the current interface in the list of interfaces to bridge?
if ! echo ${INTERFACES} | grep -qw ${IFNAME}; then if ! echo "${INTERFACES}" | grep -qw "${IFNAME}"; then
exit 0; exit 0;
fi fi
@ -53,10 +52,10 @@ if ! ${BRCTL} show | grep -q "^${BRNAME}"; then
${BRCTL} addbr ${BRNAME} # create it ${BRCTL} addbr ${BRNAME} # create it
fi fi
${LOGGER} Adding ${IFNAME} to ${BRNAME} ${LOGGER} Adding "${IFNAME}" to ${BRNAME}
ip link set ${IFNAME} down ip link set "${IFNAME}" down
ip addr flush dev ${IFNAME} ip addr flush dev "${IFNAME}"
${BRCTL} addif ${BRNAME} ${IFNAME} ${BRCTL} addif ${BRNAME} "${IFNAME}"
ip link set ${IFNAME} up ip link set "${IFNAME}" up
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -122,10 +122,10 @@ print_dead() {
parse_mac_address() { parse_mac_address() {
if [ -z "${1}" ]; then if [ -z "${1}" ]; then
MAC="" MAC=""
elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then elif echo "${1}" | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
MAC=${1} MAC=${1}
else else
echo Invalid MAC address \"${1}\" in ${ETHERCAT_CONFIG} echo Invalid MAC address \""${1}"\" in ${ETHERCAT_CONFIG}
exit_fail exit_fail
fi fi
} }
@ -156,37 +156,37 @@ start)
BACKUPS=${BACKUPS}, BACKUPS=${BACKUPS},
fi fi
parse_mac_address ${DEVICE} parse_mac_address "${DEVICE}"
DEVICES=${DEVICES}${MAC} DEVICES=${DEVICES}${MAC}
parse_mac_address ${BACKUP} parse_mac_address "${BACKUP}"
BACKUPS=${BACKUPS}${MAC} BACKUPS=${BACKUPS}${MAC}
MASTER_INDEX=$(expr ${MASTER_INDEX} + 1) MASTER_INDEX=$(( "${MASTER_INDEX}" + 1))
done done
# load master module # load master module
if ! ${MODPROBE} ${MODPROBE_FLAGS} ec_master ${MASTER_ARGS} \ if ! ${MODPROBE} "${MODPROBE_FLAGS}" ec_master "${MASTER_ARGS}" \
main_devices=${DEVICES} backup_devices=${BACKUPS}; then main_devices="${DEVICES}" backup_devices="${BACKUPS}"; then
exit_fail exit_fail
fi fi
# check for modules to replace # check for modules to replace
for MODULE in ${DEVICE_MODULES}; do for MODULE in ${DEVICE_MODULES}; do
ECMODULE=ec_${MODULE} ECMODULE=ec_${MODULE}
if ! ${MODINFO} ${ECMODULE} > /dev/null; then if ! ${MODINFO} "${ECMODULE}" > /dev/null; then
continue # ec_* module not found continue # ec_* module not found
fi fi
if [ ${MODULE} != "generic" ]; then if [ "${MODULE}" != "generic" ]; then
if ${LSMOD} | grep "^${MODULE} " > /dev/null; then if ${LSMOD} | grep "^${MODULE} " > /dev/null; then
if ! ${RMMOD} ${MODULE}; then if ! ${RMMOD} "${MODULE}"; then
exit_fail exit_fail
fi fi
fi fi
fi fi
if ! ${MODPROBE} ${MODPROBE_FLAGS} ${ECMODULE}; then if ! ${MODPROBE} "${MODPROBE_FLAGS}" "${ECMODULE}"; then
if [ ${MODULE} != "generic" ]; then if [ "${MODULE}" != "generic" ]; then
${MODPROBE} ${MODPROBE_FLAGS} ${MODULE} # try to restore ${MODPROBE} "${MODPROBE_FLAGS}" "${MODULE}" # try to restore
fi fi
exit_fail exit_fail
fi fi
@ -204,7 +204,7 @@ stop)
if ! ${LSMOD} | grep -q "^${ECMODULE} "; then if ! ${LSMOD} | grep -q "^${ECMODULE} "; then
continue # ec_* module not loaded continue # ec_* module not loaded
fi fi
if ! ${RMMOD} ${ECMODULE}; then if ! ${RMMOD} "${ECMODULE}"; then
exit_fail exit_fail
fi; fi;
done done
@ -213,9 +213,9 @@ stop)
# reload previous modules # reload previous modules
for MODULE in ${DEVICE_MODULES}; do for MODULE in ${DEVICE_MODULES}; do
if [ ${MODULE} != "generic" ]; then if [ "${MODULE}" != "generic" ]; then
if ! ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE}; then if ! ${MODPROBE} "${MODPROBE_FLAGS}" "${MODULE}"; then
echo Warning: Failed to restore ${MODULE}. echo Warning: Failed to restore "${MODULE}".
fi fi
fi fi
done done
@ -237,16 +237,16 @@ status)
while true; do while true; do
DEVICE=$(eval echo "\${MASTER${MASTER_COUNT}_DEVICE}") DEVICE=$(eval echo "\${MASTER${MASTER_COUNT}_DEVICE}")
if [ -z "${DEVICE}" ]; then break; fi if [ -z "${DEVICE}" ]; then break; fi
MASTER_COUNT=$(expr ${MASTER_COUNT} + 1) MASTER_COUNT=$(( "${MASTER_COUNT}" + 1))
done done
RESULT=0 RESULT=0
for i in `seq 0 $(expr ${MASTER_COUNT} - 1)`; do for i in $(seq 0 "$(( "${MASTER_COUNT}" - 1))"); do
echo -n "Master${i} " echo -n "Master${i} "
# Check if the master is in idle or operation phase # Check if the master is in idle or operation phase
${ETHERCAT} master --master ${i} 2>/dev/null | \ ${ETHERCAT} master --master "${i}" 2>/dev/null | \
grep -qE 'Phase:[[:space:]]*Idle|Phase:[[:space:]]*Operation' grep -qE 'Phase:[[:space:]]*Idle|Phase:[[:space:]]*Operation'
EXITCODE=$? EXITCODE=$?