-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfedora-setup-locale
84 lines (80 loc) · 4.01 KB
/
fedora-setup-locale
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
#!/bin/sh
#
# Configure locale.
#
# This script ensures that en_US.UTF-8 is installed as the locale, instead of C.UTF-8 which are
# the typical default in the container images, and removes any other unneeded locale packages
# for a minimalistic distro.
#
# In Fedora the locales are installed as regular packages with name prefix glibc-langpack.
# There are also some higher order language support meta packages with name prefix "langpacks",
# which ensures installation of translations, additional fonts and input methods, as well as
# the locale via the appropriate glibc-langpack package.
#
# As an example, Fedora 34 standard base image has installed the following packages by default:
# - glibc-minimal-langpack
# - langpacks-en_GB
# - With dependencies: langpacks-core-en_GB, langpacks-core-font-en, fonts-filesystem, dejavu-sans-fonts
# - Without the weak dependency: glibc-langpack-en
# The result is that it only contains C and POSIX locales, which are part of the glibc-minimal-langpack.
# The en_US.UTF-8 locale is part of glibc-langpack-en. Normally when installing the langpacks-en (for en_US)
# or langpacks-en_GB (for en_GB) the glibc-langpack-en package is automatically installed, but the default
# image has excluded this one. Removing the preinstalled langpacks_en_GB and the re-installing it would
# include it, but here we remove it and simply just install the glibc-langpack-en to get just the locale part.
# The result should be that en_US.UTF-8 is automatically activated as the new locale, instead of C.UTF-8.
# Later versions, Fedora 35 and newer, only includes the glibc-minimal-langpack, i.e. only need to
# install glibc-langpack-en, and nothing needs to be removed. The minimal base images, though, includes
# langpacks-en, with dependencies, which can be removed.
#
# NOTE:
# - Originally written for WSL import of docker root filesystem of Fedora 33 and 34,
# from Fedora Container Base image (with dnf) and Fedora Container Minimal
# Base image (with microdnf). Updated for Fedora 35 - 37.
# - Must be run by actual root user, not by use of sudo from regular user,
# (sudo is not installed by default in the Fedora Container Minimal Base image).
# - Interactive! Will prompt user before doing any changes!
# - Skips installation of documentation, by specifying --nodocs as command line
# argument. Standard base image has this configured as default with
# "tsflags=nodocs" in /etc/dns/dns.conf, but this is not supported by microdnf
# so for the minimal base image it must be added on command line.
#
# Verify running as root
if [ ${EUID:-$(id -u)} -ne 0 ]; then
echo 'Please run this script as root'
exit 1
fi
# Figure out if we have dnf or microdnf (from the Fedora Container Minimal Base image)
if hash dnf > /dev/null 2>&1; then
dnf=dnf
elif hash microdnf > /dev/null 2>&1; then
dnf=microdnf
else
echo 'Package manager dnf or microdnf not found'
exit 1
fi
echo
echo "Removing language support packages..."
# NOTE: Full version of dnf supports wildcards:
# if ! $dnf remove langpacks-*; then
# but microdnf does not, so we query list of actual names first and then remove the list.
# NOTE2: Even though clean_requirements_on_remove=True is preconfigured in container
# images, the dnf remove on preinstalled packages does not uninstall dependencies.
# Here we raw and dirty removes all langpacks and fonts packages, assuming it is
# either top-level langpacks-core-<locale> packages or dependencies of it, and no one
# else depends on these.
packages=$(rpm --query --all --queryformat '%{NAME} ' 'langpacks-*' '*fonts*')
if [ -n "$packages" ]; then
if ! $dnf remove $packages; then
echo "Failed!"
exit 1
fi
fi
echo
echo "Installing english locale package..."
# NOTE: Adding --nodocs to not install documentation. Standard base image has this
# configured as default with "tsflags=nodocs" in /etc/dns/dns.conf, but this is
# not supported by microdnf so for the minimal base image it must be added on command line.
if ! $dnf --nodocs install glibc-langpack-en; then
echo "Failed!"
exit 1
fi