File: keyboard-configuration.postinst

package info (click to toggle)
console-setup 1.164
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 28,464 kB
  • sloc: perl: 10,923; xml: 5,812; sh: 3,891; makefile: 785
file content (106 lines) | stat: -rw-r--r-- 2,659 bytes parent folder | download | duplicates (5)
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
#!/bin/sh

set -e

# Source debconf library.
. /usr/share/debconf/confmodule

# The same as /usr/bin/which - in order to make "which" available before
# /usr is mounted
which () {
    local IFS
    IFS=:
    for i in $PATH; do
	if [ -x "$i/$1" ]; then
	    echo "$i/$1"
	    return 0
	fi
    done
    return 1
}

# In d-i the config script is not executed automatically
if [ -f /usr/share/console-setup/keyboard-configuration.config ]; then
    /usr/share/console-setup/keyboard-configuration.config || exit $?
fi

## KEYBOARD_PRESENT ## Will be replaced by keyboard_present function

# keyboard_present () {
#     if there is a keyboard; then
# 	return 0
#     else
# 	return 1
#     fi
# }

CONFIGFILE=/etc/default/keyboard

if [ "$1" = "configure" -a ! -L "$CONFIGFILE" ]; then
    
    db_get keyboard-configuration/modelcode
    model="$RET"

    db_get keyboard-configuration/layoutcode
    layout="$RET"

    db_get keyboard-configuration/variantcode
    variant="$RET"

    db_get keyboard-configuration/optionscode
    options="$RET"

    if [ ! -e $CONFIGFILE ]; then
	cat /usr/share/console-setup/keyboard \
	    2>/dev/null >$CONFIGFILE || true
    fi

    # Ensure 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.
    for var in XKBMODEL XKBLAYOUT XKBVARIANT XKBOPTIONS BACKSPACE; do
        if ! grep "^ *${var}=" $CONFIGFILE >/dev/null; then
	    echo "${var}=" >>$CONFIGFILE
	fi
    done    
    
    sed \
	-e "s|^ *XKBMODEL=.*|XKBMODEL=\"$model\"|" \
	-e "s|^ *XKBLAYOUT=.*|XKBLAYOUT=\"$layout\"|" \
	-e "s|^ *XKBVARIANT=.*|XKBVARIANT=\"$variant\"|" \
	-e "s|^ *XKBOPTIONS=.*|XKBOPTIONS=\"$options\"|" \
	-e "s|^ *BACKSPACE=.*|BACKSPACE=\"${BACKSPACE:-guess}\"|" \
	<$CONFIGFILE >$CONFIGFILE.tmp
    
    mv -f $CONFIGFILE.tmp $CONFIGFILE

    db_set keyboard-configuration/store_defaults_in_debconf_db true
fi

if \
    [ -d /lib/debian-installer.d ] && keyboard_present
then
    if [ "$DISPLAY" ] && which setxkbmap >/dev/null; then
	setxkbmap -option '' -model "$model" "$layout" "$variant" "$options"
    else
	case "`uname`" in
	    GNU)
		[ ! -f /var/run/hurd-console.pid ] || kill `cat /var/run/hurd-console.pid`
		;;
	    *)
		setupcon --force --save
		;;
	esac
    fi
fi

if ! [ -d /lib/debian-installer.d ]; then
    dpkg-maintscript-helper rm_conffile \
                            /etc/init.d/keyboard-setup 1.138~ -- "$@"
    dpkg-maintscript-helper rm_conffile \
                            /etc/init.d/console-setup 1.138~ -- "$@"
fi

#DEBHELPER#