diff --git a/.travis.yml b/.travis.yml index 655f84e33..2ca3b2d23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ python: install: - pip install -r requirements.txt -script: py.test -v +script: py.test -vv diff --git a/autotest b/autotest index 3747cc0b0..6a02656dc 100755 --- a/autotest +++ b/autotest @@ -1 +1 @@ -py.test -v -f test/ +py.test -f ./test -v $@ diff --git a/common_start.sh b/common_start.sh index a89075947..7bf7f401a 100644 --- a/common_start.sh +++ b/common_start.sh @@ -41,30 +41,32 @@ setup_php_env_debian() { local php_error_line="\t\t\t\"PHP_ERROR_LOG\" => \"${PHP_ERROR_LOG}\"," # idempotent line additions - grep -q "$vhost_line" $PHP_ENV_CONFIG || \ - sed -i "/bin-environment/ a\\${vhost_line}" $PHP_ENV_CONFIG - grep -q "$serverip_line" $PHP_ENV_CONFIG || \ - sed -i "/bin-environment/ a\\${serverip_line}" $PHP_ENV_CONFIG - grep -q "$php_error_line" $PHP_ENV_CONFIG || \ - sed -i "/bin-environment/ a\\${php_error_line}" $PHP_ENV_CONFIG + grep -q "$vhost_line" "$PHP_ENV_CONFIG" || \ + sed -i "/bin-environment/ a\\${vhost_line}" "$PHP_ENV_CONFIG" + grep -q "$serverip_line" "$PHP_ENV_CONFIG" || \ + sed -i "/bin-environment/ a\\${serverip_line}" "$PHP_ENV_CONFIG" + grep -q "$php_error_line" "$PHP_ENV_CONFIG" || \ + sed -i "/bin-environment/ a\\${php_error_line}" "$PHP_ENV_CONFIG" echo "Added ENV to php:" - grep -E '(VIRTUAL_HOST|ServerIP|PHP_ERROR_LOG)' $PHP_ENV_CONFIG + grep -E '(VIRTUAL_HOST|ServerIP|PHP_ERROR_LOG)' "$PHP_ENV_CONFIG" } setup_php_env_alpine() { - echo "[www]" > $PHP_ENV_CONFIG; - echo "env[PATH] = ${PATH}" >> $PHP_ENV_CONFIG; - echo "env[PHP_ERROR_LOG] = ${PHP_ERROR_LOG}" >> $PHP_ENV_CONFIG; - echo "env[ServerIP] = ${ServerIP}" >> $PHP_ENV_CONFIG; + cat <<-EOF > "$PHP_ENV_CONFIG" + [www] + env[PATH] = ${PATH} + env[PHP_ERROR_LOG] = ${PHP_ERROR_LOG} + env[ServerIP] = ${ServerIP} + EOF if [ -z "$VIRTUAL_HOST" ] ; then VIRTUAL_HOST="$ServerIP" fi; - echo "env[VIRTUAL_HOST] = ${VIRTUAL_HOST}" >> $PHP_ENV_CONFIG; + echo "env[VIRTUAL_HOST] = ${VIRTUAL_HOST}" >> "$PHP_ENV_CONFIG"; echo "Added ENV to php:" - cat $PHP_ENV_CONFIG + cat "$PHP_ENV_CONFIG" } setup_ipv4_ipv6() { @@ -109,5 +111,5 @@ test_configs_alpine() { } test_framework_stubbing() { - if [ -n "$PYTEST" ] ; then sed -i 's/^gravity_spinup$/#donotcurl/g' `which gravity.sh`; fi; + if [ -n "$PYTEST" ] ; then sed -i 's/^gravity_spinup$/#gravity_spinup # DISABLED FOR PYTEST/g' "$(which gravity.sh)"; fi; } diff --git a/docker_dev.sh b/docker_dev.sh index 23a49970f..7116bc826 100755 --- a/docker_dev.sh +++ b/docker_dev.sh @@ -6,6 +6,7 @@ docker build -f debian.docker -t diginc/pi-hole:debian . IP=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1) # Alternative ports to not conflict with my real instance +# shellcheck disable=SC2068 docker run -it --rm --cap-add=NET_ADMIN \ -p 5053:53/tcp \ -p 5053:53/udp \ @@ -13,5 +14,5 @@ docker run -it --rm --cap-add=NET_ADMIN \ -e ServerIP="$IP" \ -e VIRTUAL_HOST='pihole.diginc.lan:5080' \ $@ \ - diginc/pi-hole:${image:-alpine} + diginc/pi-hole:"${image:-alpine}" diff --git a/docker_run.sh b/docker_run.sh index ea4d6e1c5..2a6799c55 100755 --- a/docker_run.sh +++ b/docker_run.sh @@ -1,11 +1,11 @@ #!/bin/bash IMAGE=${1:-'diginc/pi-hole:alpine'} NIC=${2:-'eth0'} -IP=$(ip addr show $NIC | grep "inet\b" | awk '{print $2}' | cut -d/ -f1) +IP=$(ip addr show "$NIC" | grep "inet\b" | awk '{print $2}' | cut -d/ -f1) # Default ports + daemonized docker container docker run -p 53:53/tcp -p 53:53/udp -p 80:80 \ --cap-add=NET_ADMIN \ -e ServerIP="$IP" \ --name pihole \ - -d $IMAGE + -d "$IMAGE" diff --git a/make_symlinks.sh b/make_symlinks.sh index c3b193048..cf4f91336 100755 --- a/make_symlinks.sh +++ b/make_symlinks.sh @@ -1,11 +1,11 @@ #!/bin/sh -e supportedTags='^(alpine|debian)$' -if ! (echo $1 | grep -Pq "$supportedTags") ; then +if ! (echo "$1" | grep -Pq "$supportedTags") ; then echo "$1 is not a supported tag"; exit 1; fi unlink docker-compose.yml unlink Dockerfile -ln -s doco-${1}.yml docker-compose.yml -ln -s ${1}.docker Dockerfile +ln -s "doco-${1}.yml" docker-compose.yml +ln -s "${1}.docker" Dockerfile diff --git a/test/test_shellcheck.py b/test/test_shellcheck.py new file mode 100644 index 000000000..eb2019443 --- /dev/null +++ b/test/test_shellcheck.py @@ -0,0 +1,13 @@ +import pytest +import testinfra + +run_local = testinfra.get_backend( + "local://" +).get_module("Command").run + +def test_scripts_pass_shellcheck(): + ''' Make sure shellcheck does not find anything wrong with our shell scripts ''' + shellcheck = "find . ! -path './pi-hole/*' -name '*.sh' -a ! -name 'gravity.sh' | while read file; do shellcheck $file; done;" + results = run_local(shellcheck) + print results.stdout + assert '' == results.stdout diff --git a/update.sh b/update.sh index 0039f537d..63c6eb948 100755 --- a/update.sh +++ b/update.sh @@ -10,7 +10,7 @@ pushd AdminLTE ; git describe --tags --abbrev=0 > ../AdminLTE_version.txt ; popd cron='./docker-pi-hole.cron' cp -f pi-hole/advanced/pihole.cron ${cron}; sed -i '/Update the ad sources/ i\# Your container name goes here:\nDOCKER_NAME=pihole\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n' ${cron}; -sed -i 's|/usr/local/bin/|docker exec $DOCKER_NAME |g' ${cron}; +sed -i "s|/usr/local/bin/|docker exec \$DOCKER_NAME |g" ${cron}; sed -i '/docker exec/ s|$| > /dev/null|g' ${cron}; # docker-pi-hole users update their docker images, not git code