ccc402874500e2e8d3fad0c00690ae2418b58820
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 25-locales
1 #!/bin/bash
2 # Filename:      /etc/grml/fai/config/scripts/GRMLBASE/25-locales
3 # Purpose:       locales (language) configuration of the live system
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8
9 set -e
10
11 if [ -z "$ROOTCMD" ] ; then
12    echo "variable \$ROOTCMD not set, exiting to avoid any possible damage">&2
13    exit 1
14 fi
15
16 # use full locales setup only in classes GRML_FULL and LOCALES
17 if ifclass GRML_FULL || ifclass LOCALES ; then
18    echo 'Using /etc/locale.gen.grml for locales generation'
19    cp $target/etc/locale.gen.grml $target/etc/locale.gen
20 else
21    echo 'Using /etc/locale.gen.minimal for locales generation'
22    cp $target/etc/locale.gen.minimal $target/etc/locale.gen
23 fi
24
25 # get rid of locales unless using class LOCALES
26 # TODO
27 # * this should be improved in the long run, ideas welcome :)
28 # * what about /usr/share/i18n/locales?
29 if ! ifclass LOCALES ; then
30    echo 'Removing /usr/share/locale'
31
32    # get rid of the original
33    $ROOTCMD rm -rf /usr/share/locale
34
35    # restore *empty* directories because otherwise installation/upgrade of packages might fail
36    [ -d "$target"/usr/share/locale ] || mkdir "$target"/usr/share/locale
37    $ROOTCMD ln -s /etc/locale.alias /usr/share/locale/locale.alias
38
39    # make sure the directories of removed locales exist; ugly hack but no other solution present :(
40    echo 'Creating empty /usr/share/locale/*/LC_MESSAGES directories'
41    for f in $($ROOTCMD dpkg -S LC_MESSAGES | awk '{print $2}' | grep '/usr/share/locale/' | sed 's#LC_MESSAGES.*##' | sort -u) ; do
42       if ! [ -d "$target/$f"/LC_MESSAGES ] ; then
43          $ROOTCMD mkdir -p "$f"/LC_MESSAGES
44       fi
45    done
46 fi
47
48 # make sure:
49 # localepurge     localepurge/nopurge     multiselect ....
50 # is set so localepurge works as expected
51 if [ -x $target/usr/sbin/localepurge ] ; then
52    $ROOTCMD dpkg-reconfigure -f noninteractive localepurge
53 fi
54
55 if [ -x $target/usr/sbin/locale-gen ] ; then
56    $ROOTCMD locale-gen
57 else
58    echo 'Warning: locale-gen [package locales] not available'
59 fi
60
61 if [ -x $target/usr/sbin/localepurge ] ; then
62    $ROOTCMD localepurge
63 fi
64
65 ## END OF FILE #################################################################
66 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=3