Browse Source

Tools: add run-shellcheck.sh to statically analyze startup scripts

Use './Tools/run-shellcheck.sh ROMFS/px4fmu_common' to run it.
sbg
Beat Küng 7 years ago committed by Daniel Agar
parent
commit
4e860e357c
  1. 1
      ROMFS/px4fmu_common/init.d-posix/1010_iris_opt_flow.post
  2. 2
      ROMFS/px4fmu_common/init.d-posix/6011_typhoon_h480.post
  3. 16
      ROMFS/px4fmu_common/init.d-posix/rcS
  4. 41
      Tools/run-shellcheck.sh

1
ROMFS/px4fmu_common/init.d-posix/1010_iris_opt_flow.post

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
# shellcheck disable=SC2154
mavlink stream -r 10 -s DISTANCE_SENSOR -u $udp_gcs_port_local
mavlink stream -r 10 -s VISION_POSITION_ESTIMATE -u $udp_gcs_port_local

2
ROMFS/px4fmu_common/init.d-posix/6011_typhoon_h480.post

@ -3,6 +3,8 @@ mixer append /dev/pwm_output0 etc/mixers/mount_legs.aux.mix @@ -3,6 +3,8 @@ mixer append /dev/pwm_output0 etc/mixers/mount_legs.aux.mix
mavlink start -x -u 14558 -r 4000 -f -m onboard -o 14530
# shellcheck disable=SC2154
mavlink stream -r 10 -s MOUNT_ORIENTATION -u $udp_gcs_port_local
# shellcheck disable=SC2154
mavlink stream -r 50 -s ATTITUDE_QUATERNION -u $udp_offboard_port_local
mavlink stream -r 10 -s MOUNT_ORIENTATION -u $udp_offboard_port_local

16
ROMFS/px4fmu_common/init.d-posix/rcS

@ -2,13 +2,17 @@ @@ -2,13 +2,17 @@
# PX4 commands need the 'px4-' prefix in bash.
# (px4-alias.sh is expected to be in the PATH)
# shellcheck disable=SC1091
source px4-alias.sh
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#
# Main SITL startup script
#
# check for ekf2 replay
# shellcheck disable=SC2154
if [ "$replay_mode" == "ekf2" ]
then
sh etc/init.d-posix/rc.replay
@ -96,11 +100,12 @@ else @@ -96,11 +100,12 @@ else
fi
# multi-instance setup
param set MAV_SYS_ID $((1+$px4_instance))
simulator_udp_port=$((14560+$px4_instance))
udp_offboard_port_local=$((14557+$px4_instance))
udp_offboard_port_remote=$((14540+$px4_instance))
udp_gcs_port_local=$((14556+$px4_instance))
# shellcheck disable=SC2154
param set MAV_SYS_ID $((1+px4_instance))
simulator_udp_port=$((14560+px4_instance))
udp_offboard_port_local=$((14557+px4_instance))
udp_offboard_port_remote=$((14540+px4_instance))
udp_gcs_port_local=$((14556+px4_instance))
if [ $AUTOCNF == yes ]
then
@ -163,6 +168,7 @@ fi @@ -163,6 +168,7 @@ fi
# Autostart ID
autostart_file_match="etc/init.d-posix/$(param show -q SYS_AUTOSTART)_*"
# shellcheck disable=SC2206
autostart_files=( $autostart_file_match )
autostart_file="${autostart_files[0]}" # use first match, but there should really only be one
if [ ! -e "$autostart_file" ]; then

41
Tools/run-shellcheck.sh

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
#!/bin/bash
# Script to run ShellCheck (a static analysis tool for shell scripts) over a
# script directory
if [ -z "$1" ]; then
echo "usage: $0 <directory>"
echo ""
echo " <directory> Directory to search for scripts"
exit -1
fi
search_directory="$1"
command -v shellcheck >/dev/null 2>&1 || { echo -e >&2 \
"Error: shellcheck required but it's not installed. On Ubuntu use:\n sudo apt-get install shellcheck\n\nAborting."; exit 1; }
scripts="$(find "$search_directory" -type f ! -name '*.txt' ! -name '*.mix')"
echo "Running shellcheck in '$search_directory'."
# Disabled rules:
# SC2121: allow 'set' as assignment (NuttX-style)
# SC1008: unrecognized shebang
# SC2086: double quote to prevent globbing and word splitting
# SC2166: allow the form [ $OUTPUT_MODE == fmu -o $OUTPUT_MODE == io ]
# SC2148: allow files w/o shebang
shellcheck -a -x -e SC2121 -e SC1008 -e SC2086 -e SC2166 -e SC2148 \
$scripts
ret=$?
if [ $ret -ne 0 ]; then
echo "Please fix the above script problems."
echo "If an error is raised that should be ignored, \
add the following right before the offending line:"
echo "# shellcheck disable=SCxxxx"
echo ""
echo "Re-run the script with '$0 $@'"
exit $ret
fi
echo "No problems found."
exit 0
Loading…
Cancel
Save