diff --git a/wmake/wclean b/wmake/wclean
index f615a99061..f8d475a334 100755
--- a/wmake/wclean
+++ b/wmake/wclean
@@ -1,9 +1,9 @@
-#!/bin/sh
+#!/bin/bash
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
-# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
+# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@@ -37,6 +37,7 @@
Script=${0##*/}
# Source the wmake functions
+# shellcheck source=scripts/wmakeFunctions
. ${0%/*}/scripts/wmakeFunctions
error() {
@@ -120,7 +121,7 @@ then
if [ "$dir" ]
then
- cd $dir 2>/dev/null || {
+ cd "$dir" 2>/dev/null || {
echo "$Script error: could not change to directory '$dir'" 1>&2
exit 1
}
@@ -152,61 +153,61 @@ then
echo "Removing empty directories..."
# Get sub-directories avoiding particular directories
+ # shellcheck disable=SC2044
for dir in $(find . -mindepth 1 -maxdepth 1 \
-type d \( -name .git -prune -o -print \) )
do
echo " searching: $dir"
- find $dir -depth -type d -empty -exec rmdir {} \; -print
+ find "$dir" -depth -type d -empty -exec rmdir {} \; -print
done
# Second pass: clean up object directories with WM_PROJECT_DIR that don't
# have respective source code folders, along with the respective binaries
- expandPath $PWD
+ expandPath "$PWD"
if [ "$exPath" = "$WM_PROJECT_DIR" ]
then
- findObjectDir $PWD
+ findObjectDir "$PWD"
- if [ -d $objectsDir ]
+ if [ -d "$objectsDir" ]
then
echo " Removing redundant object directories in $objectsDir"
- find $objectsDir -name 'variables' -print | \
- while read variablesFile
+ find "$objectsDir" -name 'variables' -print | \
+ while read -r variablesFile
do
# Hack'ish way of getting the original source code path
- depFile=$(dirname $variablesFile)
- depToSource $depFile
+ depFile=$(dirname "$variablesFile")
+ depToSource "$depFile"
# Check if the original source code directory exists
if [ ! -r "$sourceFile" ]
then
# Delete the respective binary first
- binaryFile=$(cat $variablesFile |
- grep -e '^ *\(EXE\|LIB\) *= *' )
+ binaryFile=$(grep -e '^ *\(EXE\|LIB\) *= *' "$variablesFile")
# Catch all file extension (o,a,so,?+) for libraries
- if echo $binaryFile | grep -qe '^ *LIB *= *'
+ if echo "$binaryFile" | grep -qe '^ *LIB *= *'
then
binaryFile="${binaryFile}.*"
fi
# Isolate path and translate environment variables
- binaryFile=$(echo $binaryFile | \
+ binaryFile=$(echo "$binaryFile" | \
sed -e 's/^ *\(EXE\|LIB\) *= *//' \
-e 's/(/{/g' -e 's/)/}/g' )
# Expand environment variables for path
- binaryFile=$(eval echo $binaryFile)
+ binaryFile=$(eval echo "$binaryFile")
# Verbosely remove binary file
- if [ -n "$binaryFile" -a -e "$binaryFile" ]
+ if [ -n "$binaryFile" ] && [ -e "$binaryFile" ]
then
- rm -vf $binaryFile 2>/dev/null
+ rm -vf "$binaryFile" 2>/dev/null
fi
# Remove the deprecated object directory
- rm -rvf $depFile 2>/dev/null
+ rm -rvf "$depFile" 2>/dev/null
fi
done
fi
@@ -232,16 +233,17 @@ then
exit $?
else
# For all the sub-directories containing a 'Make' directory
- for dir in `find . \( -type d -a -name Make \)`
+ # shellcheck disable=SC2044
+ for dir in $(find . \( -type d -a -name Make \))
do
dir=${dir%/Make} # Parent directory - trim /Make from the end
# If Allwclean exists execute otherwise wclean
if [ -e "$dir/Allwclean" ]
then
- $dir/Allwclean
+ "$dir/Allwclean"
else
- $0 $dir
+ $0 "$dir"
fi
done
fi
@@ -255,15 +257,15 @@ unset targetType
# Clean the 'Make' directory if present
#------------------------------------------------------------------------------
-if [ -d $MakeDir ]
+if [ -d "$MakeDir" ]
then
objectsDir=$MakeDir/$WM_OPTIONS
- if [ $(echo $PWD | grep "$WM_PROJECT_DIR") ]
+ if [[ "$PWD" = *"$WM_PROJECT_DIR"* ]]
then
platformPath=$WM_PROJECT_DIR/platforms/${WM_OPTIONS}
- objectsDir=$platformPath$(echo $PWD | sed s%$WM_PROJECT_DIR%% )
+ objectsDir=$platformPath${PWD//$WM_PROJECT_DIR/}
fi
- rm -rf $objectsDir 2>/dev/null
+ rm -rf "$objectsDir" 2>/dev/null
fi
diff --git a/wmake/wcleanPlatform b/wmake/wcleanPlatform
index fe473a93d2..dace4187a2 100755
--- a/wmake/wcleanPlatform
+++ b/wmake/wcleanPlatform
@@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
-# \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
+# \\ / A nd | Copyright (C) 2015-2018 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@@ -79,16 +79,16 @@ USAGE
}
# Print help message
-if [ "$1" = "-h" -o "$1" = "-help" ]; then
+if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
usage && exit 0
fi
# Check the script is executed from the project top-level directory
[ "$PWD" = "$WM_PROJECT_DIR" ] || \
- error "Not in the project top-level directory " $WM_PROJECT_DIR
+ error "Not in the project top-level directory " "$WM_PROJECT_DIR"
# Get the platforms from the arguments
-platforms="$@"
+platforms="$*"
# If no arguments are provided select the current platform
if [ "$#" -lt 1 ]; then
@@ -100,7 +100,7 @@ if [ "$platforms" = "-all" ]; then
rm -rf platforms/*
echo "Removing lnInclude directories"
- find . -depth -type d \( -name lnInclude \) | xargs rm -rf
+ find . -depth -type d \( -name lnInclude \) -print0 | xargs -0 rm -rf
tutorials/Allclean
else
@@ -114,10 +114,10 @@ else
[ -n "$platform" ] || continue
fi
- if [ -d platforms/${platform} ]
+ if [ -d platforms/"${platform}" ]
then
echo "Cleaning platform $platform"
- rm -rf platforms/${platform}*
+ rm -rf platforms/"${platform}"*
else
echo "Platform $platform not built"
fi
diff --git a/wmake/wdep b/wmake/wdep
index 9caae33e00..64db3f6234 100755
--- a/wmake/wdep
+++ b/wmake/wdep
@@ -38,6 +38,7 @@
Script=${0##*/}
# Source the wmake functions
+# shellcheck source=scripts/wmakeFunctions
. ${0%/*}/scripts/wmakeFunctions
usage() {
@@ -90,9 +91,9 @@ checkEnv
sourceFile=$1
-if [ ! -e $1 ]
+if [ ! -e "$1" ]
then
- sourceFile=$(find . -name $sourceFile -print -quit)
+ sourceFile=$(find . -name "$sourceFile" -print -quit)
if [ -z "$sourceFile" ]
then
echo "$Script: cannot find source file $1" 1>&2
@@ -106,11 +107,11 @@ fi
# and echo path for the dep file corresponding to the specified source file
#------------------------------------------------------------------------------
-findObjectDir $sourceFile
+findObjectDir "$sourceFile"
fileName=${1##*/}
-echo $objectsDir/$fileName.dep
+echo "$objectsDir/$fileName.dep"
#------------------------------------------------------------------------------
diff --git a/wmake/wmake b/wmake/wmake
index 48a2c280fc..33c9de99bc 100755
--- a/wmake/wmake
+++ b/wmake/wmake
@@ -56,7 +56,8 @@
Script=${0##*/}
# Source the wmake functions
-. ${0%/*}/scripts/wmakeFunctions
+# shellcheck source=scripts/wmakeFunctions
+. "${0%/*}/scripts/wmakeFunctions"
error() {
exec 1>&2
@@ -116,7 +117,7 @@ useAllCores()
{
if [ -r /proc/cpuinfo ]
then
- WM_NCOMPPROCS=$(egrep "^processor" /proc/cpuinfo | wc -l)
+ WM_NCOMPPROCS=$(grep -Ec "^processor" /proc/cpuinfo)
else
WM_NCOMPPROCS=1
fi
@@ -152,7 +153,7 @@ do
# Parallel compilation on all cores of local machine
-j)
useAllCores
- test $# -ge 2 && expr $2 + 1 > /dev/null 2>&1 \
+ test $# -ge 2 && (($2 + 1)) > /dev/null 2>&1 \
&& shift && export WM_NCOMPPROCS=$1
echo "Compiling enabled on $WM_NCOMPPROCS cores"
;;
@@ -202,7 +203,7 @@ checkEnv
# When compiling anything but a standalone exe WM_PROJECT and WM_PROJECT_DIR
# must be set
-[ "$1" = exe -o \( "$WM_PROJECT" -a "$WM_PROJECT_DIR" \) ] || {
+[ "$1" = exe ] || { [ "$WM_PROJECT" ] && [ "$WM_PROJECT_DIR" ]; } || {
echo "$Script error:" 1>&2
echo " environment variable \$WM_PROJECT or " \
"\$WM_PROJECT_DIR not set" 1>&2
@@ -216,25 +217,24 @@ checkEnv
#------------------------------------------------------------------------------
# Set WM_NCOMPPROCS automatically when both WM_HOSTS and WM_SCHEDULER are set
-if [ -z "$WM_NCOMPPROCS" -a -n "$WM_HOSTS" -a -n "$WM_SCHEDULER" ]
+if [ -z "$WM_NCOMPPROCS" ] && [ -n "$WM_HOSTS" ] && [ -n "$WM_SCHEDULER" ]
then
- WM_NCOMPPROCS=$(wmakeScheduler -count)
- [ $? -eq 0 ] || unset WM_NCOMPPROCS
+ WM_NCOMPPROCS=$(wmakeScheduler -count) || unset WM_NCOMPPROCS
fi
if [ "$WM_NCOMPPROCS" ]
then
parOpt="-j $WM_NCOMPPROCS"
- if [ "$WM_NCOMPPROCS" -gt 1 -a ! "$MAKEFLAGS" ]
+ if [ "$WM_NCOMPPROCS" -gt 1 ] && [ ! "$MAKEFLAGS" ]
then
lockDir=$HOME/.$WM_PROJECT/.wmake
- if [ -d $lockDir ]
+ if [ -d "$lockDir" ]
then
- rm -f $lockDir/*
+ rm -f "$lockDir/*"
else
- mkdir -p $lockDir
+ mkdir -p "$lockDir"
fi
make="$make --no-print-directory $parOpt"
@@ -266,7 +266,7 @@ then
if [ "$dir" ]
then
- cd $dir 2>/dev/null || {
+ cd "$dir" 2>/dev/null || {
echo "$Script error: could not change to directory '$dir'" 1>&2
exit 1
}
@@ -286,7 +286,7 @@ if [ -n "$update" ]
then
wrmdep -update
wrmdep -old
- wmakeLnIncludeAll -update $parOpt
+ wmakeLnIncludeAll -update "$parOpt"
wclean empty
export WM_UPDATE_DEPENDENCIES=yes
elif [ -z "$all" ]
@@ -303,7 +303,7 @@ if [ "$all" = "all" ]
then
if [ -e Allwmake ]
then
- ./Allwmake -fromWmake $targetType
+ ./Allwmake -fromWmake "$targetType"
exit $?
else
# Have to keep track of the main exit code for the call to "make"
@@ -312,22 +312,21 @@ then
# Find all the sub-directories containing a 'Make' directory
FOAM_APPS=$(\
for d in *; \
- do [ -d "$d" -a "$d" != Optional -a "$d" != Make ] \
+ do [ -d "$d" ] && [ "$d" != Optional ] && [ "$d" != Make ] \
&& echo "$d"; \
done | xargs \
)
-
if [ ! "$FOAM_APPS" = "" ]
then
# Compile all applications in sub-directories
$make ${WM_CONTINUE_ON_ERROR:+-k} \
- -f $WM_DIR/makefiles/apps \
+ -f "$WM_DIR/makefiles/apps" \
TARGET="$targetType" FOAM_APPS="$FOAM_APPS"
makeExitCode=$?
fi
# If the current directory contains a 'Make' directory continue
# otherwise exit, or always exit in case of error
- if [ ! -d $MakeDir -o $makeExitCode -ne 0 ]
+ if [ ! -d "$MakeDir" ] || [ "$makeExitCode" -ne 0 ]
then
exit $makeExitCode
fi
@@ -344,7 +343,7 @@ fi
if [ "$all" = "queue" ]
then
- [ -n "$update" ] || wmakeLnIncludeAll $parOpt
+ [ -n "$update" ] || wmakeLnIncludeAll "$parOpt"
(
export WM_COLLECT_DIR=$WM_PROJECT_DIR/platforms/${WM_OPTIONS}/${PWD////_}
@@ -385,7 +384,6 @@ then
case "$targetType" in
lib*)
unset targetType
- break
;;
esac
fi
@@ -397,23 +395,23 @@ fi
#------------------------------------------------------------------------------
objectsDir=$MakeDir/$WM_OPTIONS
-if [ $(echo $PWD | grep "$WM_PROJECT_DIR") ]
+if [[ "$PWD" = *"$WM_PROJECT_DIR"* ]]
then
platformPath=$WM_PROJECT_DIR/platforms/${WM_OPTIONS}
- objectsDir=$platformPath$(echo $PWD | sed s%$WM_PROJECT_DIR%% )
+ objectsDir=$platformPath${PWD//$WM_PROJECT_DIR/}
fi
(
unset MAKEFLAGS
- mkdir -p $objectsDir
+ mkdir -p "$objectsDir"
# Pre-build the $WM_OPTIONS/options file
# which is included when building the $WM_OPTIONS/files file
- $make -s -f $WM_DIR/makefiles/files MAKE_DIR=$MakeDir \
- OBJECTS_DIR=$objectsDir $objectsDir/options
+ $make -s -f "$WM_DIR/makefiles/files" MAKE_DIR="$MakeDir" \
+ OBJECTS_DIR="$objectsDir" "$objectsDir/options"
- $make -s -f $WM_DIR/makefiles/files MAKE_DIR=$MakeDir \
- OBJECTS_DIR=$objectsDir
+ $make -s -f "$WM_DIR/makefiles/files" MAKE_DIR="$MakeDir" \
+ OBJECTS_DIR="$objectsDir"
)
@@ -421,7 +419,7 @@ fi
# Check the $objectsDir/sourceFiles file was created successfully
#------------------------------------------------------------------------------
-[ -r $objectsDir/sourceFiles ] || {
+[ -r "$objectsDir/sourceFiles" ] || {
echo "$Script error: file '$objectsDir/sourceFiles'" \
"could not be created in $PWD" 1>&2
exit 1
@@ -438,8 +436,8 @@ case "$targetType" in
# ... but only if 'LIB' is declared in 'Make/files'
if grep -e '^ *LIB *=' "$MakeDir/files" >/dev/null 2>&1
then
- $make -s -f $WM_DIR/makefiles/general MAKE_DIR=$MakeDir \
- OBJECTS_DIR=$objectsDir lnInclude
+ $make -s -f "$WM_DIR/makefiles/general" MAKE_DIR="$MakeDir" \
+ OBJECTS_DIR="$objectsDir" lnInclude
fi
;;
esac
@@ -452,8 +450,8 @@ esac
if [ -n "$WM_UPDATE_DEPENDENCIES" ]
then
- $make -f $WM_DIR/makefiles/general MAKE_DIR=$MakeDir \
- OBJECTS_DIR=$objectsDir dep
+ $make -f "$WM_DIR"/makefiles/general MAKE_DIR="$MakeDir" \
+ OBJECTS_DIR="$objectsDir" dep
makeExitCode=$?
if [ $makeExitCode -ne 0 ]
@@ -469,8 +467,9 @@ fi
# Make the dependency files or object files and link
#------------------------------------------------------------------------------
-exec $make -f $WM_DIR/makefiles/general MAKE_DIR=$MakeDir \
- OBJECTS_DIR=$objectsDir $targetType
+# shellcheck disable=SC2093,SC2086
+exec $make -f "$WM_DIR/makefiles/general" MAKE_DIR="$MakeDir" \
+ OBJECTS_DIR="$objectsDir" $targetType
#------------------------------------------------------------------------------
diff --git a/wmake/wmakeCheckPwd b/wmake/wmakeCheckPwd
index ce24cd2fbe..b983064aa5 100755
--- a/wmake/wmakeCheckPwd
+++ b/wmake/wmakeCheckPwd
@@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
-# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
+# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@@ -104,7 +104,7 @@ dirName="$1"
# Use /bin/pwd to get the absolute path (could be linked)
thisDir=$(/bin/pwd)
-target=$(cd $dirName 2>/dev/null && /bin/pwd)
+target=$(cd "$dirName" 2>/dev/null && /bin/pwd)
# Return 0 if this directory is
[ "$thisDir" = "$target" ] && exit 0
diff --git a/wmake/wmakeFilesAndOptions b/wmake/wmakeFilesAndOptions
index fa9ef9cb6d..18ca05c933 100755
--- a/wmake/wmakeFilesAndOptions
+++ b/wmake/wmakeFilesAndOptions
@@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
-# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
+# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@@ -98,12 +98,12 @@ fi
[ -e Make/files ] || {
echo "$Script: Creating Make/files"
- $WM_DIR/scripts/makeFiles
+ "$WM_DIR/scripts/makeFiles"
}
[ -e Make/options ] || {
echo "$Script: Creating Make/options"
- $WM_DIR/scripts/makeOptions
+ "$WM_DIR/scripts/makeOptions"
}
diff --git a/wmake/wmakeLnInclude b/wmake/wmakeLnInclude
index f77183e482..40d955a4ae 100755
--- a/wmake/wmakeLnInclude
+++ b/wmake/wmakeLnInclude
@@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
-# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
+# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@@ -70,9 +70,6 @@ error() {
# Parse arguments and options
#------------------------------------------------------------------------------
-# Default 'find' option
-unset findOpt
-
# Default 'ln' option
lnOpt="-s"
@@ -141,7 +138,7 @@ fi
cd $incDir || exit 1
-if [ "$silentOpt" = true -o -n "$WM_QUIET" ]
+if [ "$silentOpt" = true ] || [ -n "$WM_QUIET" ]
then
echo " ln: $incDir" 1>&2
else
@@ -152,14 +149,14 @@ fi
#------------------------------------------------------------------------------
# Remove any broken links first (this helps when file locations have moved)
#------------------------------------------------------------------------------
-find -L . -type l | xargs rm -f
+find -L . -type l -print0 | xargs -0 rm -f
#------------------------------------------------------------------------------
# Create links, avoid recreating links unless necessary
# things placed in the 'noLink' directory are skipped
#------------------------------------------------------------------------------
-find .. $findOpt \
+find .. \
\( -name lnInclude -o -name Make -o -name config -o -name noLink \) \
-prune \
-o \( \
diff --git a/wmake/wmakeLnIncludeAll b/wmake/wmakeLnIncludeAll
index 0267dfbbd5..d66acb1fd5 100755
--- a/wmake/wmakeLnIncludeAll
+++ b/wmake/wmakeLnIncludeAll
@@ -62,7 +62,6 @@ error() {
# Parse arguments and options
#------------------------------------------------------------------------------
-findName=lnInclude
nCores=0
# Default 'wmakeLnInclude' option
@@ -87,7 +86,7 @@ do
# Parallel execution on WM_NCOMPPROCS cores
-j)
nCores=$WM_NCOMPPROCS
- test $# -ge 2 && expr $2 + 1 > /dev/null 2>&1 \
+ test $# -ge 2 && (($2 + 1)) > /dev/null 2>&1 \
&& shift && nCores=$1
;;
# Parallel compilation on specified number of cores
@@ -115,8 +114,10 @@ then
exit 1
}
+ # shellcheck disable=SC2034
LIB_SRC="$WM_PROJECT_DIR/src"
+ # shellcheck disable=SC2016
includeDirs="
$WM_PROJECT_DIR/src/$WM_PROJECT
$WM_PROJECT_DIR/src/OSspecific/$WM_OSTYPE
@@ -126,13 +127,13 @@ then
printed=
for d in $includeDirs
do [ ! -d "$d" ]
- path=$(eval echo $d)
- if [ ! -d $path/lnInclude ]
+ path=$(eval echo "$d")
+ if [ ! -d "$path/lnInclude" ]
then
[ $printed ] || echo "$Script: running wmakeLnInclude on dependent libraries:"
printed=true
echo -n " "
- eval wmakeLnInclude $wmLnOpt $d
+ eval wmakeLnInclude $wmLnOpt "$d"
fi
done
@@ -140,8 +141,6 @@ then
else
- FAIL=0
-
if [ "$nCores" -gt 0 ]
then
echo "$Script: starting wmakeLnInclude processes on $nCores cores"
@@ -154,7 +153,7 @@ else
for checkDir
do
- if [ -d $checkDir ]
+ if [ -d "$checkDir" ]
then
echo " searching $checkDir for 'Make' directories"
else
@@ -162,7 +161,7 @@ else
continue
fi
- find $checkDir -depth -type d -name Make -print | while read MakeDir
+ find "$checkDir" -depth -type d -name Make -print | while read -r MakeDir
do
topDir=${MakeDir%/Make} # trim /Make from the end
if [ -d "$topDir" ]
@@ -173,16 +172,18 @@ else
# and more as the cores become free
if [ "$nCores" -gt 0 ]
then
+ # shellcheck disable=SC2207
joblist=($(jobs -p))
- while (( ${#joblist[*]} > $nCores ))
+ while (( ${#joblist[*]} > "$nCores" ))
do
# When the job limit is reached wait for a job to finish
wait -n
+ # shellcheck disable=SC2207
joblist=($(jobs -p))
done
- wmakeLnInclude $wmLnOpt $topDir &
+ wmakeLnInclude $wmLnOpt "$topDir" &
else
- wmakeLnInclude $wmLnOpt $topDir
+ wmakeLnInclude $wmLnOpt "$topDir"
fi
elif [ -d "$topDir/lnInclude" ]
then
@@ -204,7 +205,7 @@ else
sleep 3
fi
- unset FAIL joblist
+ unset joblist
fi
@@ -212,7 +213,7 @@ fi
# Cleanup local variables and functions
#------------------------------------------------------------------------------
-unset Script usage error findName nCores wmLnOpt depOpt
+unset Script usage error nCores wmLnOpt depOpt
#------------------------------------------------------------------------------
diff --git a/wmake/wmakePrintBuild b/wmake/wmakePrintBuild
index 72494b47df..a775c0ea9f 100755
--- a/wmake/wmakePrintBuild
+++ b/wmake/wmakePrintBuild
@@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
-# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
+# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@@ -78,7 +78,7 @@ do
shift
;;
-major)
- echo ${WM_PROJECT_VERSION:-unknown}
+ echo "${WM_PROJECT_VERSION:-unknown}"
exit 0
;;
-u | -update)
@@ -119,10 +119,10 @@ build="$WM_PROJECT_DIR/.build"
unset oldPackage oldVersion
getOldValues()
{
- set -- $(tail -1 $build 2>/dev/null)
+ set -- "$(tail -1 "$build" 2>/dev/null)"
oldVersion="$1"
[ "$#" -gt 0 ] && shift
- oldPackage="$@"
+ oldPackage="$*"
[ "${oldPackage:-none}" = none ] && unset oldPackage
}
@@ -153,7 +153,7 @@ else
# if there are multiple values (eg, HEAD, origin/HEAD, ...)
# only take the first one, which is 'HEAD'
version=$(
- cd $WM_PROJECT_DIR 2>/dev/null && \
+ cd "$WM_PROJECT_DIR" 2>/dev/null && \
git show-ref --hash=12 --head HEAD 2>/dev/null | head -1
)
@@ -181,11 +181,11 @@ fi
#------------------------------------------------------------------------------
# Update persistent build tag if possible
#------------------------------------------------------------------------------
-if [ $rc -eq 0 -a -n "$update" ]
+if [ $rc -eq 0 ] && [ -n "$update" ]
then
if [ "$version:$package" != "$oldVersion:$oldPackage" ]
then
- if [ -w "$build" -o \( -w "$WM_PROJECT_DIR" -a ! -e "$build" \) ]
+ if [ -w "$build" ] || { [ -w "$WM_PROJECT_DIR" ] && [ ! -e "$build" ]; }
then
printTag >| "$build" 2>/dev/null
fi
diff --git a/wmake/wmakeScheduler b/wmake/wmakeScheduler
index a927af7a37..fb458cb616 100755
--- a/wmake/wmakeScheduler
+++ b/wmake/wmakeScheduler
@@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
-# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
+# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@@ -51,24 +51,24 @@
Script=${0##*/}
# csh sets HOST, bash sets HOSTNAME
-: ${HOST:=$HOSTNAME}
+: "${HOST:=$HOSTNAME}"
lockDir=$HOME/.$WM_PROJECT/.wmake
# Fallback - 1 core on current host
-: ${WM_HOSTS:=$HOST:1}
+: "${WM_HOSTS:=$HOST:1}"
# Count the total number of slots available and exit
if [ "$1" = "-count" ]
then
- expr $(
+ (( $(
for slotGroup in $WM_HOSTS
do
n=${slotGroup##*:}
[ "$n" = "${slotGroup%%:*}" ] && n=1 # missing ':'
echo "+ ${n:-1}"
done
- )
+ ) ))
exit 0
fi
@@ -127,7 +127,7 @@ case $sourceFoam in
esac
# Quote double-quotes for remote command line
-rcmd=$(echo $* | sed -e s/\"/\'\"\'/g)
+rcmd=${*//\"/\'\"\'}
# The same, without forking (not ksh, maybe not /bin/sh either)
# rcmd=$(while [ "$#" -gt 0 ]; do echo "${1//\"/'\"'}"; shift; done)
@@ -138,7 +138,7 @@ nColours=0
for col in $WM_COLOURS
do
colourList[$nColours]=$col
- ((nColours = $nColours + 1))
+ ((nColours = nColours + 1))
done
# Bashism: make pipe fail early.
@@ -156,9 +156,9 @@ colourPipe()
if tty -s <&1 # [ "$1" ]
then
(
- while read line
+ while read -r line
do
- setterm -foreground $1
+ setterm -foreground "$1"
echo "$line"
done
setterm -foreground default
@@ -200,17 +200,17 @@ do
colour="${colourList[$colourIndex]}"
if [ "$host" = "$HOST" ]; then
- eval $* 2>&1 | colourPipe "$colour"
+ eval "$*" 2>&1 | colourPipe "$colour"
else
- ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" \
+ ssh "$host" "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" \
2>&1 | colourPipe "$colour"
fi
retval=$?
else
if [ "$host" = "$HOST" ]; then
- eval $* 2>&1
+ eval "$*" 2>&1
else
- ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" \
+ ssh "$host" "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" \
2>&1
fi
retval=$?
@@ -220,10 +220,10 @@ do
rm -f "$lockFile" 2>/dev/null
exit $retval
fi
- i=$(expr $i + 1)
+ i=$((i + 1))
# Cycle through colours. Note: outside lock clause!
- colourIndex=$(expr $colourIndex + 1)
+ colourIndex=$((colourIndex + 1))
[ "$colourIndex" -lt "$nColours" ] || colourIndex=0
done
diff --git a/wmake/wmakeSchedulerUptime b/wmake/wmakeSchedulerUptime
index 2fb71d4881..1054e0b7f0 100755
--- a/wmake/wmakeSchedulerUptime
+++ b/wmake/wmakeSchedulerUptime
@@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
-# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
+# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@@ -67,23 +67,22 @@ error() {
}
# csh sets HOST, bash sets HOSTNAME
-: ${HOST:=$HOSTNAME}
+: "${HOST:=$HOSTNAME}"
-lockDir=$HOME/.$WM_PROJECT/.wmake
# Fallback - 1 core on current host
-: ${WM_HOSTS:=$HOST:1}
+: "${WM_HOSTS:=$HOST:1}"
# Count the total number of slots available and exit
if [ "$1" = "-count" ]
then
- expr $(
+ (( $(
for slotGroup in $WM_HOSTS
do
n=${slotGroup##*:}
[ "$n" = "${slotGroup%%:*}" ] && n=1 # Missing ':'
echo "+ ${n:-1}"
done
- )
+ ) ))
exit 0
fi
@@ -142,7 +141,7 @@ case $sourceFoam in
esac
# Quote double-quotes for remote command line
-rcmd=$(echo $* | sed -e s/\"/\'\"\'/g)
+rcmd=${*//\"/\'\"\'}
# The same, without forking (not ksh, maybe not /bin/sh either)
# rcmd=$(while [ "$#" -gt 0 ]; do echo "${1//\"/'\"'}"; shift; done)
@@ -153,7 +152,7 @@ nColours=0
for col in $WM_COLOURS
do
colourList[$nColours]=$col
- ((nColours = $nColours + 1))
+ ((nColours = nColours + 1))
done
# Bashism: make pipe fail early.
@@ -170,9 +169,9 @@ colourPipe()
if [ "$1" ]
then
(
- while read line
+ while read -r line
do
- setterm -foreground $1
+ setterm -foreground "$1"
echo "$line"
done
setterm -foreground default
@@ -222,11 +221,11 @@ do
# Determine load
if [ "$host" = "$HOST" ]; then
- stat=`uptime`
+ stat=$(uptime)
else
- stat=`ssh $host uptime`
+ stat=$(ssh "$host" uptime)
fi
- load=`echo "$stat" | sed -e 's/.*average:[^0-9.]*\([0-9.]*\).*/\1/'`
+ load=$(echo "$stat" | sed -e 's/.*average:[^0-9.]*\([0-9.]*\).*/\1/')
#echo "$Script: Machine:$host load:$load allowed:$WM_NCOMPPROCS nprocs:$nprocs"
@@ -242,18 +241,18 @@ do
echo "$Script: Machine:$host Starting:$*"
if [ "$host" = "$HOST" ]; then
- eval $* 2>&1 | colourPipe "$colour"
+ eval "$*" 2>&1 | colourPipe "$colour"
else
- ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 \
+ ssh "$host" "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 \
| colourPipe "$colour"
fi
retval=$?
else
echo "$Script: Machine:$host Starting:$*"
if [ "$host" = "$HOST" ]; then
- eval $* 2>&1
+ eval "$*" 2>&1
else
- ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1
+ ssh "$host" "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1
fi
retval=$?
fi
@@ -262,7 +261,7 @@ do
# Cycle through colours. Note: outside lock clause!
- colourIndex=$(expr $colourIndex + 1)
+ colourIndex=$((colourIndex + 1))
[ "$colourIndex" -lt "$nColours" ] || colourIndex=0
done
diff --git a/wmake/wrmdep b/wmake/wrmdep
index 2e51139283..644fab0848 100755
--- a/wmake/wrmdep
+++ b/wmake/wrmdep
@@ -54,6 +54,7 @@
Script=${0##*/}
# Source the wmake functions
+# shellcheck source=scripts/wmakeFunctions
. ${0%/*}/scripts/wmakeFunctions
usage() {
@@ -146,16 +147,16 @@ files)
# With the -a/-all option replace the current platform with a wildcard
if [ "$all" = "all" ]
then
- objectsDir=$(echo $objectsDir | sed s%$WM_OPTIONS%*% )
+ objectsDir=$(echo "$objectsDir" | sed s%"$WM_OPTIONS"%*% )
fi
if [ "$#" -eq 0 ]
then
echo "removing all .dep files ..."
- find $objectsDir -name '*.dep' -print | xargs -t rm 2>/dev/null
+ find "$objectsDir" -name '*.dep' -print0 | xargs -0t rm 2>/dev/null
else
echo "removing .dep files referring to $1 ..."
- find $objectsDir -name '*.dep' -exec grep -q "$1" '{}' \; \
+ find "$objectsDir" -name '*.dep' -exec grep -q "$1" '{}' \; \
-exec rm '{}' \; -print
fi
@@ -170,9 +171,9 @@ oldFolders)
for checkDir
do
- findObjectDir $checkDir
+ findObjectDir "$checkDir"
- if [ -d $objectsDir ]
+ if [ -d "$objectsDir" ]
then
echo " searching: $objectsDir"
else
@@ -180,15 +181,15 @@ oldFolders)
continue
fi
- find $objectsDir -name '*.dep' -print | while read depFile
+ find "$objectsDir" -name '*.dep' -print | while read -r depFile
do
- depToSource $depFile
+ depToSource "$depFile"
# Check C++ or Flex source file exists
if [ ! -r "$sourceFile" ];
then
echo " rm $depFile"
- rm -f $depFile 2>/dev/null
+ rm -f "$depFile" 2>/dev/null
fi
done
done
@@ -208,19 +209,19 @@ updateMode)
for filePathAndName in $fileNameList
do
- fileName=$(basename $filePathAndName)
+ fileName=$(basename "$filePathAndName")
echo " 'src': $fileName"
- cd src
- $Script -a $fileName
+ (
+ cd src || exit
+ $Script -a "$fileName"
- echo " 'applications': $fileName"
- cd ../applications
- $Script -a $fileName
-
- cd ..
+ echo " 'applications': $fileName"
+ cd ../applications || exit
+ $Script -a "$fileName"
+ )
# Just in case, remove the symbolic link as the last step
- unlink $filePathAndName
+ unlink "$filePathAndName"
done
;;
diff --git a/wmake/wrmo b/wmake/wrmo
index 7b0e5639c2..a0fe20bd03 100755
--- a/wmake/wrmo
+++ b/wmake/wrmo
@@ -38,6 +38,7 @@
Script=${0##*/}
# Source the wmake functions
+# shellcheck source=scripts/wmakeFunctions
. ${0%/*}/scripts/wmakeFunctions
usage() {
@@ -100,16 +101,16 @@ findObjectDir .
# With the -a/-all option replace the current platform with a wildcard
if [ "$all" = "all" ]
then
- objectsDir=$(echo $objectsDir | sed s%$WM_OPTIONS%*% )
+ objectsDir=$(echo "$objectsDir" | sed s%"$WM_OPTIONS"%*% )
fi
if [ "$#" -eq 0 ]
then
echo "removing all .o files ..."
- find $objectsDir -name '*.o' -print | xargs -t rm 2>/dev/null
+ find "$objectsDir" -name '*.o' -print0 | xargs -0t rm 2>/dev/null
else
echo "removing .o files corresponding to $1 ..."
- rm $objectsDir/${1%%.*}.o
+ rm "$objectsDir/${1%%.*}.o"
fi