~dsmythies/installation-guide/ubuntu-20.04

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /bin/sh

lang="$1"

filter_preseed() {
	awk '/^#~/ {
		next
	     }
	     /^\"?#?d-i / {
		print
	        in_setting=1
		if (/\\+[[:space:]]*(\\n\")?$/) {in_seq=1}
		next
	     }
	     /\\+[[:space:]]*(\\n\")?$/ {
		if (in_setting) {
			print
			in_seq=1
			next
		}
	     }
	     /.*/ {
		if (in_seq) {
			print
			in_seq=0
		}
		in_setting=0
             }'
}

if [ -z "$lang" ] || ([ ! -d po/"$lang" ] && [ ! -d "./$lang" ]); then
	echo "Usage: $(basename $0) <language>"
	exit 1
fi

echo "This script performs a very basic sanity check to see if nothing has"
echo "been missed in the translation of the preconfiguration appendix."
echo "It does this by counting the number of lines that start with 'd-i' or"
echo "'#d-i' (plus any continuation lines) for both the original and the"
echo "translation and printing the result. It will then print a diff between"
echo "original and translation for a visual check."
echo
echo

tmp_orig=$(mktemp -p /tmp preseed_orig.XXXXXX)
tmp_trans=$(mktemp -p /tmp preseed_trans.XXXXXX)

if [ -d "po/$lang" ]; then
	cd po/$lang

	msgattrib --no-wrap preseed.po | \
		sed -n "/^msgid/,/^msgstr/ p" | grep -v msgstr | \
		filter_preseed >$tmp_orig
	msgattrib --no-wrap preseed.po | \
		sed -n "/^msgstr/,/^$/ p" | \
		filter_preseed >$tmp_trans
else
	filter_preseed <en/appendix/preseed.xml >$tmp_orig
	filter_preseed <$lang/appendix/preseed.xml >$tmp_trans
fi

echo "Number of original lines:   $(wc -l <$tmp_orig)"
echo "Number of translated lines: $(wc -l <$tmp_trans)"
echo

diff -U0 $tmp_orig $tmp_trans

rm -f $tmp_orig $tmp_trans