From 49854a642cb621b5b1d9b731465c2a0fe86e2475 Mon Sep 17 00:00:00 2001 From: Damien DUPORTAL Date: Sun, 5 Feb 2017 12:49:48 +0100 Subject: [PATCH] Shellchecking and bash best practises Signed-off-by: Damien DUPORTAL Cleaning Signed-off-by: Damien DUPORTAL --- README.md | 5 +++-- setup-sshd | 5 +++-- tests/test_helpers.bash | 4 ++-- tests/tests.bats | 5 ++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0ce2484c..e87a8c31 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ See [Jenkins Distributed builds](https://wiki.jenkins-ci.org/display/JENKINS/Dis To run a Docker container - docker run jenkinsci/ssh-slave "" +```bash +docker run jenkinsci/ssh-slave "" +``` You'll then be able to connect this slave using ssh-slaves-plugin as "jenkins" with the matching private key. @@ -24,4 +26,3 @@ In _Environment_ field of the Docker Template (advanced section), just add: JENKINS_SLAVE_SSH_PUBKEY= Don't put quotes around the public key. You should be all set. - diff --git a/setup-sshd b/setup-sshd index cafe9bba..8ff2718e 100755 --- a/setup-sshd +++ b/setup-sshd @@ -1,5 +1,7 @@ #!/bin/bash +set -ex + # The MIT License # # Copyright (c) 2015, CloudBees, Inc. @@ -45,5 +47,4 @@ if [[ $# -gt 0 ]]; then exec "$@" fi fi -exec /usr/sbin/sshd -D $@ - +exec /usr/sbin/sshd -D "${@}" diff --git a/tests/test_helpers.bash b/tests/test_helpers.bash index c9863699..c57dbfe0 100644 --- a/tests/test_helpers.bash +++ b/tests/test_helpers.bash @@ -1,4 +1,4 @@ - +#!/bin/bash # check dependencies ( type docker &>/dev/null || ( echo "docker is not available"; exit 1 ) @@ -33,7 +33,7 @@ function retry { sleep $delay done - echo "Command \"$@\" failed $attempts times. Status: $status. Output: $output" + echo "Command \"$@\" failed $attempts times. Status: $status. Output: $output" false } diff --git a/tests/tests.bats b/tests/tests.bats index ab978688..4538c8b6 100644 --- a/tests/tests.bats +++ b/tests/tests.bats @@ -20,8 +20,8 @@ load keys } @test "clean test container" { - docker kill $SUT_CONTAINER &>/dev/null ||: - docker rm -fv $SUT_CONTAINER &>/dev/null ||: + docker kill "${SUT_CONTAINER}" &>/dev/null ||: + docker rm -fv "${SUT_CONTAINER}" &>/dev/null ||: } @test "create slave container" { @@ -100,4 +100,3 @@ function run_through_ssh { false \ ) } -