Shellcheck fixes for configure.sh and steamrt-bootstrap.sh

In steamrt-bootstrap,sh
  + Used quotes to prevent word splitting SC2046
  + Used $() notation rather than legacy backtick SC2006
  + which is non-standard. 'command -v' is builtin SC2230

In configure.sh
  + Assigned to local variable separately to avoid masking return values SC2155
  + Used to quote to prevent glob matching SC2053
  + Used -z command rather than ! -n SC2236
  + Fixed SC2129 which would have a minor performance gain of avoiding constantly opening and closing the makefile.
This commit is contained in:
Krish De Souza 2018-11-06 23:32:57 +00:00 committed by Andrew Eikum
parent e47e856563
commit 416bea727e
2 changed files with 34 additions and 28 deletions

View file

@ -19,7 +19,10 @@ if [[ $(tput colors 2>/dev/null || echo 0) -gt 0 ]]; then
COLOR_CLEAR=$'\e[0m'
fi
sh_quote() { local quoted="$(printf '%q ' "$@")"; [[ $# -eq 0 ]] || echo "${quoted:0:-1}"; }
sh_quote() {
local quoted
quoted="$(printf '%q ' "$@")"; [[ $# -eq 0 ]] || echo "${quoted:0:-1}";
}
err() { echo >&2 "${COLOR_ERR}!!${COLOR_CLEAR} $*"; }
stat() { echo >&2 "${COLOR_STAT}::${COLOR_CLEAR} $*"; }
info() { echo >&2 "${COLOR_INFO}::${COLOR_CLEAR} $*"; }
@ -72,7 +75,8 @@ function configure() {
check_steamrt_image "$steamrt64_type" "$steamrt64_name"
check_steamrt_image "$steamrt32_type" "$steamrt32_name"
local srcdir="$(dirname "$0")"
local srcdir
srcdir="$(dirname "$0")"
# Build name
local build_name="$arg_build_name"
@ -87,26 +91,28 @@ function configure() {
# Don't die after this point or we'll have rather unhelpfully deleted the Makefile
[[ ! -e "$MAKEFILE" ]] || rm "$MAKEFILE"
# Config
echo >> "$MAKEFILE" "# Generated by: $THIS_COMMAND"
echo >> "$MAKEFILE" ""
echo >> "$MAKEFILE" "SRCDIR := $(escape_for_make "$srcdir")"
echo >> "$MAKEFILE" "BUILD_NAME := $(escape_for_make "$build_name")"
{
# Config
echo "# Generated by: $THIS_COMMAND"
echo ""
echo "SRCDIR := $(escape_for_make "$srcdir")"
echo "BUILD_NAME := $(escape_for_make "$build_name")"
# ffmpeg?
if [[ -n $arg_ffmpeg ]]; then
echo >> "$MAKEFILE" "WITH_FFMPEG := 1"
fi
# ffmpeg?
if [[ -n $arg_ffmpeg ]]; then
echo "WITH_FFMPEG := 1"
fi
# SteamRT
echo >> "$MAKEFILE" "STEAMRT64_MODE := $(escape_for_make "$steamrt64_type")"
echo >> "$MAKEFILE" "STEAMRT64_IMAGE := $(escape_for_make "$steamrt64_name")"
echo >> "$MAKEFILE" "STEAMRT32_MODE := $(escape_for_make "$steamrt32_type")"
echo >> "$MAKEFILE" "STEAMRT32_IMAGE := $(escape_for_make "$steamrt32_name")"
# SteamRT
echo "STEAMRT64_MODE := $(escape_for_make "$steamrt64_type")"
echo "STEAMRT64_IMAGE := $(escape_for_make "$steamrt64_name")"
echo "STEAMRT32_MODE := $(escape_for_make "$steamrt32_type")"
echo "STEAMRT32_IMAGE := $(escape_for_make "$steamrt32_name")"
# Include base
echo >> "$MAKEFILE" ""
echo >> "$MAKEFILE" "include \$(SRCDIR)/build/makefile_base.mak"
# Include base
echo ""
echo "include \$(SRCDIR)/build/makefile_base.mak"
} >> "$MAKEFILE"
stat "Created $MAKEFILE, now run make to build."
stat " See README.md for make targets and instructions"
@ -142,7 +148,7 @@ function parse_args() {
fi
# Looks like an argument does it have a --foo=bar value?
if [[ ${arg%=*} != $arg ]]; then
if [[ ${arg%=*} != "$arg" ]]; then
val="${arg#*=}"
arg="${arg%=*}"
val_passed=1
@ -173,11 +179,11 @@ function parse_args() {
fi
# Check if this arg used the value and shouldn't have or vice-versa
if [[ -n $val_used && ! -n $val_passed ]]; then
if [[ -n $val_used && -z $val_passed ]]; then
# "--arg val" form, used $2 as the value.
# Don't allow this if it looked like "--arg --val"
if [[ ${val#--} != $val ]]; then
if [[ ${val#--} != "$val" ]]; then
err "Ambiguous format for argument with value \"$arg $val\""
err " (use $arg=$val or $arg='' $val)"
return 1

View file

@ -15,9 +15,9 @@ set -xe
apt-get install -y gcc-5 g++-5 g++-5-multilib flex bison libosmesa6-dev libpcap-dev \
libhal-dev libsane-dev libv4l-dev libgphoto2-2-dev libcapi20-dev \
libgsm1-dev libmpg123-dev libvulkan-dev libxslt1-dev nasm yasm ccache
update-alternatives --install `which gcc` gcc `which gcc-5` 50
update-alternatives --set gcc `which gcc-5`
update-alternatives --install `which g++` g++ `which g++-5` 50
update-alternatives --set g++ `which g++-5`
update-alternatives --install `which cpp` cpp-bin `which cpp-5` 50
update-alternatives --set cpp-bin `which cpp-5`
update-alternatives --install "$(command -v gcc)" gcc "$(command -v gcc-5)" 50
update-alternatives --set gcc "$(command -v gcc-5)"
update-alternatives --install "$(command -v g++)" g++ "$(command -v g++-5)" 50
update-alternatives --set g++ "$(command -v g++-5)"
update-alternatives --install "$(command -v cpp)" cpp-bin "$(command -v cpp-5)" 50
update-alternatives --set cpp-bin "$(command -v cpp-5)"