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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
#! /bin/sh
# postinst script for hunglish
#
# Note that I am deeply ashamed of my coding style in this script. :-/
#
# see: dh_installdeb(1)
set -e
. /usr/share/debconf/confmodule
# 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 /usr/share/doc/packaging-manual/
#
# 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'.
tmp=`tempfile`
function dump_hacked_XF86Config {
# Dumps a modified version of XF86Config on its standard output.
# Handles both old style (XFree86 3.x) and new style (XFree86 4.x)
# configuration file syntaxes.
# Parameters:
# $1: Full pathname of the input file. (XF86Config[-4])
# $2: Keyboard type. (pc101, pc102, etc.)
# $3: Empty or 'qwertz', describes desired default keyboard layout.
#
# !!! Beware, hideous coding ahead !!!
#
awk '
# Print customized Hunglish XKB settings.
function print_hunglish_xkb_config () {
if (new_style) {
print "\tOption\t\t\"XkbKeymap\"\t\"hunglish(pc'"$2$3"')\"";
} else {
print " XkbKeymap \"hunglish(pc'"$2$3"')\"";
print " Protocol \"Standard\"";
}
}
# Print a notification on automatic modifications.
function print_hunglish_header () {
print "#@@ {Start of Hunglish modifications}";
print "#@@ The following lines were automatically generated";
print "#@@ by Hunglish. Before you change this section by";
print "#@@ hand, please run \"dpkg-reconfigure hunglish\" and";
print "#@@ disable the automatic update of X settings. If you";
print "#@@ forget to do this, your modifications may be overwritten";
print "#@@ the next time you update Hunglish.";
print "#@@ ";
}
# Note the end of Hunglish settings.
function print_hunglish_footer () {
print "#@@ You can safely modify the settings after this line.";
print "#@@ {End of Hunglish modifications}";
}
# Initialize flags.
BEGIN {
in_inputsection = 0;
in_keyboardsection = 0;
in_keyboard = 0;
found_section = 0;
new_style = 0;
}
# Handle new style configuration syntax:
#
# Section "InputDevice"
# ...
# Driver "Keyboard"
# ...
# EndSection
#
/^[ \t]*[sS]ection[ \t]*"[iI]nput[dD]evice"/ {
in_inputsection = 1;
in_keyboard = 0;
print $0;
next;
}
in_inputsection && /^[ \t]*[dD]river[ \t]*"[kK]eyboard"/ {
print $0;
in_keyboard = 1;
found_section = 1;
new_style = 1;
print_hunglish_header();
next;
}
# Handle old style configuration syntax:
#
# Section "Keyboard"
# ...
# EndSection
#
/^[ \t]*[sS]ection[ \t]*"[kK]eyboard"/ {
print $0;
in_inputsection = 1;
in_keyboard = 1;
new_style = 0;
found_section = 1;
print_hunglish_header();
next;
}
# The end of the keyboard section.
in_inputsection && /^[ \t]*[eE]nd[sS]ection/ {
in_inputsection = 0;
if (in_keyboard) {
print_hunglish_xkb_config();
print_hunglish_footer();
found_section = 2;
in_keyboard = 0;
}
print $0;
next;
}
# Exception: keep "CoreKeyboard" options.
in_keyboard && /^[ \t]*[oO]ption[ \t]*"[cC]ore[kK]eyboard"/ {
print "#>> " $0;
print;
next;
}
# But in the usual case, just comment out old settings.
in_keyboard {
print "#>> " $0;
next;
}
# Otherwise, we just copy everything.
{ print $0; }
END {
if (found_section != 2) {
print "Could not find keyboard section in '"$1"'." | "cat >&2";
exit(1);
}
}
' "$1"
}
case "$1" in
configure)
db_get hunglish/default
case "$RET" in
[yY]*)
CONSOLE=yes
XKB=yes
;;
[xX]*)
CONSOLE=no
XKB=yes
;;
[cC]*)
CONSOLE=yes
XKB=no
;;
*)
CONSOLE=no
XKB=no
exit 0
;;
esac
db_get hunglish/keyboardtype || true
case "$RET" in
101|102|104|105)
TYPE=$RET
;;
*)
echo Assuming 105-key keyboard.
TYPE=105
;;
esac
db_get hunglish/qwertz || true
case "$RET" in
true)
QWERTZ=qwertz
;;
*)
QWERTZ=
;;
esac
if [ "$CONSOLE" = yes ]; then
install-keymap hunglish-pc$TYPE$QWERTZ.kmap.gz
fi
if [ "$XKB" = yes ]; then
OK=no
for XF86Config in /etc/X11/XF86Config-4 /etc/X11/XF86Config; do
XF86backup=$XF86Config.hunglish-orig
if [ -e $XF86Config ]; then
OK=yes
dump_hacked_XF86Config "$XF86Config" "$TYPE" "$QWERTZ" > $tmp
if [ $? -ne 0 ]; then
db_input high hunglish/badxconfiguration || true
else
mv -f $XF86Config $XF86backup && \
mv -f $tmp $XF86Config && \
chmod 644 $XF86Config $XF86backup
rm -f $tmp
fi
fi
done
if [ $OK != yes ]; then
db_input high hunglish/noxconfiguration || true
fi
# Regenerate XKB index files.
XKBCOMP=/usr/X11R6/bin/xkbcomp
XKBDIR=/etc/X11/xkb
if [ -x "$XKBCOMP" ]; then
for i in compat keymap symbols types; do
if [ -e "$XKBDIR/$i.dir" ]; then
rm -rf "$XKBDIR/$i.dir"
# Don't you just love the exhaustive and up-to-date man page of xkbcomp?
(cd "$XKBDIR/$i" && $XKBCOMP -lfhlpR -o "$XKBDIR/$i.dir" '*')
fi
done
fi
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 0
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
|