summaryrefslogtreecommitdiffstats
path: root/debian/open-infrastructure-ddns-client.postinst
diff options
context:
space:
mode:
Diffstat (limited to 'debian/open-infrastructure-ddns-client.postinst')
-rwxr-xr-xdebian/open-infrastructure-ddns-client.postinst146
1 files changed, 146 insertions, 0 deletions
diff --git a/debian/open-infrastructure-ddns-client.postinst b/debian/open-infrastructure-ddns-client.postinst
new file mode 100755
index 0000000..afbda6c
--- /dev/null
+++ b/debian/open-infrastructure-ddns-client.postinst
@@ -0,0 +1,146 @@
+#!/bin/sh
+
+set -e
+
+. /usr/share/debconf/confmodule
+
+CONFFILE="/etc/network-tools/config/ddns-client.conf"
+
+case "${1}" in
+ configure)
+ db_get open-infrastructure-ddns-client/nameservers
+ NAMESERVERS="${RET}" # string
+
+ db_get open-infrastructure-ddns-client/zone
+ ZONE="${RET}" # string
+
+ db_get open-infrastructure-ddns-client/record
+ RECORD="${RET}" # string
+
+ db_get open-infrastructure-ddns-client/ttl
+ TTL="${RET:-60}" # string (w/o empty)
+
+ db_get open-infrastructure-ddns-client/tsig
+ TSIG="${RET}" # string (w/ empty)
+
+ db_stop
+
+ if [ ! -e "${CONFFILE}" ]
+ then
+ mkdir -p /etc/network-tools/config
+
+cat > "${CONFFILE}" << EOF
+# /etc/network-tools/config/ddns-client.conf
+
+NAMESERVERS="${NAMESERVERS}"
+ZONE="${ZONE}"
+RECORD="${RECORD}"
+TTL="${TTL}"
+TSIG_KEYFILE=""
+EOF
+
+ fi
+
+ cp -a -f "${CONFFILE}" "${CONFFILE}.tmp"
+
+ # If the admin deleted or commented some variables but then set
+ # them via debconf, (re-)add them to the config file.
+
+ test -z "${NAMESERVERS}" || \
+ grep -Eq '^ *NAMESERVERS=' "${CONFFILE}" || \
+ echo "NAMESERVERS=" >> "${CONFFILE}"
+
+ test -z "${ZONE}" || \
+ grep -Eq '^ *ZONE=' "${CONFFILE}" || \
+ echo "ZONE=" >> "${CONFFILE}"
+
+ test -z "${RECORD}" || \
+ grep -Eq '^ *RECORD=' "${CONFFILE}" || \
+ echo "RECORD=" >> "${CONFFILE}"
+
+ test -z "${TTL}" || \
+ grep -Eq '^ *TTL=' "${CONFFILE}" || \
+ echo "TTL=" >> "${CONFFILE}"
+
+ sed -e "s|^ *NAMESERVERS=.*|NAMESERVERS=\"${NAMESERVERS}\"|" \
+ -e "s|^ *ZONE=.*|ZONE=\"${ZONE}\"|" \
+ -e "s|^ *RECORD=.*|RECORD=\"${RECORD}\"|" \
+ -e "s|^ *TTL=.*|TTL=\"${TTL}\"|" \
+ < "${CONFFILE}" > "${CONFFILE}.tmp"
+
+ mv -f "${CONFFILE}.tmp" "${CONFFILE}"
+
+ if [ -n "${TSIG}" ]
+ then
+ case "${TSIG}" in
+ http*)
+ # tsig is a URL
+ if command -v wget "${TSIG}" -O /dev/null > /dev/null 2>&1
+ then
+ rm -f /etc/network-tools/tsig.key
+
+ wget "${TSIG}" -O /etc/network-tools/tsig.key
+ chmod 0600 /etc/network-tools/tsig.key
+
+ TSIG_FILE="/etc/network-tools/tsig.key"
+ elif command -v curl "${TSIG}" -o /dev/null > /dev/null 2>&1
+ then
+ rm -f /etc/network-tools/tsig.key
+
+ curl "${TSIG}" -o /etc/network-tools/tsig.key
+ chmod 0600 /etc/network-tools/tsig.key
+
+ TSIG_FILE="/etc/network-tools/tsig.key"
+ fi
+ ;;
+
+ *:*)
+ # tsig is a string
+ echo "${TSIG}" > /etc/network-tools/tsig.key
+ chmod 0600 /etc/network-tools/tsig.key
+
+ TSIG_FILE="/etc/network-tools/tsig.key"
+ ;;
+
+ */*)
+ # tsig is a path
+ TSIG_FILE="${TSIG}"
+ ;;
+
+ *)
+ echo "'${TSIG}' is neither a valid tsig, nor a path or URL to an existing file - ignoring"
+ ;;
+ esac
+ fi
+
+ if [ -n "${TSIG_FILE}" ]
+ then
+ cp -a -f "${CONFFILE}" "${CONFFILE}.tmp"
+
+ # If the admin deleted or commented some variables but then set
+ # them via debconf, (re-)add them to the config file.
+
+ test -z "${TSIG_FILE}" || \
+ grep -Eq '^ *TSIG_KEYFILE=' "${CONFFILE}" || \
+ echo "TSIG_KEYFILE=" >> "${CONFFILE}"
+
+ sed -e "s|^ *TSIG_KEYFILE=.*|TSIG_KEYFILE=\"${TSIG_FILE}\"|" \
+ < "${CONFFILE}" > "${CONFFILE}.tmp"
+
+ mv -f "${CONFFILE}.tmp" "${CONFFILE}"
+ fi
+ ;;
+
+ abort-upgrade|abort-remove|abort-deconfigure)
+
+ ;;
+
+ *)
+ echo "postinst called with unknown argument \`${1}'" >&2
+ exit 1
+ ;;
+esac
+
+#DEBHELPER#
+
+exit 0