#!/bin/sh set -e if [ "$BANDWIDTHD_PACKAGE_DEBUG" != "" ]; then echo "bandwidthd-pgsql.postinst: $*" set -x fi # Source debconf library in postinst. . /usr/share/debconf/confmodule # Source dbconfig-common library. . /usr/share/dbconfig-common/dpkg/postinst.pgsql # Calling dbc first because we are using the answers later dbc_first_version="2.0.1+cvs20050208-12" dbc_generate_include=php:/etc/bandwidthd/debian-db.php dbc_generate_include_owner="www-data:www-data" dbc_generate_include_perms="660" dbc_go bandwidthd-pgsql $@ # ------------------------------------------------------------- # Create bandwidthd.conf based on debconf data, and install it. # ------------------------------------------------------------- if [ "$1" = "configure" ]; then db_get bandwidthd/dev || true DEV=$RET db_get bandwidthd/subnet || true SUBNETS=$RET # ATTENTION! $SUBNETS needs to be parsed and split. # Example contents: 192.168.1.0/24, 172.20.0.0 255.255.0.0, 10.0.0.0/8 # Get pgsql-settings from dbconfig-common. if [ -f /etc/dbconfig-common/bandwidthd-pgsql.conf ]; then . /etc/dbconfig-common/bandwidthd-pgsql.conf fi if [ "$dbc_install" = "true" ]; then PGSQL_USER=$dbc_dbuser PGSQL_PASS=$dbc_dbpass PGSQL_DB=$dbc_dbname PGSQL_HOST=$dbc_dbserver if [ -z "$PGSQL_HOST" ]; then PGSQL_HOST="localhost" fi PGSQL_PORT=$dbc_dbport if [ -z "$PGSQL_PORT" ]; then PGSQL_PORT=5432 fi else PGSQL_USER="bwduser" PGSQL_PASS="bwdpass" PGSQL_DB="bwddb" PGSQL_HOST="localhost" PGSQL_PORT=5432 fi db_get bandwidthd-pgsql/sensorid || true SENSORID=$RET db_get bandwidthd/promisc || true PROMISC=$RET if [ "$BANDWIDTHD_PACKAGE_DEBUG" != "" ]; then echo "This is the bandwidthd postinst script reporting debconf settings:" echo "dev: $DEV" echo "subnets: $SUBNETS" echo "promisc: $PROMISC" fi # parse a bandwidthd.conf template and insert dev, subnet and # recover_cdf rules, then use ucf to install config file. TEMPDIR=$(mktemp -d) TMPFILE=$TEMPDIR/bandwidthd.conf cp /usr/share/bandwidthd-pgsql/bandwidthd-pgsql.conf.template $TMPFILE chmod 640 $TMPFILE RULE='s%^#DEBCONF_DEVS#$%dev "'$DEV'"%' sed -ie "$RULE" $TMPFILE PARSED_SUBNETS=$(echo $SUBNETS | sed -e 's/, */:/g') #PARSED_SUBNETS=$(echo $PARSED_SUBNETS | sed -e 's/^/subnet /') OLDIFS=$IFS IFS=":" for subnet in $PARSED_SUBNETS ; do # CIDR and dotted-quad subnets have different syntax: # subnet 1.2.3.4/24 # subnet 4.3.2.1 255.255.255.0 subnet=$(echo $subnet | sed -e 's#/\(.*\..*\)# \1#') RULE='s%^#DEBCONF_SUBNETS#$%subnet '$subnet'\ #DEBCONF_SUBNETS#%' sed -ie "$RULE" $TMPFILE done RULE='s%^#DEBCONF_SUBNETS#$%%' sed -ie "$RULE" $TMPFILE IFS=$OLDIFS RULE='s%^#DEBCONF_PGSQL#$%pgsql_connect_string "user = '$PGSQL_USER' password = '$PGSQL_PASS' dbname = '$PGSQL_DB' host = '$PGSQL_HOST'"%' sed -ie "$RULE" $TMPFILE RULE='s%^#DEBCONF_SENSORID#$%sensor_id "'$SENSORID'"%' sed -ie "$RULE" $TMPFILE RULE='s%^#DEBCONF_PROMISC#$%promiscuous '$PROMISC'%' sed -ie "$RULE" $TMPFILE # Install new configuration... chmod 640 $TMPFILE ucf --debconf-ok $TMPFILE /etc/bandwidthd/bandwidthd.conf chmod 640 /etc/bandwidthd/bandwidthd.conf # create new password config file for psql (used in weekly cron script) TMPFILE=$TEMPDIR/pgpass echo "$PGSQL_HOST:$PGSQL_PORT:$PGSQL_DB:$PGSQL_USER:$PGSQL_PASS" > $TMPFILE chown root:root $TMPFILE chmod 0600 $TMPFILE ucf --debconf-ok $TMPFILE /etc/bandwidthd/.pgpass # clean up rm -rf $TEMPDIR # Stop debhelper, we are done. db_stop fi # "$1" = "configure" # ---------------------------------------------------------------------- # move configuration file to new location for apache 2.4 dpkg-maintscript-helper mv_conffile \ /etc/apache2/conf.d/bandwidthd /etc/apache2/conf-available/bandwidthd.conf 2.0.1+cvs20090917-6~ bandwidthd-pgsql -- "$@" # From http://wiki.debian.org/Apache/PackagingFor24 : # "In your postinst maintainer script invoke the enconf handler on fresh installations." if [ -z "$2" ]; then if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then . /usr/share/apache2/apache2-maintscript-helper apache2_invoke enconf bandwidthd.conf fi fi # reload apache2 config for installed /bandwidthd alias. if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then . /usr/share/apache2/apache2-maintscript-helper apache2_reload fi # debhelper autoinserted stuff: # Automatically added by dh_installinit/13.15.3 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -z "${DPKG_ROOT:-}" ] && [ -x "/etc/init.d/bandwidthd" ]; then update-rc.d bandwidthd defaults >/dev/null if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi invoke-rc.d --skip-systemd-native bandwidthd $_dh_action || exit 1 fi fi # End automatically added section # Automatically added by dh_installsystemd/13.15.3 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then 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 'bandwidthd.service' >/dev/null || true fi fi # End automatically added section