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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
#! /bin/sh
# prerm script for multispeech
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <prerm> `remove'
# * <old-prerm> `upgrade' <new-version>
# * <new-prerm> `failed-upgrade' <old-version>
# * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
# * <deconfigured's-prerm> `deconfigure' `in-favour'
# <package-being-installed> <version> `removing'
# <conflicting-package> <version>
# 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 <<EOF # bash discards everything from here to EOF
# perl ignores everything until the next line, due to the "-x" option above
#!/usr/bin/perl -w $*
use strict;
use Debconf::Client::ConfModule q(:all);
# get choices already in the debconf database
my $deleted_device='Multispeech';
my ($b, $p, $t, $device, $olddevice,
%blurb, %program, %tcl, %device, %db);
my ($ret, $database) = metaget ('shared/emacspeak/database', 'choices');
foreach (split (/, */, $database)){ # debconf database is comma separated
($b, $p, $t, $device)=split(/:/);
if ($deleted_device ne $device){
$blurb{$device}=$b;
$program{$device}=$p;
$tcl{$device}=$t;
$db{$device}="$b:$p:$t";
}
}
# Add choices from unpacked .blurb files from other packages, in case
# they aren't debconf compliant
my $dirname='/usr/share/emacs/site-lisp/emacspeak/blurbs';
if (opendir(DIR,$dirname)){
my @fnames=readdir(DIR);
closedir(DIR);
foreach (@fnames){
if (/.blurb$/){
open(IF,"$dirname/$_");
while(<IF>){
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 (<CF>){
/^\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.
#DEBHELPER#
exit 0
|