#! /bin/sh # prerm script for multispeech # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `remove' # * `upgrade' # * `failed-upgrade' # * `remove' `in-favour' # * `deconfigure' `in-favour' # `removing' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package case "$1" in upgrade) exit 0 ;; remove|deconfigure) ;; failed-upgrade) ;; *) echo "prerm called with unknown argument \`$1'" >&2 exit 1 ;; esac #echo " deconfiguring" >>/var/log/emacspeak if [ -e /usr/share/debconf/confmodule ]; then # {{{ . /usr/share/debconf/confmodule if db_get shared/emacspeak/fake; then # I no longer claim these questions. db_unregister shared/emacspeak/fake db_unregister shared/emacspeak/device db_unregister shared/emacspeak/port db_unregister shared/emacspeak/invalidport db_unregister shared/emacspeak/groupies db_unregister shared/emacspeak/invaliduser db_unregister shared/emacspeak/rootgroup db_unregister shared/emacspeak/program db_unregister shared/emacspeak/tcl db_unregister shared/emacspeak/database fi # See if the shared question still exists. if db_get shared/emacspeak/fake; then db_metaget shared/emacspeak/fake owners db_subst shared/emacspeak/fake choices $RET export task=$1 # save argument perl -x $0 # execute this file as a perl program true <){ if (/^blurb: *(.*)$/) {$b=$1;} if (/^program: *(.*)$/) {$p=$1;} if (/^tcl: *(.*)$/) {$t=$1;} if (/^device: *(.*)$/) {$device=$1;} } if ($deleted_device ne $device){ $blurb{$device}=$b; $program{$device}=$p; $tcl{$device}=$t; $db{$device}="$b:$p:$t"; } } } } my $newdatabase=''; foreach $device (sort keys %db) { ($b,$p,$t)=split(':',$db{$device}); $newdatabase .= "$b:$p:$t:$device, "; } # update debconf database subst ('shared/emacspeak/database', 'choices', $newdatabase); my $devicelist=join(', ', sort keys %db); subst ('shared/emacspeak/device', 'choices', $devicelist); # get current settings from the configuration file if it exists my $configfile='/etc/emacspeak.conf'; my $program=''; my $port=''; my $tcl=''; if (-e $configfile){ open(CF,$configfile) or die("$configfile exists but could not be opened for reading\n"); while (){ /^\s*DTK_PROGRAM\s*=\s*(\S+)/ and set('shared/emacspeak/program',$1); /^\s*DTK_PORT\s*=\s*(\S+)/ and set('shared/emacspeak/port',$1); /^\s*DTK_TCL\s*=\s*(\S+)/ and set('shared/emacspeak/tcl',$1); /^\s*DTK_DEVICE\s*=\s*(\S+)/ and set('shared/emacspeak/device',$1); # If device is a quoted string, rescan to get the whole thing /^\s*DTK_DEVICE\s*=\s*\"(.+)\"/ and set('shared/emacspeak/device',$1); /^\s*DTK_DEVICE\s*=\s*\'(.+)\'/ and set('shared/emacspeak/device',$1); } close(CF); } if ($ENV{task} eq "remove" && $deleted_device eq $device){ # the currently configured device is being removed, # so ask which remaining device to use fset('shared/emacspeak/device', 'seen', 'false'); title('emacspeak speech server configuration'); input('high', 'shared/emacspeak/device'); go(); $device=get('shared/emacspeak/device'); if (get('shared/emacspeak/program') eq ''){ set('shared/emacspeak/program',$program{$device}); } if (get('shared/emacspeak/tcl') eq ''){ set('shared/emacspeak/tcl',$tcl{$device}); } if ($device eq "DoubleTalk PC" and $port =~ m./dev/tty.){ set('shared/emacspeak/port','/dev/dtlk'); } set('shared/emacspeak/program',$program{$device}); fset('shared/emacspeak/port', 'seen', 'false'); set('shared/emacspeak/tcl',$tcl{$device}); my $valid=0; while (!$valid) { input('high', 'shared/emacspeak/port'); go(); $port=get('shared/emacspeak/port'); if (($port eq "none") || (-c $port)){ $valid=1; } else { subst("shared/emacspeak/invalidport",'port',$port); input('high','shared/emacspeak/invalidport'); go(); } } # we don't check port permissions or ownership, or add or delete # users from the port's group } # if ($deleted_device eq $device) __END__ # perl ignores everything after this EOF # Actualize chosen speech server in config file CONFIGFILE=/etc/emacspeak.conf if [ -e $CONFIGFILE ]; then # Substitute in the values from the debconf db. db_get shared/emacspeak/program DTK_PROGRAM="$RET" db_get shared/emacspeak/tcl DTK_TCL="$RET" db_get shared/emacspeak/port DTK_PORT="$RET" db_get shared/emacspeak/device DTK_DEVICE="$RET" # This cp ensures we do not mess up # the config file's ownership and permissions. cp -a -f $CONFIGFILE $CONFIGFILE.tmp # If the admin deleted or commented some variables but then set # them via debconf, (re-)add them to the conffile. test -z "$DTK_PROGRAM" || grep -Eq '^ *DTK_PROGRAM=' $CONFIGFILE || \ echo "DTK_PROGRAM=" >> $CONFIGFILE test -z "$DTK_TCL" || grep -Eq '^ *DTK_TCL=' $CONFIGFILE || \ echo "DTK_TCL=" >> $CONFIGFILE test -z "$DTK_PORT" || grep -Eq '^ *DTK_PORT=' $CONFIGFILE || \ echo "DTK_PORT=" >> $CONFIGFILE test -z "$DTK_DEVICE" || grep -Eq '^ *DTK_DEVICE=' $CONFIGFILE || \ echo "DTK_DEVICE=" >> $CONFIGFILE # the strings can contain slashes, so use something else to delimit patterns sed -e "s|^ *DTK_PROGRAM=.*|DTK_PROGRAM=$DTK_PROGRAM|" \ -e "s|^ *DTK_TCL=.*|DTK_TCL=$DTK_TCL|" \ -e "s|^ *DTK_PORT=.*|DTK_PORT=$DTK_PORT|" \ -e "s/^ *DTK_DEVICE=.*/DTK_DEVICE=\"$DTK_DEVICE\"/" \ < $CONFIGFILE > $CONFIGFILE.tmp mv -f $CONFIGFILE.tmp $CONFIGFILE fi fi # shared question still exists fi # debconf is installed # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. exit 0