Linux standalone: Include locale files in the bundle, and generate locale definition files for the locales in use when starting runshell.

Currently only done for utf-8 locales because the charset can easily be
told for those. Other locales don't include the charset in their name.

The locale definition is generated under git-annex.linux/locales.
So, this only works if the user can write there.

If locale generation fails for any reason, it's silently skipped.

The git-annex-standalone.deb installs the bundle under /usr, so this locale
generation won't work for non-root users.
This commit is contained in:
Joey Hess 2016-10-04 16:37:43 -04:00
parent a93e38e8fc
commit aacd9b190d
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
4 changed files with 40 additions and 11 deletions

View file

@ -100,11 +100,6 @@ export ORIG_GCONV_PATH
GCONV_PATH="$base/$(cat "$base/gconvdir")"
export GCONV_PATH
ORIG_LOCPATH="$LOCPATH"
export ORIG_LOCPATH
LOCPATH=/dev/null
export LOCPATH
ORIG_GIT_EXEC_PATH="$GIT_EXEC_PATH"
export ORIG_GIT_EXEC_PATH
GIT_EXEC_PATH="$base/git-core"
@ -120,6 +115,39 @@ export ORIG_MANPATH
MANPATH="$base/usr/share/man:$MANPATH"
export MANPATH
# Avoid using system locales, which may interact badly with bundled libc.
ORIG_LOCPATH="$LOCPATH"
export ORIG_LOCPATH
LOCPATH="$base/locales"
export LOCPATH
# Generate locale definition files for the locales in use,
# using the localedef and locale files from the bundle.
# Currently only utf-8 locales are handled.
lastlocaleenv=""
for localeenv in "$LANG" "$LANGUAGE" "$LC_CTYPE" "$LC_NUMERIC" "$LC_TIME" \
"$LC_COLLATE" "$LC_MONETARY" "$LC_MESSAGES" "$LC_PAPER" \
"$LC_NAME" "$LC_ADDRESS" "$LC_TELEPHONE" "$LC_MEASUREMENT" \
"$LC_IDENTIFICATION" "$LC_ALL"; do
if [ "$localeenv" != "$lastlocaleenv" ]; then
lastlocaleenv="$localeenv"
if [ ! -d "$base/locales/$localeenv" ]; then
if [ "${localeenv##[!.]*.}" = "utf8" ]; then
(
rm -rf "$base/locales/$localeenv.new.$$" &&
mkdir -p "$base/locales/$localeenv.new.$$" &&
# cd to $base since localedef reads files from pwd
cd "$base" &&
# Run localedef using the bundled i18n files;
# use LANG=C to avoid it reading the system locale archive.
I18NPATH="$base/i18n" LANG=C localedef -i "${localeenv%%.*}" -c -f UTF-8 "$base/locales/$localeenv.new.$$" &&
mv "$base/locales/$localeenv.new.$$" "$base/locales/$localeenv"
) >/dev/null 2>/dev/null || true
fi
fi
fi
done
# Indicate which variables were exported above and should be cleaned
# when running non-bundled programs.
GIT_ANNEX_STANDLONE_ENV="PATH GCONV_PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR MANPATH LOCPATH"