From bee18358311401488dc59de8b7a63866c613b51d Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Sun, 24 Feb 2019 16:53:45 +0100 Subject: [PATCH] Tools: fix style consistency in shell scripts "if [...]; then" --- Tools/astyle/check_code_style_all.sh | 5 +-- Tools/astyle/files_to_check_code_style.sh | 3 +- Tools/astyle/pre-commit | 3 +- Tools/check_submodules.sh | 18 +++----- Tools/serial/rc.serial.jinja | 3 +- Tools/serial/rc.serial_port.jinja | 6 +-- Tools/setup/ubuntu.sh | 9 ++-- Tools/sitl_run.sh | 54 ++++++++--------------- Tools/upload.sh | 12 ++--- 9 files changed, 38 insertions(+), 75 deletions(-) diff --git a/Tools/astyle/check_code_style_all.sh b/Tools/astyle/check_code_style_all.sh index debf058678..79c9d98bf7 100755 --- a/Tools/astyle/check_code_style_all.sh +++ b/Tools/astyle/check_code_style_all.sh @@ -25,7 +25,7 @@ else if [ "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_1" -a \ "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_2" -a \ "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_3" -a \ - "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_4" ]; + "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_4" ] then echo "Error: you're using ${ASTYLE_VER}" echo "but should be using ${ASTYLE_VER_REQUIRED_1}, ${ASTYLE_VER_REQUIRED_2}, ${ASTYLE_VER_REQUIRED_3}, or ${ASTYLE_VER_REQUIRED_4} instead" @@ -36,8 +36,7 @@ fi CI="${CI:-false}" DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) -if [[ "$@" == "--fix" ]] -then +if [[ "$@" == "--fix" ]]; then export PX4_ASTYLE_FIX=1 fi diff --git a/Tools/astyle/files_to_check_code_style.sh b/Tools/astyle/files_to_check_code_style.sh index 68cc410118..8cc317cbd5 100755 --- a/Tools/astyle/files_to_check_code_style.sh +++ b/Tools/astyle/files_to_check_code_style.sh @@ -3,8 +3,7 @@ set -eu PATTERN="-e ." -if [ $# -gt 0 ] -then +if [ $# -gt 0 ]; then PATTERN="$1" fi diff --git a/Tools/astyle/pre-commit b/Tools/astyle/pre-commit index d7fca3f31f..31b5a61bb2 100755 --- a/Tools/astyle/pre-commit +++ b/Tools/astyle/pre-commit @@ -48,8 +48,7 @@ fi # If there are whitespace errors, print the offending file names and fail. git diff-index --check --cached $against -- -if [ $? -ne 0 ] -then +if [ $? -ne 0 ]; then exit 1 fi diff --git a/Tools/check_submodules.sh b/Tools/check_submodules.sh index 66891809ea..f245c9ba0f 100755 --- a/Tools/check_submodules.sh +++ b/Tools/check_submodules.sh @@ -3,12 +3,10 @@ function check_git_submodule { # The .git exists in a submodule if init and update have been done. -if [[ -f $1"/.git" || -d $1"/.git" ]]; -then +if [[ -f $1"/.git" || -d $1"/.git" ]]; then # CI environment always update - if [ "$CI" == "true" ]; - then + if [ "$CI" == "true" ]; then git submodule --quiet sync --recursive -- $1 git submodule --quiet update --init --recursive -- $1 || true git submodule --quiet update --init --recursive -- $1 @@ -17,8 +15,7 @@ then SUBMODULE_STATUS=$(git submodule summary "$1") STATUSRETVAL=$(echo $SUBMODULE_STATUS | grep -A20 -i "$1") - if ! [[ -z "$STATUSRETVAL" ]]; - then + if ! [[ -z "$STATUSRETVAL" ]]; then echo -e "\033[31mChecked $1 submodule, ACTION REQUIRED:\033[0m" echo "" echo -e "Different commits:" @@ -39,11 +36,9 @@ then echo -e " Use \033[94mgit add $1 && git commit -m 'Updated $1'\033[0m to choose this version (careful!)" echo "" read user_cmd - if [ "$user_cmd" == "y" ] - then + if [ "$user_cmd" == "y" ]; then echo "Continuing build with manually overridden submodule.." - elif [ "$user_cmd" == "u" ] - then + elif [ "$user_cmd" == "u" ]; then git submodule sync --recursive -- $1 git submodule update --init --recursive -- $1 || true git submodule update --init --recursive --force -- $1 @@ -62,8 +57,7 @@ fi } # If called with a path then respect $GIT_SUBMODULES_ARE_EVIL but do normal processing -if [ "$#" != "0" ]; -then +if [ "$#" != "0" ]; then # called with a path then process only that path but respect $GIT_SUBMODULES_ARE_EVIL [ -n "$GIT_SUBMODULES_ARE_EVIL" ] && { # GIT_SUBMODULES_ARE_EVIL is set, meaning user doesn't want submodules updated diff --git a/Tools/serial/rc.serial.jinja b/Tools/serial/rc.serial.jinja index 6f3b9de05b..e767409173 100644 --- a/Tools/serial/rc.serial.jinja +++ b/Tools/serial/rc.serial.jinja @@ -12,8 +12,7 @@ set i {{ command.instance }} {% endif -%} # get the device & baudrate sh $PRT_F -if [ $SERIAL_DEV != none ] -then +if [ $SERIAL_DEV != none ]; then {% if not constrained_flash -%} echo "Starting {{ command.label }} on $SERIAL_DEV" {% endif -%} diff --git a/Tools/serial/rc.serial_port.jinja b/Tools/serial/rc.serial_port.jinja index 869ffb0452..1abcb8f81a 100644 --- a/Tools/serial/rc.serial_port.jinja +++ b/Tools/serial/rc.serial_port.jinja @@ -4,10 +4,8 @@ set SERIAL_DEV none {% for serial_device in serial_devices -%} -if param compare "$PRT" {{ serial_device.index }} -then - if [ "x$PRT_{{ serial_device.tag }}_" = "x" ] - then +if param compare "$PRT" {{ serial_device.index }}; then + if [ "x$PRT_{{ serial_device.tag }}_" = "x" ]; then set SERIAL_DEV {{ serial_device.device }} set BAUD_PARAM SER_{{ serial_device.tag }}_BAUD set PRT_{{ serial_device.tag }}_ 1 diff --git a/Tools/setup/ubuntu.sh b/Tools/setup/ubuntu.sh index 4451822a03..fa0df8f479 100755 --- a/Tools/setup/ubuntu.sh +++ b/Tools/setup/ubuntu.sh @@ -23,15 +23,12 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) # otherwise warn and point to docker? UBUNTU_RELEASE=`lsb_release -rs` -if [[ "${UBUNTU_RELEASE}" == "14.04" ]] -then +if [[ "${UBUNTU_RELEASE}" == "14.04" ]]; then echo "Ubuntu 14.04 unsupported, see docker px4io/px4-dev-base" exit 1 -elif [[ "${UBUNTU_RELEASE}" == "16.04" ]] -then +elif [[ "${UBUNTU_RELEASE}" == "16.04" ]]; then echo "Ubuntu 16.04" -elif [[ "${UBUNTU_RELEASE}" == "18.04" ]] -then +elif [[ "${UBUNTU_RELEASE}" == "18.04" ]]; then echo "Ubuntu 18.04" fi diff --git a/Tools/sitl_run.sh b/Tools/sitl_run.sh index ad81dfbca7..59d71cebca 100755 --- a/Tools/sitl_run.sh +++ b/Tools/sitl_run.sh @@ -31,20 +31,17 @@ fi if [ "$model" != none ]; then jmavsim_pid=`ps aux | grep java | grep "\-jar jmavsim_run.jar" | awk '{ print $2 }'` - if [ -n "$jmavsim_pid" ] - then + if [ -n "$jmavsim_pid" ]; then kill $jmavsim_pid fi fi -if [ "$model" == "" ] || [ "$model" == "none" ] -then +if [ "$model" == "" ] || [ "$model" == "none" ]; then echo "empty model, setting iris as default" model="iris" fi -if [ "$#" -lt 6 ] -then +if [ "$#" -lt 6 ]; then echo usage: sitl_run.sh sitl_bin debugger program model src_path build_path echo "" exit 1 @@ -67,24 +64,19 @@ done SIM_PID=0 # Allow speed factor to bet set from environment. -if [[ -n "$PX4_SIM_SPEED_FACTOR" ]]; -then +if [[ -n "$PX4_SIM_SPEED_FACTOR" ]]; then speed_factor=$PX4_SIM_SPEED_FACTOR else speed_factor=1 fi -if [ "$program" == "jmavsim" ] && [ ! -n "$no_sim" ] -then +if [ "$program" == "jmavsim" ] && [ ! -n "$no_sim" ]; then # Start Java simulator "$src_path"/Tools/jmavsim_run.sh -r 250 -f $speed_factor & SIM_PID=`echo $!` -elif [ "$program" == "gazebo" ] && [ ! -n "$no_sim" ] -then - if [ -x "$(command -v gazebo)" ] - then - if [[ -z "$DONT_RUN" ]] - then +elif [ "$program" == "gazebo" ] && [ ! -n "$no_sim" ]; then + if [ -x "$(command -v gazebo)" ]; then + if [[ -z "$DONT_RUN" ]]; then # Set the plugin path so Gazebo finds our model and sim source "$src_path/Tools/setup_gazebo.bash" "${src_path}" "${build_path}" @@ -123,26 +115,19 @@ echo SITL COMMAND: $sitl_command export PX4_SIM_MODEL=${model} -if [[ -n "$DONT_RUN" ]] -then +if [[ -n "$DONT_RUN" ]]; then echo "Not running simulation (\$DONT_RUN is set)." -elif [ "$debugger" == "lldb" ] -then +elif [ "$debugger" == "lldb" ]; then eval lldb -- $sitl_command -elif [ "$debugger" == "gdb" ] -then +elif [ "$debugger" == "gdb" ]; then eval gdb --args $sitl_command -elif [ "$debugger" == "ddd" ] -then +elif [ "$debugger" == "ddd" ]; then eval ddd --debugger gdb --args $sitl_command -elif [ "$debugger" == "valgrind" ] -then +elif [ "$debugger" == "valgrind" ]; then eval valgrind --track-origins=yes --leak-check=full -v $sitl_command -elif [ "$debugger" == "callgrind" ] -then +elif [ "$debugger" == "callgrind" ]; then eval valgrind --tool=callgrind -v $sitl_command -elif [ "$debugger" == "ide" ] -then +elif [ "$debugger" == "ide" ]; then echo "######################################################################" echo echo "PX4 simulator not started, use your IDE to start PX4_${model} target." @@ -156,14 +141,11 @@ fi popd >/dev/null -if [[ -z "$DONT_RUN" ]] -then - if [ "$program" == "jmavsim" ] - then +if [[ -z "$DONT_RUN" ]]; then + if [ "$program" == "jmavsim" ]; then pkill -9 -P $SIM_PID kill -9 $SIM_PID - elif [ "$program" == "gazebo" ] - then + elif [ "$program" == "gazebo" ]; then kill -9 $SIM_PID if [[ ! -n "$HEADLESS" ]]; then kill -9 $GUI_PID diff --git a/Tools/upload.sh b/Tools/upload.sh index cce24ee991..d12a3c7e8b 100755 --- a/Tools/upload.sh +++ b/Tools/upload.sh @@ -10,23 +10,19 @@ SYSTYPE=`uname -s` # # XXX The uploader should be smarter than this. # -if [ $SYSTYPE = "Darwin" ]; -then +if [ $SYSTYPE = "Darwin" ]; then SERIAL_PORTS="/dev/tty.usbmodemPX*,/dev/tty.usbmodem*" fi -if [ $SYSTYPE = "Linux" ]; -then +if [ $SYSTYPE = "Linux" ]; then SERIAL_PORTS="/dev/serial/by-id/*_PX4_*,/dev/serial/by-id/usb-3D_Robotics*,/dev/serial/by-id/usb-The_Autopilot*,/dev/serial/by-id/usb-Bitcraze*,/dev/serial/by-id/pci-Bitcraze*,/dev/serial/by-id/usb-Gumstix*," fi -if [[ $SYSTYPE = *"CYGWIN"* ]]; -then +if [[ $SYSTYPE = *"CYGWIN"* ]]; then SERIAL_PORTS="/dev/ttyS*" fi -if [ $SYSTYPE = "" ]; -then +if [ $SYSTYPE = "" ]; then SERIAL_PORTS="COM32,COM31,COM30,COM29,COM28,COM27,COM26,COM25,COM24,COM23,COM22,COM21,COM20,COM19,COM18,COM17,COM16,COM15,COM14,COM13,COM12,COM11,COM10,COM9,COM8,COM7,COM6,COM5,COM4,COM3,COM2,COM1,COM0" fi