1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
#!/bin/sh
set -e
fatal() { printf %s\\n "$0: $*" >&2; exit 1; }
. /usr/share/debconf/confmodule
db_version 2.0 || fatal "need DebConf 2.0 or later"
# Usage: y=`quote_backslashes "$x"`
# Quotes each backslash in $x with another backslash, outputs result.
quote_backslashes() {
echo -n "$1" | sed 's,\\,\\\\,g'
}
newline='
'
run_as_daemon() {
db_get ddclient/method
[ "${RET}" != "Web-based IP discovery service" ] || return 0
db_get ddclient/run_mode
[ "${RET}" = "As a daemon" ]
}
write_ddclient_conf() {
# get the values from the debconf database
db_get ddclient/protocol
protocol="$RET"
db_get ddclient/server
server=${RET:+ \\${newline}server=${RET}}
db_get ddclient/names
names="$RET"
db_get ddclient/username
username="$RET"
db_get ddclient/password
password=$(echo "$RET"|sed -e "s/'/\\\\'/g")
db_get ddclient/method
case ${RET} in
"Web-based IP discovery service")
db_get ddclient/web-url
[ -n "${RET}" ] || db_get ddclient/web
use="web, web=${RET%% *}"
;;
"Network interface")
db_get ddclient/interface
use="if, if=${RET}"
;;
*) fatal "unsupported IP discovery method: ${RET}";;
esac
db_get ddclient/proxy
[ -n "${RET}" ] && proxy="${newline}proxy=${RET}${newline}" || proxy=
# create configuration file /etc/ddclient.conf
config=`mktemp /etc/ddclient.conf.XXXXXX`
trap 'rm -f "$config"; exit 1' HUP INT QUIT TERM
password_quoted=`quote_backslashes "$password"`
cat <<EOF >>"$config"
# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf
$proxy
protocol=$protocol \\
use=$use$server \\
login=$username \\
password='$password_quoted' \\
$names
EOF
mv "$config" /etc/ddclient.conf
}
write_etc_default_ddclient() {
db_get ddclient/daemon_interval
daemon_interval="$RET"
run_as_daemon && run_ipup=false || run_ipup=true
temp=`mktemp /etc/default/ddclient.XXXXXX`
trap 'rm -f "$temp"; exit 1' HUP INT QUIT TERM
cat <<EOF >"$temp"
# Configuration for ddclient scripts
# generated from debconf on $(date)
#
# /etc/default/ddclient
# Set to "true" if ddclient should be run every time DHCP client ('dhclient'
# from package isc-dhcp-client) updates the systems IP address.
run_dhclient="false"
# Set to "true" if ddclient should be run every time a new ppp connection is
# established. This might be useful, if you are using dial-on-demand.
run_ipup="$run_ipup"
# Set the time interval between the updates of the dynamic DNS name in seconds.
# This option only takes effect if the ddclient runs in daemon mode.
daemon_interval="$daemon_interval"
EOF
mv "$temp" /etc/default/ddclient
}
case "$1" in
# 'reconfigure' is here because of this comment from debconf-devel(7):
#
# Make your postinst script accept a first parameter of
# "reconfigure". It can treat it just like "configure". This
# will be used in a later version of debconf to let postinsts
# know when they are reconfigured.
configure|reconfigure)
[ -f /etc/ddclient.conf ] || write_ddclient_conf
[ -f /etc/default/ddclient ] || write_etc_default_ddclient
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 0
;;
esac
if run_as_daemon; then
# We can't use the DEBHELPER magic comment to enable and start the
# service because of the --no-enable --no-start options in
# debian/rules. Instead we copy the code that would have been
# generated had those options not been passed.
case $1 in
configure|abort-upgrade|abort-deconfigure|abort-remove)
#### Begin part generated by dh_installinit/13.11.1
if [ -z "${DPKG_ROOT:-}" ] && [ -x "/etc/init.d/ddclient" ]; then
update-rc.d ddclient defaults >/dev/null
if [ -n "$2" ]; then
_dh_action=restart
else
_dh_action=start
fi
invoke-rc.d --skip-systemd-native ddclient $_dh_action || exit 1
fi
#### End part generated by dh_installinit/13.11.1
#### Begin 1st part generated by dh_installsystemd/13.11.1
# The following line should be removed in trixie or trixie+1
deb-systemd-helper unmask 'ddclient.service' >/dev/null || true
# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled 'ddclient.service'; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable 'ddclient.service' >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state 'ddclient.service' >/dev/null || true
fi
#### End 1st part generated by dh_installsystemd/13.11.1
#### Begin 2nd part generated by dh_installsystemd/13.11.1
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
if [ -n "$2" ]; then
_dh_action=restart
else
_dh_action=start
fi
deb-systemd-invoke $_dh_action 'ddclient.service' >/dev/null || true
fi
#### End 2nd part generated by dh_installsystemd/13.11.1
;;
esac
else
# The following magic comment (see dh_installdeb(1)) will be
# replaced with code that will unconditionally disable the service
# due to the --no-enable --no-start options in debian/rules.
#DEBHELPER#
fi
# Configuration was successful so remove the password from debconf as
# recommended by debconf-devel(7).
db_set ddclient/password ""
db_fset ddclient/password seen false
db_set ddclient/password-repeat ""
db_fset ddclient/password-repeat seen false
db_stop
exit 0
|