From 63726d9f16de39b94d5bfe85ae5474ab86d77972 Mon Sep 17 00:00:00 2001
From: Gunnar Hjalmarsson <gunnarhj@ubuntu.com>
Date: Wed, 21 Feb 2018 21:23:20 +0100
Subject: [PATCH] Enable translations for the cryptroot script

https://bugs.debian.org/688735, https://launchpad.net/bugs/1027854
---
 .../{cryptroot-script => cryptroot-script.sh}      | 35 +++++++++++++++-------
 debian/patches/cryptroot-script-translations.patch | 13 ++++++++
 debian/patches/series                              |  1 +
 debian/rules                                       |  4 ++-
 4 files changed, 41 insertions(+), 12 deletions(-)
 rename debian/initramfs/{cryptroot-script => cryptroot-script.sh} (84%)
 create mode 100644 debian/patches/cryptroot-script-translations.patch

diff --git a/debian/initramfs/cryptroot-script b/debian/initramfs/cryptroot-script.sh
similarity index 84%
rename from debian/initramfs/cryptroot-script
rename to debian/initramfs/cryptroot-script.sh
index 75299a0..3fa9e67 100644
--- a/debian/initramfs/cryptroot-script
+++ b/debian/initramfs/cryptroot-script.sh
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 PREREQ="cryptroot-prepare"
+export TEXTDOMAIN=cryptsetup
+. /usr/bin/gettext.sh
 
 #
 # Standard initramfs preamble
@@ -165,7 +167,8 @@ parse_options()
 	export CRYPTTAB_OPTIONS
 
 	if [ -z "$cryptsource" ]; then
-		message "cryptsetup ($crypttarget): source parameter missing"
+		# TRANSLATORS: Keep the variable $crypttarget untranslated
+		message $(eval_gettext 'cryptsetup ($crypttarget): source parameter missing')
 		return 1
 	fi
 	return 0
@@ -175,7 +178,8 @@ activate_vg()
 {
 	# Sanity checks
 	if [ ! -x /sbin/lvm ]; then
-		message "cryptsetup ($crypttarget): lvm is not available"
+		# TRANSLATORS: Keep the variable $crypttarget untranslated
+		message $(eval_gettext 'cryptsetup ($crypttarget): lvm is not available')
 		return 1
 	fi
 
@@ -206,7 +210,8 @@ setup_mapping()
 		cryptkeyscript="/lib/cryptsetup/askpass"
 		cryptkey="Please unlock disk $diskname: "
 	elif ! type "$cryptkeyscript" >/dev/null; then
-		message "cryptsetup ($crypttarget): error - script \"$cryptkeyscript\" missing"
+		# TRANSLATORS: Keep the variables $crypttarget and $cryptkeyscript untranslated
+		message $(eval_gettext 'cryptsetup ($crypttarget): error - script "$cryptkeyscript" missing')
 		return 1
 	fi
 
@@ -218,7 +223,8 @@ setup_mapping()
 	fi
 
 	if [ -n "$cryptheader" ] && ! type "$cryptheader" >/dev/null; then
-		message "cryptsetup ($crypttarget): error - LUKS header \"$cryptheader\" missing"
+		# TRANSLATORS: Keep the variables $crypttarget and $cryptheader untranslated
+		message $(eval_gettext 'cryptsetup ($crypttarget): error - LUKS header "$cryptheader" missing')
 		return 1
 	fi
 
@@ -323,13 +329,15 @@ setup_mapping()
 		if [ ! -e "$NEWROOT" ]; then
 			if ! crypttarget="$crypttarget" cryptsource="$cryptsource" \
 			     $cryptkeyscript "$cryptkey" | $cryptopen; then
-				message "cryptsetup ($crypttarget): cryptsetup failed, bad password or options?"
+				# TRANSLATORS: Keep the variable $crypttarget untranslated
+				message $(eval_gettext 'cryptsetup ($crypttarget): cryptsetup failed, bad password or options?')
 				continue
 			fi
 		fi
 
 		if [ ! -e "$NEWROOT" ]; then
-			message "cryptsetup ($crypttarget): unknown error setting up device mapping"
+			# TRANSLATORS: Keep the variable $crypttarget untranslated
+			message $(eval_gettext 'cryptsetup ($crypttarget): unknown error setting up device mapping')
 			return 1
 		fi
 
@@ -341,7 +349,8 @@ setup_mapping()
 		#if [ "$FSTYPE" = "lvm" ] || [ "$FSTYPE" = "lvm2" ]; then
 		if [ "$FSTYPE" = "LVM_member" ] || [ "$FSTYPE" = "LVM2_member" ]; then
 			if [ -z "$cryptlvm" ]; then
-				message "cryptsetup ($crypttarget): lvm fs found but no lvm configured"
+				# TRANSLATORS: Keep the variable $crypttarget untranslated
+				message $(eval_gettext 'cryptsetup ($crypttarget): lvm fs found but no lvm configured')
 				return 1
 			elif ! activate_vg; then
 				# disable error message, LP: #151532
@@ -366,7 +375,8 @@ setup_mapping()
 
 		#if [ -z "$FSTYPE" ] || [ "$FSTYPE" = "unknown" ]; then
 		if [ -z "$FSTYPE" ]; then
-			message "cryptsetup ($crypttarget): unknown fstype, bad password or options?"
+			# TRANSLATORS: Keep the variable $crypttarget untranslated
+			message $(eval_gettext 'cryptsetup ($crypttarget): unknown fstype, bad password or options?')
 			udev_settle
 			$cryptremove
 			continue
@@ -375,15 +385,18 @@ setup_mapping()
 		# decrease $count by 1, apparently last try was successful.
 		count=$(( $count - 1 ))
 
-		message "cryptsetup ($crypttarget): set up successfully"
+		# TRANSLATORS: Keep the variable $crypttarget untranslated
+		message $(eval_gettext 'cryptsetup ($crypttarget): set up successfully')
 		break
 	done
 
 	failsleep=60 # make configurable later?
 
 	if [ "$cryptrootdev" = "yes" ] && [ $crypttries -gt 0 ] && [ $count -ge $crypttries ]; then
-		message "cryptsetup ($crypttarget): maximum number of tries exceeded"
-		message "cryptsetup: going to sleep for $failsleep seconds..."
+		# TRANSLATORS: Keep the variable $crypttarget untranslated
+		message $(eval_gettext 'cryptsetup ($crypttarget): maximum number of tries exceeded')
+		# TRANSLATORS: Keep the variable $failsleep untranslated
+		message $(eval_gettext 'cryptsetup: going to sleep for $failsleep seconds...')
 		sleep $failsleep
 		exit 1
 	fi
diff --git a/debian/patches/cryptroot-script-translations.patch b/debian/patches/cryptroot-script-translations.patch
new file mode 100644
index 0000000..ba7c18e
--- /dev/null
+++ b/debian/patches/cryptroot-script-translations.patch
@@ -0,0 +1,13 @@
+Description: Add cryptroot-script.sh to po/POTFILES.in
+Bug: https://bugs.debian.org/688735
+Bug-Ubuntu: https://launchpad.net/bugs/1027854
+Author: Gunnar Hjalmarsson <gunnarhj@ubuntu.com>
+Forwarded: not-needed
+
+--- a/po/POTFILES.in
++++ b/po/POTFILES.in
+@@ -39,3 +39,4 @@
+ src/cryptsetup_reencrypt.c
+ src/utils_tools.c
+ src/utils_password.c
++debian/initramfs/cryptroot-script.sh
diff --git a/debian/patches/series b/debian/patches/series
index 35ea15f..ad8012a 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 Fix-loopaesOpen-for-keyfile-on-standard-input.patch
+cryptroot-script-translations.patch
diff --git a/debian/rules b/debian/rules
index fb1c187..2b100a6 100755
--- a/debian/rules
+++ b/debian/rules
@@ -82,6 +82,8 @@ build-arch: build-stamp
 	# build askpass and passdev keyscripts
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -pedantic -std=c99 debian/askpass.c -o debian/askpass
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -pedantic -std=c99 debian/passdev.c -o debian/scripts/passdev
+	# update the translation template
+	$(MAKE) -C po cryptsetup.pot-update
 
 build: build-indep build-arch
 
@@ -152,7 +154,7 @@ install-stamp: build-stamp
 		$(CURDIR)/debian/cryptsetup/usr/share/cryptsetup/initramfs/bin/cryptroot-unlock
 	install -m 0755 debian/initramfs/cryptroot-unlock-hook \
 		$(CURDIR)/debian/cryptsetup/usr/share/initramfs-tools/hooks/cryptroot-unlock
-	install -m 0755 debian/initramfs/cryptroot-script \
+	install -m 0755 debian/initramfs/cryptroot-script.sh \
 		$(CURDIR)/debian/cryptsetup/usr/share/initramfs-tools/scripts/local-top/cryptroot
 	install -m 0755 debian/initramfs/cryptroot-script-block \
 		$(CURDIR)/debian/cryptsetup/usr/share/initramfs-tools/scripts/local-block/cryptroot
-- 
2.15.1

