From e37b326748ba94f0be1530bfe8b25329d5c58965 Mon Sep 17 00:00:00 2001 From: Peter Schiffer <3899107+pschiffe@users.noreply.github.com> Date: Tue, 19 Dec 2023 23:12:51 +0100 Subject: [PATCH] Tidy up scripts --- ansible-playbook.yml | 6 ++-- docker-compose.yml | 2 +- examples/kubernetes/admin-dashboard.yaml | 8 +++--- .../docker-entrypoint.sh | 2 +- .../docker-entrypoint.sh | 14 +++++----- pdns-recursor/docker-entrypoint.sh | 6 ++-- pdns/docker-entrypoint.sh | 28 +++++++++---------- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/ansible-playbook.yml b/ansible-playbook.yml index c108461..3869714 100644 --- a/ansible-playbook.yml +++ b/ansible-playbook.yml @@ -234,9 +234,9 @@ volumes: - /etc/localtime:/etc/localtime:ro env: - PDNS_ADMIN_SQLA_DB_PASSWORD: "'my-secret-pw'" - PDNS_VERSION: "4.8" - PDNS_API_KEY: "secret" + PDNS_ADMIN_SQLA_DB_PASSWORD: 'my-secret-pw' + PDNS_VERSION: '4.8' + PDNS_API_KEY: 'secret' tags: - pdns-admin diff --git a/docker-compose.yml b/docker-compose.yml index abae0bd..5ac721c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -103,7 +103,7 @@ services: volumes: - /etc/localtime:/etc/localtime:ro environment: - - PDNS_ADMIN_SQLA_DB_PASSWORD='my-secret-pw' + - PDNS_ADMIN_SQLA_DB_PASSWORD=my-secret-pw - PDNS_VERSION=4.8 - PDNS_API_KEY=secret depends_on: diff --git a/examples/kubernetes/admin-dashboard.yaml b/examples/kubernetes/admin-dashboard.yaml index bf19846..3728f34 100644 --- a/examples/kubernetes/admin-dashboard.yaml +++ b/examples/kubernetes/admin-dashboard.yaml @@ -43,18 +43,18 @@ spec: imagePullPolicy: IfNotPresent env: - name: PDNS_ADMIN_SQLA_DB_HOST - value: "'mariadb-pdns'" + value: "mariadb-pdns" - name: PDNS_ADMIN_SQLA_DB_PORT - value: "'3306'" + value: "3306" - name: PDNS_ADMIN_SQLA_DB_USER - value: "'root'" + value: "root" - name: PDNS_ADMIN_SQLA_DB_PASSWORD valueFrom: secretKeyRef: name: pdns-admin-secret key: quoted_mysql_password - name: PDNS_ADMIN_SQLA_DB_NAME - value: "'pdnsadmin'" + value: "pdnsadmin" - name: PDNS_API_URL value: "http://master-api-pdns:8081/" - name: PDNS_VERSION diff --git a/pdns-admin-static-ngoduykhanh/docker-entrypoint.sh b/pdns-admin-static-ngoduykhanh/docker-entrypoint.sh index c70a7cb..19df953 100755 --- a/pdns-admin-static-ngoduykhanh/docker-entrypoint.sh +++ b/pdns-admin-static-ngoduykhanh/docker-entrypoint.sh @@ -2,6 +2,6 @@ set -euo pipefail -subvars --prefix 'PDNS_ADMIN_STATIC_' < /pdns-nginx.conf.tpl > /etc/nginx/nginx.conf +subvars --prefix 'PDNS_ADMIN_STATIC_' < '/pdns-nginx.conf.tpl' > '/etc/nginx/nginx.conf' exec "$@" diff --git a/pdns-admin-uwsgi-ngoduykhanh/docker-entrypoint.sh b/pdns-admin-uwsgi-ngoduykhanh/docker-entrypoint.sh index b3e2fd8..f3906a9 100755 --- a/pdns-admin-uwsgi-ngoduykhanh/docker-entrypoint.sh +++ b/pdns-admin-uwsgi-ngoduykhanh/docker-entrypoint.sh @@ -32,7 +32,7 @@ PDNS_ADMIN_SECRET_KEY="$(cat /root/secret-key)" export PDNS_ADMIN_SECRET_KEY -subvars --prefix 'PDNS_ADMIN_' < /config.py.tpl > /opt/powerdns-admin/powerdnsadmin/default_config.py +subvars --prefix 'PDNS_ADMIN_' < '/config.py.tpl' > '/opt/powerdns-admin/powerdnsadmin/default_config.py' # Initialize DB if needed MYSQL_COMMAND="mysql -h ${PDNS_ADMIN_SQLA_DB_HOST} -P ${PDNS_ADMIN_SQLA_DB_PORT} -u ${PDNS_ADMIN_SQLA_DB_USER} -p${PDNS_ADMIN_SQLA_DB_PASSWORD}" @@ -47,14 +47,14 @@ $MYSQL_COMMAND -e "CREATE DATABASE IF NOT EXISTS ${PDNS_ADMIN_SQLA_DB_NAME}" flask db upgrade # initial settings if not available in the DB -$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME} -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_api_url', '${PDNS_API_URL//[\'\"]}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_api_url') LIMIT 1;" -$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME} -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_api_key', '${PDNS_API_KEY//[\'\"]}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_api_key') LIMIT 1;" -$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME} -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_version', '${PDNS_VERSION//[\'\"]}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_version') LIMIT 1;" +$MYSQL_COMMAND "${PDNS_ADMIN_SQLA_DB_NAME}" -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_api_url', '${PDNS_API_URL//[\'\"]}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_api_url') LIMIT 1;" +$MYSQL_COMMAND "${PDNS_ADMIN_SQLA_DB_NAME}" -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_api_key', '${PDNS_API_KEY//[\'\"]}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_api_key') LIMIT 1;" +$MYSQL_COMMAND "${PDNS_ADMIN_SQLA_DB_NAME}" -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_version', '${PDNS_VERSION//[\'\"]}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_version') LIMIT 1;" # update pdns api settings if env changed -$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME} -e "UPDATE setting SET value='${PDNS_API_URL//[\'\"]}' WHERE name='pdns_api_url';" -$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME} -e "UPDATE setting SET value='${PDNS_API_KEY//[\'\"]}' WHERE name='pdns_api_key';" -$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME} -e "UPDATE setting SET value='${PDNS_VERSION//[\'\"]}' WHERE name='pdns_version';" +$MYSQL_COMMAND "${PDNS_ADMIN_SQLA_DB_NAME}" -e "UPDATE setting SET value='${PDNS_API_URL//[\'\"]}' WHERE name='pdns_api_url';" +$MYSQL_COMMAND "${PDNS_ADMIN_SQLA_DB_NAME}" -e "UPDATE setting SET value='${PDNS_API_KEY//[\'\"]}' WHERE name='pdns_api_key';" +$MYSQL_COMMAND "${PDNS_ADMIN_SQLA_DB_NAME}" -e "UPDATE setting SET value='${PDNS_VERSION//[\'\"]}' WHERE name='pdns_version';" mkdir -p /run/uwsgi chown uwsgi: /run/uwsgi diff --git a/pdns-recursor/docker-entrypoint.sh b/pdns-recursor/docker-entrypoint.sh index de307b1..a7caca3 100755 --- a/pdns-recursor/docker-entrypoint.sh +++ b/pdns-recursor/docker-entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/sh -set -euo pipefail +set -eu # Configure base vars : "${PDNS_local_port:=53}" @@ -18,9 +18,9 @@ elif [ -f /etc/alpine-release ]; then fi # Create config file from template -subvars --prefix 'PDNS_' < /recursor.conf.tpl > $config_file +subvars --prefix 'PDNS_' < '/recursor.conf.tpl' > "${config_file}" # Fix config file ownership -chown ${pdns_user}: $config_file +chown "${pdns_user}:" "${config_file}" exec "$@" diff --git a/pdns/docker-entrypoint.sh b/pdns/docker-entrypoint.sh index 00dcf45..5a3f7e9 100755 --- a/pdns/docker-entrypoint.sh +++ b/pdns/docker-entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/sh -set -euo pipefail +set -eu # Configure mysql env vars : "${PDNS_gmysql_host:=${MYSQL_ENV_MYSQL_HOST:-mysql}}" @@ -14,23 +14,23 @@ fi # use first part of node name as database name suffix if [ "${NODE_NAME:-}" ]; then - NODE_NAME=$(echo ${NODE_NAME} | sed -e 's/\..*//' -e 's/-//') + NODE_NAME=$(echo "${NODE_NAME}" | sed -e 's/\..*//' -e 's/-//') PDNS_gmysql_dbname="${PDNS_gmysql_dbname}${NODE_NAME}" fi - export PDNS_gmysql_host PDNS_gmysql_port PDNS_gmysql_user PDNS_gmysql_password PDNS_gmysql_dbname -EXTRA="" + +EXTRA='' # Password Auth -if [ "${PDNS_gmysql_password}" != "" ]; then +if [ "${PDNS_gmysql_password}" ]; then EXTRA="${EXTRA} -p${PDNS_gmysql_password}" fi # Allow socket connections -if [ "${PDNS_gmysql_socket:-}" != "" ]; then - export PDNS_gmysql_host="localhost" +if [ "${PDNS_gmysql_socket:-}" ]; then + export PDNS_gmysql_host='localhost' EXTRA="${EXTRA} --socket=${PDNS_gmysql_socket}" fi @@ -61,17 +61,17 @@ if [ "$MYSQL_NUM_TABLE" -eq 0 ]; then $MYSQL_COMMAND -D "$PDNS_gmysql_dbname" < /usr/share/doc/pdns/4.3.0_to_4.7.0_schema.mysql.sql fi -if [ "${PDNS_superslave:-no}" == "yes" ]; then +if [ "${PDNS_superslave:-no}" = 'yes' ]; then # Configure supermasters if needed if [ "${SUPERMASTER_IPS:-}" ]; then - $MYSQL_COMMAND -D "$PDNS_gmysql_dbname" -e "TRUNCATE supermasters;" + $MYSQL_COMMAND -D "$PDNS_gmysql_dbname" -e 'TRUNCATE supermasters;' MYSQL_INSERT_SUPERMASTERS='' - if [ "${SUPERMASTER_COUNT:-0}" == "0" ]; then + if [ "${SUPERMASTER_COUNT:-0}" -eq 0 ]; then SUPERMASTER_COUNT=10 fi - i=1; while [ $i -le ${SUPERMASTER_COUNT} ]; do - SUPERMASTER_HOST=$(echo ${SUPERMASTER_HOSTS:-} | awk -v col="$i" '{ print $col }') - SUPERMASTER_IP=$(echo ${SUPERMASTER_IPS} | awk -v col="$i" '{ print $col }') + i=1; while [ $i -le "${SUPERMASTER_COUNT}" ]; do + SUPERMASTER_HOST=$(echo "${SUPERMASTER_HOSTS:-}" | awk -v col="$i" '{ print $col }') + SUPERMASTER_IP=$(echo "${SUPERMASTER_IPS}" | awk -v col="$i" '{ print $col }') if [ -z "${SUPERMASTER_HOST:-}" ]; then SUPERMASTER_HOST=$(hostname -f) fi @@ -85,6 +85,6 @@ if [ "${PDNS_superslave:-no}" == "yes" ]; then fi # Create config file from template -subvars --prefix 'PDNS_' < /pdns.conf.tpl > /etc/pdns/pdns.conf +subvars --prefix 'PDNS_' < '/pdns.conf.tpl' > '/etc/pdns/pdns.conf' exec "$@"