|
@@ -1,77 +1,178 @@
|
|
|
-#! /bin/sh
|
|
|
-# $Id$
|
|
|
-# postinst script for ser-0.8.7
|
|
|
-#
|
|
|
-# see: dh_installdeb(1)
|
|
|
+#!/bin/sh
|
|
|
|
|
|
set -e
|
|
|
|
|
|
-# summary of how this script can be called:
|
|
|
-# * <postinst> `configure' <most-recently-configured-version>
|
|
|
-# * <old-postinst> `abort-upgrade' <new version>
|
|
|
-# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
|
|
|
-# <new-version>
|
|
|
-# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
|
|
|
-# <failed-install-package> <version> `removing'
|
|
|
-# <conflicting-package> <version>
|
|
|
-# for details, see http://www.debian.org/doc/debian-policy/ or
|
|
|
-# the debian-policy package
|
|
|
-#
|
|
|
-# quoting from the policy:
|
|
|
-# Any necessary prompting should almost always be confined to the
|
|
|
-# post-installation script, and should be protected with a conditional
|
|
|
-# so that unnecessary prompting doesn't happen if a package's
|
|
|
-# installation fails and the `postinst' is called with `abort-upgrade',
|
|
|
-# `abort-remove' or `abort-deconfigure'.
|
|
|
-
|
|
|
+# don't do anything when called with other argument than configure
|
|
|
case "$1" in
|
|
|
- configure)
|
|
|
- adduser --quiet --system --group --disabled-password \
|
|
|
- --shell /bin/false --gecos "SIP Express Router" \
|
|
|
- --home /var/run/ser ser || true
|
|
|
+ configure)
|
|
|
+ ;;
|
|
|
+ abort-upgrade|abort-remove|abort-deconfigure)
|
|
|
+ exit 0
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ echo "postinst called with unknown argument \$1'" >&2
|
|
|
+ exit 1
|
|
|
+ ;;
|
|
|
+esac
|
|
|
|
|
|
- ;;
|
|
|
+. /usr/share/debconf/confmodule
|
|
|
|
|
|
- abort-upgrade|abort-remove|abort-deconfigure)
|
|
|
+# add ser user
|
|
|
+adduser --quiet --system --group --disabled-password --shell /bin/false \
|
|
|
+--gecos "SIP Express Router" --home /var/run/ser ser || true
|
|
|
|
|
|
- ;;
|
|
|
+if [ -d /usr/doc -a ! -e /usr/doc/ser -a -d /usr/share/doc/ser ]; then
|
|
|
+ ln -sf ../share/doc/ser /usr/doc/ser
|
|
|
+fi
|
|
|
|
|
|
- *)
|
|
|
- echo "postinst called with unknown argument \`$1'" >&2
|
|
|
- exit 1
|
|
|
- ;;
|
|
|
-esac
|
|
|
|
|
|
-# # dh_installdeb will replace this with shell code automatically
|
|
|
-# # generated by other debhelper scripts.
|
|
|
-# deb_helper is not used here to avoid automatically starting ser after
|
|
|
-# the installation (dh_installinit 4.0 , from woody does not support
|
|
|
-# --nostart, if you're using a newer version is safe to comment out the
|
|
|
-# rest of the code and add again deb_helper)
|
|
|
-
|
|
|
-# this will be added automatically by dh_installdocs if deb_helper is
|
|
|
-# "enabled"
|
|
|
-if [ "$1" = "configure" ]; then
|
|
|
- if [ -d /usr/doc -a ! -e /usr/doc/ser -a -d /usr/share/doc/ser ]; then
|
|
|
- ln -sf ../share/doc/ser /usr/doc/ser
|
|
|
- fi
|
|
|
+# ser defaults file, which will be modified by this script
|
|
|
+DEFAULTFILE=/etc/default/ser
|
|
|
+
|
|
|
+if ! test -e $DEFAULTFILE; then
|
|
|
+ echo "Warning: ser postinst script can't find config file $DEFAULTFILE. Configuration aborted."
|
|
|
+ exit 0
|
|
|
fi
|
|
|
-# end dh_installdocs section
|
|
|
-# this will be automativally added by dh_installinit if deb_helper is
|
|
|
-# "enabled
|
|
|
-if [ -x "/etc/init.d/ser" ]; then
|
|
|
- update-rc.d ser defaults 23 >/dev/null
|
|
|
- if ! invoke-rc.d ser restart ; then
|
|
|
+
|
|
|
+# ----------------------------------------------------------------------
|
|
|
+
|
|
|
+function fn_config_replace
|
|
|
+{
|
|
|
+ if test $# -ne 2; then
|
|
|
+ echo "Error - bad number of input parameters"
|
|
|
+ echo "usage:"
|
|
|
+ echo "fn_config_replace config_file CFG_OPTION_something"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+
|
|
|
+ FILENAME="$1"
|
|
|
+ ITEM="$2"
|
|
|
+
|
|
|
+ echo "Changing config option $ITEM."
|
|
|
+ OLDFILE="$FILENAME.config_replace_bck"
|
|
|
+ cp -f $FILENAME $OLDFILE
|
|
|
+
|
|
|
+ REPLACEMENT="$FILENAME.repl"
|
|
|
+ TEMPFILE="$FILENAME.temp"
|
|
|
+ TAIL="$FILENAME.tail"
|
|
|
+
|
|
|
+ rm -f $REPLACEMENT
|
|
|
+ touch $REPLACEMENT # needed if the input is empty
|
|
|
+ while read -r LINE
|
|
|
+ do
|
|
|
+ echo "$LINE" >> $REPLACEMENT
|
|
|
+ done
|
|
|
+
|
|
|
+ STARTPOS=`nl -b a $FILENAME | grep -w "DEBCONF-$ITEM-START" | sed -e "s/^ *\([0-9]*\).*/\1/g"`
|
|
|
+ if [ "$STARTPOS" == "" ]; then
|
|
|
+ echo "WARNING: section $ITEM not found"
|
|
|
+ return
|
|
|
+ fi
|
|
|
+
|
|
|
+ ENDPOS=`nl -b a $FILENAME | sed -e "1,${STARTPOS}d" | grep "DEBCONF-$ITEM-END" | head -n 1 | sed -e "s/^ *\([0-9]*\).*/\1/g"`
|
|
|
+ if [ "$STARTPOS" == "" ]; then
|
|
|
+ echo "WARNING: end of section $ITEM not found"
|
|
|
+ return
|
|
|
+ fi
|
|
|
+ ENDPOS=$(($ENDPOS-1))
|
|
|
+ STARTPOS=$(($STARTPOS+1))
|
|
|
+
|
|
|
+ cat $FILENAME | sed -e "1,${ENDPOS}d" > $TAIL
|
|
|
+ cat $FILENAME | sed -e "${STARTPOS},\$d" > $TEMPFILE
|
|
|
+ cat $REPLACEMENT >> $TEMPFILE
|
|
|
+ cat $TAIL >> $TEMPFILE
|
|
|
+ rm -f $TAIL
|
|
|
+ mv -f $TEMPFILE $FILENAME
|
|
|
+}
|
|
|
+
|
|
|
+# pads $1 with as many empty rows as needed until $2 lines are complete
|
|
|
+padLines() {
|
|
|
+ output="$1"
|
|
|
+ needed="$2"
|
|
|
+ num=`echo "$output" | wc -l`
|
|
|
+ echo "$output"
|
|
|
+ moreneeded=$(($needed-$num))
|
|
|
+ while (true); do
|
|
|
+ if [ $moreneeded -gt 0 ]
|
|
|
+ then
|
|
|
echo ""
|
|
|
- echo "ser failed to (re)start. Perhaps your configuration requires "
|
|
|
- echo "additional modules (e.g. ser-mysql-modules, ser-jabber-module "
|
|
|
- echo "or ser-radius-modules). Next try to install any additional ser"
|
|
|
- echo "modules you might need and then (re)start ser by executing "
|
|
|
- echo "the command '/etc/init.d/ser start|restart'."
|
|
|
+ moreneeded=$(($moreneeded-1))
|
|
|
+ else
|
|
|
+ break
|
|
|
fi
|
|
|
+ done
|
|
|
+}
|
|
|
+
|
|
|
+#----------------------------------------------------------------------------
|
|
|
+
|
|
|
+
|
|
|
+db_get ser/config
|
|
|
+if [ "$RET" = "false" ] ; then
|
|
|
+ # do not change config file
|
|
|
+ echo "Package ser postinstall script: NOT modifying config file $DEFAULTFILE."
|
|
|
+else
|
|
|
+
|
|
|
+BACKUP="$DEFAULTFILE.config_bck"
|
|
|
+
|
|
|
+echo "Package ser postinstall script: MODIFYING config file $DEFAULTFILE."
|
|
|
+echo "Creating backup copy as $BACKUP"
|
|
|
+cp -f $DEFAULTFILE $BACKUP
|
|
|
+
|
|
|
+db_get ser/USER
|
|
|
+if test "$RET" != "!" ; then
|
|
|
+ fn_config_replace $DEFAULTFILE USER <<+++
|
|
|
+SER_USER="$RET"
|
|
|
++++
|
|
|
fi
|
|
|
-# end dh_installinit section
|
|
|
|
|
|
-exit 0
|
|
|
+db_get ser/GROUP
|
|
|
+if test "$RET" != "!" ; then
|
|
|
+ fn_config_replace $DEFAULTFILE GROUP <<+++
|
|
|
+SER_GROUP="$RET"
|
|
|
++++
|
|
|
+fi
|
|
|
|
|
|
+db_get ser/WORKDIR
|
|
|
+if test "$RET" != "!" ; then
|
|
|
+ fn_config_replace $DEFAULTFILE WORKDIR <<+++
|
|
|
+SER_WORKDIR="$RET"
|
|
|
++++
|
|
|
+fi
|
|
|
+
|
|
|
+db_get ser/KERNEL_CORE_PID
|
|
|
+if test "$RET" != "!" ; then
|
|
|
+ fn_config_replace $DEFAULTFILE KERNEL_CORE_PID <<+++
|
|
|
+SER_KERNEL_CORE_PID="$RET"
|
|
|
++++
|
|
|
+fi
|
|
|
+
|
|
|
+db_get ser/MEMORY
|
|
|
+if test "$RET" != "!" ; then
|
|
|
+ fn_config_replace $DEFAULTFILE MEMORY <<+++
|
|
|
+SER_MEMORY="$RET"
|
|
|
++++
|
|
|
+fi
|
|
|
+
|
|
|
+fi # if changing config
|
|
|
+
|
|
|
+echo ""
|
|
|
+echo "***"
|
|
|
+echo "Configuration of ser has finished."
|
|
|
+echo ""
|
|
|
+echo "To restart it when configuration has changed use '/etc/init.d/ser restart'"
|
|
|
+echo ""
|
|
|
+echo "To change it's configuration use 'dpkg-reconfigure ser'"
|
|
|
+echo "***"
|
|
|
+echo ""
|
|
|
+
|
|
|
+if [ -x "/etc/init.d/ser" ]; then
|
|
|
+ if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
|
|
|
+ invoke-rc.d ser restart || exit 0
|
|
|
+ else
|
|
|
+ /etc/init.d/ser restart || exit 0
|
|
|
+ fi
|
|
|
+fi
|
|
|
+
|
|
|
+
|
|
|
+exit 0
|
|
|
|