Linux standalone: Include locale files in the bundle, and generate locale definition...
authorJoey Hess <joeyh@joeyh.name>
Tue, 4 Oct 2016 20:37:43 +0000 (16:37 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 4 Oct 2016 20:37:43 +0000 (16:37 -0400)
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.

Build/BundledPrograms.hs
CHANGELOG
Makefile
standalone/linux/skel/runshell

index 69d72b4610cc16a98f0079d48ea2fc98516f074c..a9a29b60398fa7f68d68b8f621ccb98cd352f023 100644 (file)
@@ -91,6 +91,8 @@ preferredBundledPrograms = catMaybes
        -- used to unpack the tarball when upgrading
        , Just "gunzip"
        , Just "tar"
+       -- used by runshell to generate locales
+       , Just "localedef"
 #endif
        -- nice, ionice, and nocache are not included in the bundle;
        -- we rely on the system's own version, which may better match
index edc018b06830e2a34f7159f4deb3816898b5475a..15a5de2f5f7a3e1b0b11f3eb3da505d2072739a6 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -14,12 +14,9 @@ git-annex (6.20160924) UNRELEASED; urgency=medium
     external special remotes, because running multiple git-annex commands
     at the same time could already start multiple processes for the same
     external special remotes.
-  * Linux standalone: Add back the LOCPATH=/dev/null hack to avoid
-    the system locale-archive being read. Version mismatches between the
-    system locale-archive and the glibc in the bundle have been observed
-    to cause git crashes. Unfortunately, this causes locales to not be
-    used in the linux standalone bundle, reverting back to pre-6.20160419
-    behavior.
+  * 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.)
 
  -- Joey Hess <id@joeyh.name>  Mon, 26 Sep 2016 16:46:19 -0400
 
index 92c2989b9e72576e4bdbdd62bb684a578f991347..da5affbfebbc81a0ad9e3b09fca8af20fdcf60d3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -143,6 +143,8 @@ linuxstandalone-nobuild: Build/Standalone Build/LinuxMkLibs
        install -d "$(LINUXSTANDALONE_DEST)/templates"
        install -d "$(LINUXSTANDALONE_DEST)/magic"
        cp /usr/share/file/magic.mgc "$(LINUXSTANDALONE_DEST)/magic"
+       install -d "$(LINUXSTANDALONE_DEST)/i18n"
+       cp /usr/share/i18n -a "$(LINUXSTANDALONE_DEST)/i18n"
        
        ./Build/LinuxMkLibs "$(LINUXSTANDALONE_DEST)"
        
index 6f6ba8a3e19711d68df60aef11474711837e152a..d6bec7aa38379f8d9ff82f34b26ee23c62c6260a 100755 (executable)
@@ -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"