inadyn confile file variable

This commit is contained in:
Bob Mottram 2018-05-12 13:30:47 +01:00
parent bd7f8b4a91
commit a3e6ce965c
1 changed files with 28 additions and 27 deletions

View File

@ -41,6 +41,7 @@ DDNS_PASSWORD=
INADYN_REPO="https://github.com/bashrc/inadyn"
INADYN_COMMIT='fadbe17f520d337dfb8d69ee4bf1fcaa23fce0d6'
INADYN_CONFIG_FILE=/etc/inadyn.conf
# web site used to obtain the external IP address of the system
GET_IP_ADDRESS_URL="checkip.two-dns.de"
@ -95,7 +96,7 @@ EXTERNAL_IP_SERVICES=( \
'http://httpbin.org/ip')
function update_inadyn_config {
if [ ! -f /etc/inadyn.conf ]; then
if [ ! -f "${INADYN_CONFIG_FILE}" ]; then
return
fi
@ -103,43 +104,43 @@ function update_inadyn_config {
return
fi
if ! grep -q "$DDNS_PROVIDER" /etc/inadyn.conf; then
if ! grep -q "$DDNS_PROVIDER" "${INADYN_CONFIG_FILE}"; then
# store any previous aliases
grep 'alias ' /etc/inadyn.conf > /tmp/inadyn_aliases
grep 'alias ' "${INADYN_CONFIG_FILE}" > /tmp/inadyn_aliases
# remove entry for any previous ddns
sed -i '/system /,$d' /etc/inadyn.conf
sed -i '/system /,$d' "${INADYN_CONFIG_FILE}"
# add the new provider
{ echo '';
echo "system $DDNS_PROVIDER";
echo ' ssl';
echo " checkip-url $GET_IP_ADDRESS_URL /"; } >> /etc/inadyn.conf
echo " checkip-url $GET_IP_ADDRESS_URL /"; } >> "${INADYN_CONFIG_FILE}"
if [ "$DDNS_USERNAME" ]; then
echo " username $DDNS_USERNAME" >> /etc/inadyn.conf
echo " username $DDNS_USERNAME" >> "${INADYN_CONFIG_FILE}"
fi
if [ "$DDNS_PASSWORD" ]; then
echo " password $DDNS_PASSWORD" >> /etc/inadyn.conf
echo " password $DDNS_PASSWORD" >> "${INADYN_CONFIG_FILE}"
fi
if [ -f /tmp/inadyn_aliases ]; then
cat /tmp/inadyn_aliases >> /etc/inadyn.conf
cat /tmp/inadyn_aliases >> "${INADYN_CONFIG_FILE}"
rm /tmp/inadyn_aliases
fi
else
# change username/password for an existing provider
if [ "$DDNS_USERNAME" ]; then
if grep -q " username " /etc/inadyn.conf; then
sed -i "s| username .*| username $DDNS_USERNAME|g" /etc/inadyn.conf
if grep -q " username " "${INADYN_CONFIG_FILE}"; then
sed -i "s| username .*| username $DDNS_USERNAME|g" "${INADYN_CONFIG_FILE}"
else
echo " username $DDNS_USERNAME" >> /etc/inadyn.conf
echo " username $DDNS_USERNAME" >> "${INADYN_CONFIG_FILE}"
fi
fi
if [ "$DDNS_PASSWORD" ]; then
if grep -q " password " /etc/inadyn.conf; then
sed -i "s| password .*| password $DDNS_PASSWORD|g" /etc/inadyn.conf
if grep -q " password " "${INADYN_CONFIG_FILE}"; then
sed -i "s| password .*| password $DDNS_PASSWORD|g" "${INADYN_CONFIG_FILE}"
else
echo " password $DDNS_PASSWORD" >> /etc/inadyn.conf
echo " password $DDNS_PASSWORD" >> "${INADYN_CONFIG_FILE}"
fi
fi
fi
@ -197,27 +198,27 @@ function add_ddns_domain {
if [[ "$DDNS_PROVIDER" == 'none' ]]; then
return
fi
if [ ! -f /etc/inadyn.conf ]; then
echo $'Unable to find inadyn configuration file /etc/inadyn.conf'
if [ ! -f "${INADYN_CONFIG_FILE}" ]; then
echo $'Unable to find inadyn configuration file "${INADYN_CONFIG_FILE}"'
exit 5745
fi
if ! grep -q "$DDNS_PROVIDER" /etc/inadyn.conf; then
if ! grep -q "$DDNS_PROVIDER" "${INADYN_CONFIG_FILE}"; then
{ echo '';
echo "system $DDNS_PROVIDER";
echo ' ssl';
echo " checkip-url $GET_IP_ADDRESS_URL /"; } >> /etc/inadyn.conf
echo " checkip-url $GET_IP_ADDRESS_URL /"; } >> "${INADYN_CONFIG_FILE}"
if [ $DDNS_USERNAME ]; then
echo " username $DDNS_USERNAME" >> /etc/inadyn.conf
echo " username $DDNS_USERNAME" >> "${INADYN_CONFIG_FILE}"
fi
if [ $DDNS_PASSWORD ]; then
echo " password $DDNS_PASSWORD" >> /etc/inadyn.conf
echo " password $DDNS_PASSWORD" >> "${INADYN_CONFIG_FILE}"
fi
fi
if ! grep -q "$CURRENT_DDNS_DOMAIN" /etc/inadyn.conf; then
echo " alias $CURRENT_DDNS_DOMAIN" >> /etc/inadyn.conf
if ! grep -q "$CURRENT_DDNS_DOMAIN" "${INADYN_CONFIG_FILE}"; then
echo " alias $CURRENT_DDNS_DOMAIN" >> "${INADYN_CONFIG_FILE}"
fi
chmod 600 /etc/inadyn.conf
chmod 600 "${INADYN_CONFIG_FILE}"
systemctl restart inadyn
systemctl daemon-reload
}
@ -234,13 +235,13 @@ function remove_ddns_domain {
if [[ "$DDNS_PROVIDER" == 'none' ]]; then
return
fi
if [ ! -f /etc/inadyn.conf ]; then
echo $'Unable to find inadyn configuration file /etc/inadyn.conf'
if [ ! -f "${INADYN_CONFIG_FILE}" ]; then
echo $'Unable to find inadyn configuration file "${INADYN_CONFIG_FILE}"'
exit 5745
fi
if grep -q "$CURRENT_DDNS_DOMAIN" /etc/inadyn.conf; then
if grep -q "$CURRENT_DDNS_DOMAIN" "${INADYN_CONFIG_FILE}"; then
systemctl stop inadyn
sed -i "/alias $CURRENT_DDNS_DOMAIN/d" /etc/inadyn.conf
sed -i "/alias $CURRENT_DDNS_DOMAIN/d" "${INADYN_CONFIG_FILE}"
systemctl start inadyn
systemctl daemon-reload
fi