#!/bin/bash # set variables scriptversion="1.6" defaultenvfile=".env.dist" if [ ! -z $1 ] then dir=$1 endpoint=$(basename ${dir}) # set up log file location suggestion log1="/var/log/dnsupdater/${endpoint}.json" log2="${dir}/log.json" else echo "### ownDynDNS configuration script" wwwuserd="www-data" wwwgroupd="www-data" dir=$(pwd) while [ ! -f $dir/$defaultenvfile ] do echo "current directory does not contain ${defaultenvfile} !" read -p "enter directory where ownDynDNS is located: " dir done # source .env.dist source $dir/$defaultenvfile # set up log file location suggestions log1="$logFile" log2="/var/log/dnsupdater/log.json" fi envfile="${dir}/.env" ### main script #echo "found ${defaultenvfile}. using current directory" read -p "enter a custom username for dns updates [random]: " user user=${user:-$(tr -dc A-Za-z0-9 $htaccess << EOM Order allow,deny Deny from all envfile EOM if [ -z $endpoint ] then rm .htaccess.example fi ;; 3) mv .htaccess{.example,} ;; *) if [ -z $endpoint ] then rm .htaccess.example fi ;; esac ### nginx htaccess equivalent message echo "if you are using nginx please read the docs about how to disable access to certain files and folders.\nyou might add a location block to the beginning of your site config as follows:" echo -e " location ~* (env|log|json) {\n deny all;\n return 404;\n }" read -p "do you wish to enable result return? [y/N]: " returnip echo "" if [[ ${returnip,,::1} == "y" ]] then #echo "enabling return ip" returnip="true" else #echo "disabling return ip" returnip="false" fi read -p "do you want to allow creation of new entries on the fly? [y/N]: " allowcreate echo "" if [[ ${allowcreate,,::1} == "y" ]] then #echo "enabling return ip" allowcreate="true" else #echo "disabling return ip" allowcreate="false" fi read -p "do you want to restrict updates to a specific domain entry? [Y/n]: " restrictdomain echo "" if [[ ${restrictdomain,,::1} == "n" ]] then restrictdomain="false" else restrictdomain="true" echo "enter the FQDN you want to restrict updates to. If you are using third\ level domains, e.g. nas.home.example.com you should only enter example.com" echo "use the \"host\" variable for nas.home in that case." echo "" read -p "domain or FQDN: " domain echo "" read -p "host if third level domain: " host echo "" fi ### create the .env file if [ -f $envfile ] then echo "${envfile} already exists!" read -p "overwrite? [y/N]: " overwrite echo "" if [[ ! ${overwrite,,::1} == y ]] then echo "script cancelled. exiting" echo "" exit 1 fi fi touch $envfile echo "# file created at $(date)" >$envfile echo "# by configuration script version ${scriptversion}" >> $envfile echo "username=\"${user}\"" >> $envfile echo "password=\"${pass}\"" >> $envfile echo "apiKey=\"${apikey}\"" >> $envfile echo "apiPassword=\"${apipass}\"" >> $envfile echo "customerId=\"${custid}\"" >> $envfile echo "debug=${debug}" >> $envfile echo "log=${log}" >> $envfile echo "logFile=${logfile}" >> $envfile echo "returnIp=${returnip}" >> $envfile echo "allowCreate=${allowcreate}" >> $envfile echo "restrictDomain=${restrictdomain}" >> $envfile if [ ! -z ${domain} ] then echo "domain=${domain}" >> $envfile fi if [ ! -z ${host} ] then echo "host=${host}" >> $envfile fi echo "created .env file at: ${envfile}" echo ""