Merge remote-tracking branch 'origin/github/pr/145'
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 25-locales
1 #!/bin/bash
2 # Filename:      ${GRML_FAI_CONFIG}/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 -u
10 set -e
11
12 # set up /etc/locale.gen, only GRML_FULL and LOCALES have
13 # the full setup, GRMLBASE installs a minimal configuration
14 fcopy -v /etc/locale.gen
15
16 # get rid of locales unless using class LOCALES
17 set +u
18 if ! ifclass LOCALES ; then
19 set -u
20    echo 'Removing /usr/share/locale'
21
22    # get rid of the original
23    rm -rf $target/usr/share/locale
24
25    # restore *empty* directories because otherwise installation/upgrade of packages might fail
26    [ -d "$target"/usr/share/locale ] || mkdir "$target"/usr/share/locale
27    $ROOTCMD ln -s /etc/locale.alias /usr/share/locale/locale.alias
28
29    # make sure the directories of removed locales exist; ugly hack but no other solution present :(
30    echo 'Creating empty /usr/share/locale/*/LC_MESSAGES directories'
31    for f in $($ROOTCMD dpkg -S LC_MESSAGES | awk '{print $2}' | grep '/usr/share/locale/' | sed 's#LC_MESSAGES.*##' | sort -u) ; do
32       if ! [ -d "$target/$f"/LC_MESSAGES ] ; then
33          $ROOTCMD mkdir -p "$f"/LC_MESSAGES
34       fi
35    done
36 fi
37
38 # make sure:
39 # localepurge     localepurge/nopurge     multiselect ....
40 # is set so localepurge works as expected
41 if $ROOTCMD dpkg --list localepurge 2>&1 | grep -q '^ii' ; then
42    $ROOTCMD dpkg-reconfigure -f noninteractive localepurge
43 fi
44
45 if ! [ -x $target/usr/sbin/localepurge ] ; then
46   echo "Warning: localepurge not installed"
47 else
48   echo "Running localepurge."
49   $ROOTCMD localepurge
50 fi
51
52 if $ROOTCMD dpkg-query -s locales-all >/dev/null 2>&1 ; then
53   echo "locales-all installed, skipping locales generation"
54 else
55   if ! [ -x ${target}/usr/sbin/locale-gen ] ; then
56     echo 'Warning: locale-gen [package locales] not installed'
57   else
58     echo "Running locale-gen"
59     $ROOTCMD locale-gen
60   fi
61 fi
62
63 ## END OF FILE #################################################################
64 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2