Skip to content

Commit

Permalink
init: fix locale generation on musl and older systems
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Di Maio <[email protected]>
  • Loading branch information
89luca89 committed Jun 19, 2024
1 parent bb1a97d commit f9870c1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions distrobox-init
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,11 @@ elif [ -f "/run/host/etc/default/locale" ]; then
HOST_LOCALE_LANG=$(echo "${HOST_LOCALE}" | sed -n 's/^\([^.]*\)\..*$/\1/p')
fi
# Add fallback values in case host's locale is not set correctly
[ -z "${HOST_LOCALE}" ] && HOST_LOCALE="en_US.UTF-8"
[ -z "${HOST_LOCALE_ENCODING}" ] && HOST_LOCALE_ENCODING="UTF-8 en_US.UTF-8"
[ -z "${HOST_LOCALE_LANG}" ] && HOST_LOCALE_LANG="en_US"
if [ -z "${HOST_LOCALE}" ] || [ "${HOST_LOCALE}" = "C.UTF-8" ]; then
HOST_LOCALE="en_US.UTF-8"
HOST_LOCALE_ENCODING="UTF-8 en_US.UTF-8"
HOST_LOCALE_LANG="en_US"
fi

# get_locked_mount_flags will print mount flags considered "locked".
# Arguments:
Expand Down Expand Up @@ -1178,7 +1180,9 @@ EOF

# In case the locale is not available, install it
# will ensure we don't fallback to C.UTF-8
if command -v locale && ! locale -a | grep -qi en_us.utf8 || ! locale -a | grep -qi "${HOST_LOCALE}"; then
if command -v locale && {
! locale -a | grep -qi en_us.utf8 || ! locale -a | grep -qi "${HOST_LOCALE}"
}; then
sed -i "s|#.*en_US.UTF-8|en_US.UTF-8|g" /etc/default/libc-locales
sed -i "s|#.*${HOST_LOCALE}|${HOST_LOCALE}|g" /etc/default/libc-locales
xbps-reconfigure --force glibc-locales
Expand Down

0 comments on commit f9870c1

Please sign in to comment.