Skip to content

Commit 5de5106

Browse files
committed
De-lint shell scripts with shellcheck
Safer and cleaner shell scripts courtesy of shellcheck
1 parent 396ed0b commit 5de5106

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

build.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959
#
6060
# REQUIRES
6161
# FoBiS.py : https://github.com/szaghi/FoBiS [version 1.2.5 or later required]
62-
# FORD : https://github.com/cmacmackin/ford [version 3.0.2 is the one tested]
62+
# FORD : https://github.com/cmacmackin/ford [version 4.0.0 or later]
6363
#
6464
# AUTHOR
6565
# Jacob Williams : 12/27/2014
6666
#
6767

68-
set -e
68+
set -o errexit
6969

7070
FORDMD='json-fortran.md' # FORD options file for building documentation
7171
DOCDIR='./doc/' # build directory for documentation
@@ -97,7 +97,7 @@ FCOMPILER='gnu' #Set default compiler to gfortran
9797
# e.g., "./build.sh --compiler intel --coverage no --compiler gnu --coverage" will
9898
# perform the build with the GFORTRAN compiler, and coverage analysis
9999

100-
script_name="$(basename $0)"
100+
script_name="$(basename "$0")"
101101

102102
# usage message
103103
print_usage () {
@@ -213,7 +213,7 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
213213
shift
214214
;;
215215
no|No|NO)
216-
JF_SKIP_DOCSS="no"
216+
JF_SKIP_DOCS="no"
217217
shift
218218
;;
219219
*)
@@ -226,7 +226,7 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
226226
exit 0
227227
;;
228228
--clean)
229-
rm -r src{,/tests}/*.o $DOCDIR* $LIBDIR* $BINDIR* *.gcov*
229+
rm -r -- src{,/tests}/*.o $DOCDIR* $LIBDIR* $BINDIR* *.gcov*
230230
;;
231231
*)
232232
echo "Unknown flag, \"$1\", passed to ${script_name}!" 2>&1
@@ -254,12 +254,12 @@ fi
254254

255255
if [[ $FCOMPILER == custom ]]; then
256256
echo "Trying to compile with custom compiler, $FC"
257-
CUSTOM="-fc $FC"
257+
CUSTOM=("-fc" "$FC")
258258
fi
259259

260260
if [[ $TRY_UNICODE == [yY]* ]]; then
261261
echo "Trying to compile library with Unicode/UCS4 support"
262-
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS}" -dbld "${BINDIR}" -s "${INTROSPECDIR}" -dmod ./ -dobj ./ -t ${UCS4TESTCODE} -o ${UCS4TESTCODE%.f90} -colors
262+
FoBiS.py build -ch -compiler "${FCOMPILER}" "${CUSTOM[@]}" -cflags "${FCOMPILERFLAGS}" -dbld "${BINDIR}" -s "${INTROSPECDIR}" -dmod ./ -dobj ./ -t "${UCS4TESTCODE}" -o "${UCS4TESTCODE%.f90}" -colors
263263
if "${BINDIR}/${UCS4TESTCODE%.f90}"; then
264264
DEFINES="-DUSE_UCS4 -Wunused-function"
265265
fi
@@ -269,7 +269,7 @@ fi
269269
echo ""
270270
echo "Building library..."
271271

272-
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS} ${DEFINES}" ${COVERAGE} ${PROFILING} -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors
272+
FoBiS.py build -ch -compiler ${FCOMPILER} "${CUSTOM[@]}" -cflags "${FCOMPILERFLAGS} ${DEFINES}" ${COVERAGE} ${PROFILING} -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors
273273

274274
#build the unit tests (uses the above library):
275275
if [[ $JF_SKIP_TESTS != [yY]* ]]; then
@@ -282,7 +282,7 @@ if [[ $JF_SKIP_TESTS != [yY]* ]]; then
282282
for TEST in "${TESTDIR%/}"/jf_test_*.[fF]90; do
283283
THIS_TEST=${TEST##*/}
284284
echo "Build ${THIS_TEST%.[fF]90}"
285-
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS} ${DEFINES}" ${COVERAGE} ${PROFILING} -dbld ${BINDIR} -s ${TESTDIR} -i ${LIBDIR} -libs ${LIBDIR}/${LIBOUT} -dmod ./ -dobj ./ -t ${THIS_TEST} -o ${THIS_TEST%.[fF]90} -colors
285+
FoBiS.py build -ch -compiler ${FCOMPILER} "${CUSTOM[@]}" -cflags "${FCOMPILERFLAGS} ${DEFINES}" ${COVERAGE} ${PROFILING} -dbld "${BINDIR}" -s "${TESTDIR}" -i "${LIBDIR}" -libs "${LIBDIR}/${LIBOUT}" -dmod ./ -dobj ./ -t "${THIS_TEST}" -o "${THIS_TEST%.[fF]90}" -colors
286286
done
287287
else
288288
echo "Skip building the unit tests since \$JF_SKIP_TESTS has been set to 'true'."
@@ -292,17 +292,17 @@ fi
292292
echo ""
293293
if [[ $JF_SKIP_TESTS != [yY]* ]] ; then
294294
echo "Running tests..."
295-
cd "$BINDIR"
296295
OLD_IGNORES="$GLOBIGNORE"
296+
# run next commands in subshell to avoid `cd -`
297+
(cd "$BINDIR"
297298
GLOBIGNORE='*.*'
298299
#
299300
for TEST in jf_test_*; do
300301
# It would be nice to run json output printed to stdout through jsonlint, however,
301302
# some tests output more than one json structure and these need to be split
302303
echo "Running ${TEST}"
303-
./${TEST}
304-
done
305-
cd -
304+
"./${TEST}"
305+
done)
306306
GLOBIGNORE="$OLD_IGNORES"
307307
if [[ $CODE_COVERAGE = [yY]* ]] ; then
308308
for SRCFILE in json_string_utilities.F90 json_value_module.F90 json_file_module.F90 ; do

deploy.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
# If running under travis-ci this will automatically deploy updates to the master branch's
44
# documentation on build events for the master branch, and will add/update documentation for
55
# any new/updated tags that are pushed.
6+
set -o errexit
7+
set -o verbose
68
if [ "$TRAVIS" ]; then #running under travis
79
if $TRAVIS_SECURE_ENV_VARS ; then
810
# only try to update master's development documentation
911
if [ "$TRAVIS_BRANCH" = "master" ] && \
1012
[ "$TRAVIS_PULL_REQUEST" = "false" ] && \
11-
[ "$(ls -A $TRAVIS_BUILD_DIR/doc)" ] ; then #not empty
12-
git clone --branch=gh-pages https://${GH_TOKEN}@github.com/$TRAVIS_REPO_SLUG gh-pages
13-
cd gh-pages
13+
[ "$(ls -A "$TRAVIS_BUILD_DIR/doc")" ] ; then #not empty
14+
git clone --branch=gh-pages "https://${GH_TOKEN}@github.com/$TRAVIS_REPO_SLUG" gh-pages
15+
cd gh-pages || exit 1
1416
rm -r css favicon.png fonts index.html interface js lists media module page proc \
1517
program search.html sourcefile src tipuesearch type
1618
cp -r "$TRAVIS_BUILD_DIR"/doc/* .
@@ -19,13 +21,13 @@ if [ "$TRAVIS" ]; then #running under travis
1921
git push origin gh-pages
2022
fi
2123
# If publishing a new/updated tag, deploy it's documentation
22-
if [ "$TRAVIS_TAG" ] && [ "$(ls -A $TRAVIS_BUILD_DIR/doc)" ] ; then #not empty
23-
cd "$TRAVIS_BUILD_DIR"
24-
git clone --branch=gh-pages https://${GH_TOKEN}@github.com/$TRAVIS_REPO_SLUG gh-pages
24+
if [ "$TRAVIS_TAG" ] && [ "$(ls -A "$TRAVIS_BUILD_DIR/doc")" ] ; then #not empty
25+
cd "$TRAVIS_BUILD_DIR" || exit 1
26+
git clone --branch=gh-pages "https://${GH_TOKEN}@github.com/$TRAVIS_REPO_SLUG" gh-pages
2527
sed "1 s/^/version: ${TRAVIS_TAG}\n/" json-fortran.md > json-fortran.tagged.md
2628
# rebuild FORD documentation without pages, with version info, wiping out any existing tag folder
2729
ford -o "gh-pages/$TRAVIS_TAG" json-fortran.tagged.md
28-
cd gh-pages
30+
cd gh-pages || exit 1
2931
git add -A # add all new files in $TRAVIS_TAG/
3032
git commit -m "Tag/release documentation updated by travis job $TRAVIS_JOB_NUMBER for tag $TRAVIS_TAG $TRAVIS_COMMIT"
3133
git push origin gh-pages

0 commit comments

Comments
 (0)