Shellcheck added to py.test and fixes

- Various minor quote fixes
- Optimized repeated echos into php conf for alpine
This commit is contained in:
diginc 2016-10-08 14:56:06 -05:00
parent beb364dfce
commit 21eee5a0ca
8 changed files with 36 additions and 20 deletions

View File

@ -7,4 +7,4 @@ python:
install:
- pip install -r requirements.txt
script: py.test -v
script: py.test -vv

View File

@ -1 +1 @@
py.test -v -f test/
py.test -vv -f test/

View File

@ -39,31 +39,33 @@ setup_php_env() {
}
setup_php_env_debian() {
sed -i "/bin-environment/ a\\\t\t\t\"ServerIP\" => \"${ServerIP}\"," $PHP_ENV_CONFIG
sed -i "/bin-environment/ a\\\t\t\t\"PHP_ERROR_LOG\" => \"${PHP_ERROR_LOG}\"," $PHP_ENV_CONFIG
sed -i "/bin-environment/ a\\\t\t\t\"ServerIP\" => \"${ServerIP}\"," "$PHP_ENV_CONFIG"
sed -i "/bin-environment/ a\\\t\t\t\"PHP_ERROR_LOG\" => \"${PHP_ERROR_LOG}\"," "$PHP_ENV_CONFIG"
if [ -z "$VIRTUAL_HOST" ] ; then
VIRTUAL_HOST="$ServerIP"
fi;
sed -i "/bin-environment/ a\\\t\t\t\"VIRTUAL_HOST\" => \"${VIRTUAL_HOST}\"," $PHP_ENV_CONFIG
sed -i "/bin-environment/ a\\\t\t\t\"VIRTUAL_HOST\" => \"${VIRTUAL_HOST}\"," "$PHP_ENV_CONFIG"
echo "Added ENV to php:"
grep -E '(VIRTUAL_HOST|ServerIP)' $PHP_ENV_CONFIG
grep -E '(VIRTUAL_HOST|ServerIP)' "$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"
}
test_configs() {
@ -96,5 +98,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/#donotcurl/g' "$(which gravity.sh)"; fi;
}

View File

@ -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}"

View File

@ -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"

View File

@ -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

13
test/test_shellcheck.py Normal file
View File

@ -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

View File

@ -14,7 +14,7 @@ sed -i 's|service dnsmasq start|dnsmasq -7 /etc/dnsmasq.d|g' alpine/gravity.sh
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