From 2355a629bebcba4ea2740cbaba8c4982f58d6abd Mon Sep 17 00:00:00 2001
From: Marco Mariani <marco.mariani@nexedi.com>
Date: Mon, 29 Sep 2014 16:28:41 +0200
Subject: [PATCH] slaprunner: use LC_ALL=en_US in import/export scripts

pbs: enforce LC_ALL=C (importer/exporter as well) for proper sort collation

to mark the purpose, repeat inside the call to /usr/bin/sort,
but it's also needed for messages (i.e. we don't want /bin/cp
to write unicode chars in the pubsub feed)
---
 slapos/recipe/pbs.py                                 | 4 +++-
 software/slaprunner/common.cfg                       | 4 ++--
 software/slaprunner/template/runner-export.sh.jinja2 | 6 +++---
 software/slaprunner/template/runner-import.sh.jinja2 | 4 +++-
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/slapos/recipe/pbs.py b/slapos/recipe/pbs.py
index d34d7c898..e2f8ed7a4 100644
--- a/slapos/recipe/pbs.py
+++ b/slapos/recipe/pbs.py
@@ -135,6 +135,8 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
       rdiff_wrapper_template = textwrap.dedent("""\
           #!/bin/sh
           # %(comment)s
+          LC_ALL=C
+          export LC_ALL
           RDIFF_BACKUP="%(rdiffbackup_binary)s"
           $RDIFF_BACKUP %(rdiffbackup_parameter)s
           if [ ! $? -eq 0 ]; then
@@ -156,7 +158,7 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
           
           if [ -e /srv/slapgrid/slappart17/srv/backup/pbs/COMP-1867-slappart6-runner-2/backup.signature ]; them
             cd %(local_directory)s
-            find -type f ! -name backup.signature ! -wholename "./rdiff-backup-data/*" -print0 | xargs -0 sha256sum  | sort > ../proof.signature
+            find -type f ! -name backup.signature ! -wholename "./rdiff-backup-data/*" -print0 | xargs -0 sha256sum  | LC_ALL=C sort -k 66 > ../proof.signature
             diff -ruw backup.signature ../proof.signature > ../backup.diff
             # XXX If there is a difference on the backup, we should publish the 
             # failure and ask the equeue, re-run this script again, 
diff --git a/software/slaprunner/common.cfg b/software/slaprunner/common.cfg
index 9b0f1516a..111163f32 100644
--- a/software/slaprunner/common.cfg
+++ b/software/slaprunner/common.cfg
@@ -53,7 +53,7 @@ mode = 0644
 recipe = hexagonit.recipe.download
 url = ${:_profile_base_location_}/template/runner-import.sh.jinja2
 download-only = true
-md5sum = d64529e263d42b0b56e5fe3a976d18c9
+md5sum = 7d3c42b9cc457f41f6be72c765b8aadf
 filename = runner-import.sh.jinja2
 mode = 0644
 
@@ -68,7 +68,7 @@ mode = 0644
 recipe = hexagonit.recipe.download
 url = ${:_profile_base_location_}/template/runner-export.sh.jinja2
 download-only = true
-md5sum = 86e42a6d37fde9b3b5ad1036ae25aa5c
+md5sum = 072a6a15b17b364e709d89468a6ac180
 filename = runner-export.sh.jinja2
 mode = 0644
 
diff --git a/software/slaprunner/template/runner-export.sh.jinja2 b/software/slaprunner/template/runner-export.sh.jinja2
index ef2c18af1..607d27140 100644
--- a/software/slaprunner/template/runner-export.sh.jinja2
+++ b/software/slaprunner/template/runner-export.sh.jinja2
@@ -1,6 +1,6 @@
 #!{{ shell_binary }}
-LANG=en_US
-export $LANG
+LC_ALL=C
+export LC_ALL
 umask 077
 sync_element () {
   path=$1
@@ -24,4 +24,4 @@ if [ -d {{ directory['backup'] }}/runner/software ]; then
   rm {{ directory['backup'] }}/runner/software/*
 fi
 
-cd {{ directory['backup'] }} && find -type f ! -name backup.signature -print0 | xargs -0 sha256sum | sort  > backup.signature
+cd {{ directory['backup'] }} && find -type f ! -name backup.signature -print0 | xargs -0 sha256sum | LC_ALL=C sort -k 66 > backup.signature
diff --git a/software/slaprunner/template/runner-import.sh.jinja2 b/software/slaprunner/template/runner-import.sh.jinja2
index 3b182ec85..dfc5ba215 100644
--- a/software/slaprunner/template/runner-import.sh.jinja2
+++ b/software/slaprunner/template/runner-import.sh.jinja2
@@ -1,4 +1,6 @@
 #!{{ shell_binary }}
+LC_ALL=C
+export LC_ALL
 umask 077
 restore_element () {
   backup_path=$1
@@ -16,7 +18,7 @@ restore_element () {
 
 write_backup_proof () {
   cd {{ directory['backup'] }}
-  find -type f ! -name backup.signature ! -wholename "./rdiff-backup-data/*" -print0 | xargs -0 sha256sum  | sort > {{ directory['srv'] }}/proof.signature
+  find -type f ! -name backup.signature ! -wholename "./rdiff-backup-data/*" -print0 | xargs -0 sha256sum  | LC_ALL=C sort -k 66 > {{ directory['srv'] }}/proof.signature
   diff -ruw {{ directory['backup'] }} {{ directory['srv'] }}/proof.signature > {{ directory['srv'] }}/backup.diff
 }
 
-- 
2.30.9