mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
Tools: add run-shellcheck.sh to statically analyze startup scripts
Use './Tools/run-shellcheck.sh ROMFS/px4fmu_common' to run it.
This commit is contained in:
parent
9712f6b02a
commit
4e860e357c
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
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
|
||||
|
||||
# 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
Executable file
41
Tools/run-shellcheck.sh
Executable file
@ -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…
x
Reference in New Issue
Block a user