Setup PowerDNS Admin Part 2

#!/bin/bash

ROOT_MYSQL_PASSWORD="penguin"
POWERUSER_MYSQL_PASSWORD="penguin"
domain_name=tuxmail.io
POWERDNS_ADMIN_PASSWORD_PLAIN_TEXT="penguin"
domain_name=tuxmail.io
user1_email_address=user1

# Import powerdns scheme structure

mysql -u root -p$ROOT_MYSQL_PASSWORD powerdns < /var/www/powerdns/sql/poweradmin-mysql-db-structure.sql

# Create a user for PowerDNS with authority to modify PowerDNS database

mysql -u root -p$ROOT_MYSQL_PASSWORD powerdns < "/var/www/powerdns/inc/config.inc.php"
<?php
\$db_host = 'localhost';
\$db_name = 'powerdns';
\$db_user = 'poweruser';
\$db_pass = '$POWERUSER_MYSQL_PASSWORD';
\$db_type = 'mysql';

\$session_key = '$SESSION_ID';

\$iface_lang = 'en_EN';

\$dns_hostmaster = 'hostmaster.$domain_name';
\$dns_ns1 = 'ns1.$domain_name';
\$dns_ns2 = 'ns1.$domain_name';

\$ignore_install_dir = true;
EOF

# Remove the install files for security reasons

rm -rf /var/www/powerdns/install

# We have to generate an encrypted password for the admin user of PowerDNS Admin

s=`htpasswd -nbBC 12 "" "$POWERDNS_ADMIN_PASSWORD_PLAIN_TEXT"`;

# Remove the : from the output of htpasswd

POWERDNS_ADMIN_PASSWORD=${s:1}

# Set admin password for PowerDNS Admin

mysql -u root -p$ROOT_MYSQL_PASSWORD powerdns < /dev/null; do echo "DNS lookup for powerdns.$domain_name not successful yet (DNS server needs to respond for certbot to get certificate). Sleeping for 5 seconds..."; sleep 5; done

# Run the following command to obtain a Let’s Encrypt TLS certificate

printf "1\n" | certbot --non-interactive --apache --agree-tos --redirect --hsts --staple-ocsp --email "$user1_email_address@$domain_name" -d powerdns.$domain_name

#http://powerdns.tuxmail.io/index.php