ソースを参照

updating Debian specification - adding debconf configuration for ser package, adding ser-nth package, adding more options to default/ser file and init script

Pavel Kasparek 18 年 前
コミット
8fc5a29534

+ 162 - 61
pkg/debian/postinst

@@ -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
 

+ 6 - 38
pkg/debian/postrm

@@ -1,45 +1,13 @@
-#! /bin/sh
-# $Id$
-# postrm script for ser-0.8.7
-#
-# see: dh_installdeb(1)
-
-set -e
-
-# summary of how this script can be called:
-#        * <postrm> `remove'
-#        * <postrm> `purge'
-#        * <old-postrm> `upgrade' <new-version>
-#        * <new-postrm> `failed-upgrade' <old-version>
-#        * <new-postrm> `abort-install'
-#        * <new-postrm> `abort-install' <old-version>
-#        * <new-postrm> `abort-upgrade' <old-version>
-#        * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
-# for details, see http://www.debian.org/doc/debian-policy/ or
-# the debian-policy package
-
-
-case "$1" in
-       purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
-        ;;
-
-    *)
-        echo "postrm called with unknown argument \`$1'" >&2
-        exit 1
-
-esac
-
-
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
+#!/bin/sh
 
 #DEBHELPER#
 
 if [ "$1" = "purge" ] ; then
-# remove user/group on purge
-	deluser --quiet --remove-home ser &>/dev/null || true
-# remove /etc/ser if empty
-	rmdir /etc/ser || true
+  # remove user/group on purge
+  deluser --quiet --remove-home ser &>/dev/null || true
+  # remove /etc/ser if empty
+  rmdir /etc/ser || true
 fi
 
 exit 0
+

+ 14 - 0
pkg/debian/prerm

@@ -0,0 +1,14 @@
+#!/bin/sh
+
+set -e
+
+if test "$1" = "upgrade"; then
+  exit 0
+fi
+
+#DEBHELPER#
+
+
+exit 0
+
+

+ 5 - 1
pkg/debian/ser-oob.config

@@ -2,7 +2,11 @@
 
 . /usr/share/debconf/confmodule
 
-# configure ?
+# set cfg file name in default/ser file
+db_input medium ser-oob/CFG_FILE || true
+db_go
+
+# configure the ser-oob.cfg file ?
 db_input medium ser-oob/config || true
 db_go
 

+ 10 - 12
pkg/debian/ser-oob.postinst

@@ -30,17 +30,8 @@ if ! test -e $CONFIGFILE; then
 fi
 
 if ! test -e $DEFAULTFILE; then
-  echo "Warning: ser-oob postinst script can't find config file $CONFIGFILE. Configuration aborted."
+  echo "Warning: ser-oob postinst script can't find config file $DEFAULTFILE. Configuration aborted."
   exit 0
-else
-  # do not modify the default file more than once
-  if ! cat $DEFAULTFILE | grep -q "#SER-OOB_CONFIGURED" ; then
-    echo "Package ser-oob postinst script: setting ser configuration file to ser-oob.cfg in $DEFAULTFILE"
-    cp -f $DEFAULTFILE ${DEFAULTFILE}.config_bck
-    cat ${DEFAULTFILE}.config_bck | sed -e "s+^SER_CFG_FILE=.*$+SER_CFG_FILE=$CONFIGFILE+" >$DEFAULTFILE
-    echo "#the following line marks that ser config filename was updated by ser-oob postinst script, and will not be modified again" >>$DEFAULTFILE
-    echo "#SER-OOB_CONFIGURED" >>$DEFAULTFILE
-  fi
 fi
 
 
@@ -113,16 +104,23 @@ padLines() {
 
 #----------------------------------------------------------------------------
 
+db_get ser-oob/CFG_FILE
+if test "$RET" != "!" ; then
+  echo "Package ser-oob postinstall script: MODIFYING config file $DEFAULTFILE."
+  fn_config_replace $DEFAULTFILE CFG_FILE <<+++
+SER_CFG_FILE="$RET"
++++
+fi
 
 db_get ser-oob/config
 if [ "$RET" = "false" ] ; then
   # do not change config file
-  echo "Package ser-oob postinst script: NOT modifying config file $CONFIGFILE."
+  echo "Package ser-oob postinstall script: NOT modifying config file $CONFIGFILE."
 else
 
 BACKUP="$CONFIGFILE.config_bck"
 
-echo "Package ser-oob config script: MODIFYING config file $CONFIGFILE."
+echo "Package ser-oob postinstall script: MODIFYING config file $CONFIGFILE."
 echo "Creating backup copy as $BACKUP"
 cp -f $CONFIGFILE $BACKUP
 

+ 29 - 0
pkg/debian/ser.config

@@ -0,0 +1,29 @@
+#!/bin/sh -e
+
+. /usr/share/debconf/confmodule
+
+# configure ?
+db_input medium ser/config || true
+db_go
+
+db_get ser/config
+
+if [ "$RET" = "false" ]; then
+  exit 0
+fi
+
+db_input medium ser/USER || true
+db_go
+
+db_input medium ser/GROUP || true
+db_go
+
+db_input medium ser/WORKDIR || true
+db_go
+
+db_input medium ser/KERNEL_CORE_PID || true
+db_go
+
+db_input medium ser/MEMORY || true
+db_go
+

+ 29 - 3
pkg/debian/ser.default

@@ -2,17 +2,43 @@
 #
 # this file is sourced by ser init script /etc/init.d/ser
 
+# Note: the #DEBCONF-xxx-START and DEBCONF-xxx-END lines are used for
+# debconf configuration, please don't remove or alter them.
+
 # ser configuration file
+#DEBCONF-CFG_FILE-START
 SER_CFG_FILE="/etc/ser/ser.cfg"
+#DEBCONF-CFG_FILE-END
 
 # user to run ser as
-#SER_USER="ser"
+#DEBCONF-USER-START
+SER_USER="ser"
+#DEBCONF-USER-END
 
 # group to run ser as
-#SER_GROUP="ser"
+#DEBCONF-GROUP-START
+SER_GROUP="ser"
+#DEBCONF-GROUP-END
 
 # ser pidfile
-#SER_PIDFILE="/var/run/ser/ser.pid"
+SER_PIDFILE="/var/run/ser/ser.pid"
+
+# working dir (cores will be placed there in case of ser crash)
+#DEBCONF-WORKDIR-START
+#SER_WORKDIR="/var/cores"
+#DEBCONF-WORKDIR-END
+
+# set if you want kernel flag to use pid for core files
+#DEBCONF-KERNEL_CORE_PID-START
+#SER_KERNEL_CORE_PID="yes"
+#DEBCONF-KERNEL_CORE_PID-END
+
+# size of shared memory used by ser, in megabytes
+#DEBCONF-MEMORY-START
+#SER_MEMORY="128"
+#DEBCONF-MEMORY-END
+
+
 
 
 

+ 32 - 17
pkg/debian/ser.init

@@ -13,42 +13,57 @@
 # $Id$
 
 # read configuration from /etc/default/ser file
-DEFAULT_FILE="/etc/default/ser"
-
-if test -f "$DEFAULT_FILE" ; then
+if test -f /etc/default/ser ; then
   . /etc/default/ser
 fi
 
-
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 DAEMON=/usr/sbin/ser
 NAME=ser
 DESC=ser
 
-if test "$SER_PIDFILE" = ""; then
-  SER_PIDFILE="/var/run/$NAME/$NAME.pid"
-fi
+PARAMS=""
 
-if test "$SER_USER" = "" ; then
-  SER_USER="ser"
+if test "$SER_PIDFILE" ; then
+  PARAMS="$PARAMS -P $SER_PIDFILE"
 fi
-if test "$SER_GROUP" = "" ; then
-  SER_GROUP="ser"
+
+if test "$SER_USER" ; then
+  PARAMS="$PARAMS -u $SER_USER"
 fi
 
-PARAMS="-P $SER_PIDFILE -u $SER_USER -g $SER_GROUP"
-LD_LIBRARY_PATH=/usr/lib/ser
+if test "$SER_GROUP" ; then
+  PARAMS="$PARAMS -g $SER_GROUP"
+fi
 
-CFGPARAMS=""
-if test "$SER_CFG_FILE" != "" ; then
+if test "$SER_CFG_FILE" ; then
+  PARAMS="$PARAMS -f $SER_CFG_FILE"
   CFGPARAMS="-f $SER_CFG_FILE"
 fi
 
-PARAMS="$PARAMS $CFGPARAMS"
+if test "$SER_WORKDIR" ; then
+  PARAMS="$PARAMS -w $SER_WORKDIR"
+  # try to create the working dir
+  mkdir -p $SER_WORKDIR || echo "Warning: error creating ser working dir $SER_WORKDIR"
+fi
+
+if test "$SER_MEMORY" ; then
+  PARAMS="$PARAMS -m $SER_MEMORY"
+fi
 
-test -f $DAEMON || exit 0
+if test "$SER_KERNEL_CORE_PID" = "true" ; then
+  # enable using pid for cores
+  echo 1 > /proc/sys/kernel/core_uses_pid || echo "Warning: error when enabling /proc/sys/kernel/core_uses_pid"
+fi
 
+if ! test -f $DAEMON ; then
+  echo "Error: cannot find $DAEMON"
+  exit 0
+fi
+
+LD_LIBRARY_PATH=/usr/lib/ser
 export LD_LIBRARY_PATH
+
 set -e
 
 case "$1" in

+ 57 - 0
pkg/debian/ser.templates

@@ -0,0 +1,57 @@
+Template: ser/config
+Type: boolean
+Default: false
+Description: Change config file now ?
+ You have now opportunity to modify basic configuration values in '/etc/default/ser'
+ config file for SER Sip Express Router, installed from 'ser' package. Settings from this
+ file are used by SER init script when it is started - e.g. size of shared memory used,
+ user and group to run as, working directory.
+ .
+ If you do not want to modify the config file now you can modify it manually later,
+ or repeat this configuartion by running "dpkg-reconfigure ser".
+ .
+ Note: if you choose 'yes' here then the values you enter will be automatically applied
+ each time the ser package is upgraded (or installed without purging previous installation).
+
+Template: ser/USER
+Type: string
+Default: ser
+Description: User to run SER as
+ Set the user which SER should run as. Default is 'ser' user.
+ .
+ Enter "!" to not modify this option.
+
+Template: ser/GROUP
+Type: string
+Default: ser
+Description: Group to run SER as
+ Set the group which SER should run as. Default is 'ser' group.
+ .
+ Enter "!" to not modify this option.
+
+Template: ser/WORKDIR
+Type: string
+Default: /
+Description: SER working directory
+ Set the working directory to which core files will be written in case of SER crash.
+ For debugging purposes it is recommended to use '/var/cores' directory. The directory will
+ be created automatically by SER init script if not existing.
+ .
+ Enter "!" to not modify this option.
+
+Template: ser/KERNEL_CORE_PID
+Type: boolean
+Default: false
+Description: Set kernel to use pid for core files
+ If enabled the '/proc/sys/kernel/core_uses_pid' will be set to '1' before starting SER,
+ to enable using of pid for core files creation. If disabled nothing will be set.
+ For debugging purposes it is recommended to enable this option.
+
+Template: ser/MEMORY
+Type: string
+Default: 32
+Description: Size of shared memory used, in MB
+ Set size of SER shared memory to allocate, in megabytes.
+ .
+ Enter "!" to not modify this option.
+