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 # set up /etc/locale.conf, to avoid systemd-firstboot prompting for user input
17 fcopy -v /etc/locale.conf
18
19 # get rid of locales unless using class LOCALES
20 set +u
21 if ! ifclass LOCALES ; then
22 set -u
23    echo 'Removing /usr/share/locale'
24
25    # get rid of the original
26    rm -rf $target/usr/share/locale
27
28    # restore *empty* directories because otherwise installation/upgrade of packages might fail
29    [ -d "$target"/usr/share/locale ] || mkdir "$target"/usr/share/locale
30    $ROOTCMD ln -s /etc/locale.alias /usr/share/locale/locale.alias
31
32    # make sure the directories of removed locales exist; ugly hack but no other solution present :(
33    echo 'Creating empty /usr/share/locale/*/LC_MESSAGES directories'
34    for f in $($ROOTCMD dpkg -S LC_MESSAGES | awk '{print $2}' | grep '/usr/share/locale/' | sed 's#LC_MESSAGES.*##' | sort -u) ; do
35       if ! [ -d "$target/$f"/LC_MESSAGES ] ; then
36          $ROOTCMD mkdir -p "$f"/LC_MESSAGES
37       fi
38    done
39 fi
40
41 # make sure:
42 # localepurge     localepurge/nopurge     multiselect ....
43 # is set so localepurge works as expected
44 if $ROOTCMD dpkg --list localepurge 2>&1 | grep -q '^ii' ; then
45    $ROOTCMD dpkg-reconfigure -f noninteractive localepurge
46 fi
47
48 if ! [ -x $target/usr/sbin/localepurge ] ; then
49   echo "Warning: localepurge not installed"
50 else
51   echo "Running localepurge."
52   $ROOTCMD localepurge
53 fi
54
55 if $ROOTCMD dpkg-query -s locales-all >/dev/null 2>&1 ; then
56   echo "locales-all installed, skipping locales generation"
57 else
58   if ! [ -x ${target}/usr/sbin/locale-gen ] ; then
59     echo 'Warning: locale-gen [package locales] not installed'
60   else
61     echo "Running locale-gen"
62     $ROOTCMD locale-gen
63   fi
64 fi
65
66 ## END OF FILE #################################################################
67 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2