~eugenenuke/ubuntu/wily/console-setup/fix-for-1565542

« back to all changes in this revision

Viewing changes to setupcon

  • Committer: Bazaar Package Importer
  • Author(s): Anton Zinoviev
  • Date: 2011-03-29 12:06:14 UTC
  • mto: This revision was merged to the branch mainline in revision 125.
  • Revision ID: james.westby@ubuntu.com-20110329120614-nucwnqqg7rz88508
Tags: 1.72
* README: /etc/getty=>/etc/gettytab
* debian/*.init: source /etc/default/locale to permit autodetection of
  the charmap when console-setup-mini operates without configuration
  file.
* debian/*.init: do not test whether we are on the console, there are
  better tests inside setupcon.
* setupcon: do not expect the existence of 'tty' (if /usr is not mounted
  'tty' will be unavailable).  Thanks to Sven Joachim, closes: #619462.
* README.Debian: console-setup-mini no longer installs only a minimal
  set of fonts.  Without configuration file no font will be loaded.
* A little Lintian cleaning:
  - copyright: add the required reference to common-licenses;
  - restore the separate copyright file for bdf2psf;
  - versioned build dependency on debhelper (>=7.2.3~) for dh_bugfiles;
  - standards version 3.9.1;
  - use dh_lintian to install the override file.
* setupcon: new options --save-keyboard and --setup-dir.  Keep them
  undocumented for now.
* setupcon: some bug fixing:
  - the function findfile wouldn't work when setupcon is not run from
    /bin or /usr/local/bin, but from a non-standard location;
  - when working with incomplete information and guessing the font name,
    use [A-WXYZa-wyz] as file pattern for fonts instead of [A-Za-z] (we do
    not want 'x' and in some locales [A-Z] includes 'x').
* Use all-permissive, non-copyleft license for setupcon and ckbcomp-mini.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
2
 
3
3
#     setupcon -- setup the font and keyboard on the Linux console
4
 
#     Copyright © 1999,2000,2001,2002,2003,2006,2007,2008,2009,2010,2011 Anton Zinoviev
5
 
 
6
 
#     This program is free software; you can redistribute it and/or modify
7
 
#     it under the terms of the GNU General Public License as published by
8
 
#     the Free Software Foundation; either version 2 of the License, or
9
 
#     (at your option) any later version.
10
 
 
11
 
#     This program is distributed in the hope that it will be useful,
12
 
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
#     GNU General Public License for more details.
15
 
 
16
 
#     If you have not received a copy of the GNU General Public License
17
 
#     along with this program, write to the Free Software Foundation, Inc.,
18
 
#     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
4
#     Copyright (C) 2011 Anton Zinoviev <anton@lml.bas.bg>
 
5
 
 
6
#     Permission is hereby granted, free of charge, to any person
 
7
#     obtaining a copy of this file (the "Program"), to deal in the
 
8
#     Program without restriction, including without limitation the
 
9
#     rights to use, copy, modify, merge, publish, distribute,
 
10
#     sublicense, and/or sell copies of the Program, and to permit
 
11
#     persons to whom the Program is furnished to do so, subject to
 
12
#     the following conditions: The above copyright notice and this
 
13
#     permission notice shall be included in all copies or substantial
 
14
#     portions of the Program.
 
15
 
 
16
#     THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
17
#     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 
18
#     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
19
#     NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 
20
#     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
21
#     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
22
#     FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR
 
23
#     OTHER DEALINGS IN THE PROGRAM.
19
24
 
20
25
###########################################################################
21
26
 
22
 
do_font=yes   # configure font
23
 
do_kbd=yes    # configure keyboard
24
 
do_save=''    # save the required files in /etc/console-setup
25
 
do_check=yes  # test whether we are on the console
26
 
do_verbose='' # explain what is being doing
 
27
do_font=yes     # configure font
 
28
do_kbd=yes      # configure keyboard
 
29
do_check=yes    # test whether we are on the console
 
30
do_verbose=''   # explain what is being doing
 
31
do_save=''      # save the required files in /etc/console-setup
 
32
savekbdfile=''  # save the keyboard map in $savekbdfile
 
33
setupdir=''     # directory for --setup-dir
 
34
SETUP=''
27
35
 
28
36
# The same as /usr/bin/which - in order to make "which" available before
29
37
# /usr is mounted
31
39
    local IFS
32
40
    IFS=:
33
41
    for i in $PATH; do
34
 
        if [ -x "$i/$1" ]; then
 
42
        if [ -f "$i/$1" -a -x "$i/$1" ]; then
35
43
            echo "$i/$1"
36
44
            return 0
37
45
        fi
83
91
    fi
84
92
    case "$ttyarg" in
85
93
        plain)
86
 
            if [ "$do_verbose" ]; then
 
94
            if [ "$setupdir" ]; then
 
95
                SETUP="$SETUP$cmd $@
 
96
"
 
97
            elif [ "$do_verbose" ]; then
87
98
                case "$verbose" in
88
99
                    ECHO)
89
100
                        report Executing $cmd "$@".
100
111
        in)
101
112
            for tty in $ACTIVE_CONSOLES; do
102
113
                if [ -r $tty ]; then
103
 
                    report For $tty:
104
 
                    run plain "$verbose" "$cmd" "$@" <$tty
 
114
                    if [ "$setupdir" ]; then
 
115
                        # keep the space between < and $tty
 
116
                        SETUP="$SETUP$cmd $@ < $tty
 
117
"
 
118
                    else
 
119
                        report For $tty:
 
120
                        run plain "$verbose" "$cmd" "$@" <$tty
 
121
                    fi
105
122
                else
106
123
                    report No read access from $tty. Can not execute $cmd.
107
124
                fi
130
147
            fi
131
148
            ;;
132
149
    esac
133
 
    x=`(ls "$installdir"/$1/$2 /usr/local/$1/$2
134
 
           /usr/$1/$2 /etc/console-setup/$2
 
150
    x=`(ls "$installdir"/$1/$2 /usr/local/$1/$2 \
 
151
           /usr/$1/$2 /etc/console-setup/$2 \
135
152
           "$installdir"/etc/console-setup/$2) 2>/dev/null`
136
153
    x=`echo $x`
137
154
    [ "${x%% *}" ] || report Unable to find "$2".
162
179
 
163
180
# Return code 0: we are on the console; 1: we are not on the console
164
181
test_console () {
165
 
    case "`tty`" in
166
 
        /dev/tty[1-9]*|/dev/vc/[0-9]*|/dev/console|/dev/ttyv[0-9]*)
167
 
            return 0
168
 
            ;;
169
 
    esac
 
182
    local ok
 
183
    ok=0
 
184
    if which tty >/dev/null; then
 
185
        case "`tty`" in
 
186
            /dev/tty[1-9]*|/dev/vc/[0-9]*|/dev/console|/dev/ttyv[0-9]*)
 
187
                return 0
 
188
                ;;
 
189
        esac
 
190
        ok=1
 
191
    fi
170
192
 
171
193
    if which kbd_mode >/dev/null; then
172
194
        mode="`(LC_ALL=C; export LC_ALL; kbd_mode) 2>&1`"
174
196
        case "$mode" in
175
197
            Unicode*|default*|xlate*) return 0 ;;
176
198
        esac
 
199
        ok=1
177
200
    fi
178
201
 
179
202
    if which vidcontrol >/dev/null; then
180
203
        if vidcontrol -i adapter >&- 2>&-; then
181
204
            return 0
182
205
        fi
 
206
        ok=1
183
207
    fi
184
 
    return 1
 
208
 
 
209
    return $ok
185
210
}
186
211
 
187
212
###########################################################################
211
236
            do_font=''
212
237
            do_check=''
213
238
            ;;
 
239
        --save-keyboard)
 
240
            shift
 
241
            savekbdfile="$1"
 
242
            do_kbd=''
 
243
            do_font=''
 
244
            do_check=''
 
245
            ;;
 
246
        --setup-dir)
 
247
            shift
 
248
            setupdir="$1"
 
249
            do_check=''
 
250
            ;;
214
251
        -h|--help)
215
252
            cat >&2 <<EOF
216
253
Usage: setupcon [OPTION] [VARIANT]
375
412
    ISO8859-*) CHARMAP="ISO-8859-${CHARMAP#ISO8859-}" ;;
376
413
    US-ASCII|ANSI*) CHARMAP=ISO-8859-1 ;;
377
414
esac
 
415
report The charmap is $CHARMAP
378
416
 
379
417
# unicode
380
418
if \
505
543
        stdmap=$CHARMAP.acm.gz
506
544
        fontdir=share/consolefonts
507
545
        stdfont=$CODESET-$FONTFACE$FONTSIZE.psf.gz
508
 
        stdfontfallback=$CODESET-*[A-Za-z]$FONTSIZE.psf.gz
 
546
        # [A-WXYZa-wyz] is a funny way to say [A-Za-wyz].  In some locales 
 
547
        # [A-Z] includes x and we don't want this.
 
548
        stdfontfallback=$CODESET-*[A-WXYZa-wyz]$FONTSIZE.psf.gz
509
549
        ;;
510
550
    freebsd)
511
551
        mapdir=share/syscons/scrnmaps
514
554
        stdfont16=$CODESET-${FONTFACE}16.fnt
515
555
        stdfont14=$CODESET-${FONTFACE}14.fnt
516
556
        stdfont8=$CODESET-${FONTFACE}8.fnt
517
 
        stdfontfallback16=$CODESET-*[A-Za-z]16.fnt
518
 
        stdfontfallback14=$CODESET-*[A-Za-z]14.fnt
519
 
        stdfontfallback8=$CODESET-*[A-Za-z]8.fnt
 
557
        stdfontfallback16=$CODESET-*[A-WXYZa-wyz]16.fnt
 
558
        stdfontfallback14=$CODESET-*[A-WXYZa-wyz]14.fnt
 
559
        stdfontfallback8=$CODESET-*[A-WXYZa-wyz]8.fnt
520
560
        ;;
521
561
esac
522
562
 
576
616
fi
577
617
 
578
618
# XKBMODEL
579
 
if [ -n "$do_kbd$do_save" -a "$XKBMODEL" = unknown ]; then
 
619
if [ -n "$do_kbd$do_save$savekbdfile$setupdir" -a "$XKBMODEL" = unknown ]; then
580
620
    echo The keyboard model is unknown.  Keyboard will not be configured. >&2
581
621
    XKBMODEL=''
582
622
fi
654
694
        ;;
655
695
esac
656
696
 
657
 
# do_savekbd
658
 
do_savekbd=${do_save:+$kernel}
659
 
[ "$XKBMODEL" ] || do_savekbd=''
660
 
if [ "$do_savekbd" = linux ] && ! which gzip >/dev/null; then
661
 
    do_savekbd=''
 
697
# savekbdfile
 
698
if \
 
699
    [ -z "$savekbdfile" -a -n "$do_save" ] \
 
700
    && [ ! -f "$cached" \
 
701
         -o "$cached" -ot "$CONFIG"  \
 
702
         -o "$cached" -ot "$CONFIG2" ]
 
703
then
 
704
    savekbdfile="$cached"
 
705
fi
 
706
if [ -z "$savekbdfile" -a -n "$setupdir" ]; then
 
707
    mkdir -p "$setupdir"/etc/console-setup
 
708
    case "$kernel" in
 
709
        linux) savekbdfile="$setupdir"/etc/console-setup/cached.kmap.gz ;;
 
710
        freebsd) savekbdfile="$setupdir"/etc/console-setup/cached.kbd ;;
 
711
    esac
 
712
fi
 
713
[ "$XKBMODEL" ] || savekbdfile=''
 
714
if [ "$kernel" = linux ] && ! which gzip >/dev/null; then
 
715
    savekbdfile=''
662
716
    echo gzip is not accessible.  Will not save cached keyboard map. >&2
663
717
fi
664
 
[ ! -f "$cached" -o "$cached" -ot "$CONFIG"  -o "$cached" -ot "$CONFIG2" ] \
665
 
    || do_savekbd=''
666
718
 
667
719
# KMAP
668
720
if [ -n "$KMAP" -a ! -f "$KMAP" ]; then
692
744
    esac
693
745
fi
694
746
 
695
 
case "$do_savekbd" in
696
 
    linux)
697
 
        $installdir/bin/ckbcomp -backspace "$backspace" $acm_option \
698
 
            $rules_option -model "$XKBMODEL" \
699
 
            "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" | gzip -9 >"$cached"
700
 
        ;;
701
 
    freebsd)
702
 
        $installdir/bin/ckbcomp -freebsd -backspace "$backspace" $acm_option \
703
 
            $rules_option -model "$XKBMODEL" \
704
 
            "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >"$cached"
705
 
        ;;
706
 
esac
 
747
if [ "$savekbdfile" ]; then
 
748
    case "$kernel" in
 
749
        linux)
 
750
            $installdir/bin/ckbcomp -backspace "$backspace" $acm_option \
 
751
                $rules_option -model "$XKBMODEL" \
 
752
                "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
 
753
                | gzip -9 >"$savekbdfile"
 
754
            ;;
 
755
        freebsd)
 
756
            $installdir/bin/ckbcomp -freebsd -backspace "$backspace" \
 
757
                $acm_option $rules_option -model "$XKBMODEL" \
 
758
                "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >"$savekbdfile"
 
759
            ;;
 
760
    esac
 
761
fi
707
762
 
708
763
 
709
764
###########################################################################
849
904
        freebsd) run plain ECHO kbdcontrol -l "$KMAP" ;;
850
905
    esac
851
906
else
 
907
    TMPFILE=`mktemp /tmp/tmpkbd.XXXXXX` \
 
908
        || { echo Can not create temporary file >&2; exit 1; }
852
909
    case "$do_kbd" in
853
910
        linux)
854
911
            $installdir/bin/ckbcomp -backspace "$backspace" $acm_option \
855
912
                $rules_option -model "$XKBMODEL" \
856
 
                "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
857
 
                | run plain ECHO loadkeys
 
913
                "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >$TMPFILE
 
914
            run plain ECHO loadkeys $TMPFILE
858
915
            ;;
859
916
        freebsd)
860
 
            TMPFILE=`mktemp /tmp/console-setup.XXXXXX` \
861
 
                || { echo Can not create temporary file >&2; exit 1; }
862
917
            $installdir/bin/ckbcomp -freebsd -backspace "$backspace" \
863
918
                $acm_option $rules_option -model "$XKBMODEL" \
864
919
                "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >$TMPFILE
865
920
            run plain ECHO kbdcontrol -l $TMPFILE
866
921
            run plain ECHO kbdcontrol -f 70 "`printf '\033[3~'`"
867
 
            rm $TMPFILE
868
922
            ;;
869
923
    esac
 
924
    rm $TMPFILE
 
925
fi
 
926
 
 
927
 
 
928
###########################################################################
 
929
### SETUPDIR
 
930
###########################################################################
 
931
 
 
932
if [ "$setupdir" ]; then
 
933
 
 
934
    filearg () {
 
935
        case "$1" in
 
936
            *.kmap.gz|*.kbd|/tmp/tmpkbd.*)
 
937
                echo -n "/etc/console-setup/${savekbdfile##*/} "
 
938
                ;;
 
939
            /*)
 
940
                if [ -e "$1" ]; then
 
941
                    if [ ! -e "$setupdir/etc/console-setup/${1##*/}" ]; then
 
942
                        cp -a "$1" "$setupdir/etc/console-setup/${1##*/}"
 
943
                    fi
 
944
                    echo -n "/etc/console-setup/${1##*/} "
 
945
                else
 
946
                    echo -n "$1 "
 
947
                fi
 
948
                ;;
 
949
            *)
 
950
                echo -n "$1 "
 
951
                ;;
 
952
        esac
 
953
    }
 
954
 
 
955
    mkdir -p "$setupdir"/bin
 
956
 
 
957
    echo '#!/bin/sh' >"$setupdir"/bin/setupcon
 
958
    echo '# A micro-version of setupcon with static configuration.' >>"$setupdir"/bin/setupcon
 
959
    chmod +x "$setupdir"/bin/setupcon
 
960
    TMPFILE=`mktemp /tmp/console-setup.XXXXXX` \
 
961
        || { echo Can not create temporary file >&2; exit 1; }
 
962
    echo "$SETUP" |
 
963
    while read cmd args; do
 
964
        case "$cmd $args" in
 
965
            utf_start*)
 
966
                echo -n printf \'\\\\'033%%G'\'' >'
 
967
                filearg "${args%% *}"
 
968
                echo
 
969
                ;;
 
970
            utf_stop*)
 
971
                echo -n printf \'\\\\'033%%@'\'' >'
 
972
                filearg "${args%% *}"
 
973
                echo
 
974
                ;;
 
975
            kbdcontrol?-f?70*)
 
976
                echo kbdcontrol -f 70 \"\`printf \'\\\\033[3~\'\`\"
 
977
                ;;
 
978
            *)
 
979
                which "$cmd" >>$TMPFILE || true
 
980
                echo -n "$cmd "
 
981
                for arg in $args; do
 
982
                    filearg "$arg"
 
983
                done
 
984
                echo
 
985
                ;;
 
986
        esac
 
987
    done >>"$setupdir"/bin/setupcon
 
988
    echo exit 0 >>"$setupdir"/bin/setupcon
 
989
    sort $TMPFILE | uniq >"$setupdir"/morefiles
 
990
    rm $TMPFILE
870
991
fi