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
+20 -20
View File
@@ -122,10 +122,10 @@ print_dead() {
parse_mac_address() {
if [ -z "${1}" ]; then
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}
else
echo Invalid MAC address \"${1}\" in ${ETHERCAT_CONFIG}
echo Invalid MAC address \""${1}"\" in ${ETHERCAT_CONFIG}
exit_fail
fi
}
@@ -156,37 +156,37 @@ start)
BACKUPS=${BACKUPS},
fi
parse_mac_address ${DEVICE}
parse_mac_address "${DEVICE}"
DEVICES=${DEVICES}${MAC}
parse_mac_address ${BACKUP}
parse_mac_address "${BACKUP}"
BACKUPS=${BACKUPS}${MAC}
MASTER_INDEX=$(expr ${MASTER_INDEX} + 1)
MASTER_INDEX=$(( "${MASTER_INDEX}" + 1))
done
# load master module
if ! ${MODPROBE} ${MODPROBE_FLAGS} ec_master ${MASTER_ARGS} \
main_devices=${DEVICES} backup_devices=${BACKUPS}; then
if ! ${MODPROBE} "${MODPROBE_FLAGS}" ec_master "${MASTER_ARGS}" \
main_devices="${DEVICES}" backup_devices="${BACKUPS}"; then
exit_fail
fi
# check for modules to replace
for MODULE in ${DEVICE_MODULES}; do
ECMODULE=ec_${MODULE}
if ! ${MODINFO} ${ECMODULE} > /dev/null; then
if ! ${MODINFO} "${ECMODULE}" > /dev/null; then
continue # ec_* module not found
fi
if [ ${MODULE} != "generic" ]; then
if [ "${MODULE}" != "generic" ]; then
if ${LSMOD} | grep "^${MODULE} " > /dev/null; then
if ! ${RMMOD} ${MODULE}; then
if ! ${RMMOD} "${MODULE}"; then
exit_fail
fi
fi
fi
if ! ${MODPROBE} ${MODPROBE_FLAGS} ${ECMODULE}; then
if [ ${MODULE} != "generic" ]; then
${MODPROBE} ${MODPROBE_FLAGS} ${MODULE} # try to restore
if ! ${MODPROBE} "${MODPROBE_FLAGS}" "${ECMODULE}"; then
if [ "${MODULE}" != "generic" ]; then
${MODPROBE} "${MODPROBE_FLAGS}" "${MODULE}" # try to restore
fi
exit_fail
fi
@@ -204,7 +204,7 @@ stop)
if ! ${LSMOD} | grep -q "^${ECMODULE} "; then
continue # ec_* module not loaded
fi
if ! ${RMMOD} ${ECMODULE}; then
if ! ${RMMOD} "${ECMODULE}"; then
exit_fail
fi;
done
@@ -213,9 +213,9 @@ stop)
# reload previous modules
for MODULE in ${DEVICE_MODULES}; do
if [ ${MODULE} != "generic" ]; then
if ! ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE}; then
echo Warning: Failed to restore ${MODULE}.
if [ "${MODULE}" != "generic" ]; then
if ! ${MODPROBE} "${MODPROBE_FLAGS}" "${MODULE}"; then
echo Warning: Failed to restore "${MODULE}".
fi
fi
done
@@ -237,16 +237,16 @@ status)
while true; do
DEVICE=$(eval echo "\${MASTER${MASTER_COUNT}_DEVICE}")
if [ -z "${DEVICE}" ]; then break; fi
MASTER_COUNT=$(expr ${MASTER_COUNT} + 1)
MASTER_COUNT=$(( "${MASTER_COUNT}" + 1))
done
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} "
# 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'
EXITCODE=$?