~ubuntu-langpack/langpack-o-matic/main

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
#!/bin/sh -e

# this is part of langpack-o-matic, by Martin Pitt <martin.pitt@canonical.com>
#
# (C) 2005-2015 Canonical Ltd.
#
# Merge multiple translation tarballs.

[ $# -lt 3 ] && {
    echo "Usage: $0 <input tarball 1> <input tarball 2> ... <input tarball n> <output tarball>" >&2
    exit 1
}

TD=$(mktemp -d)
# initial trap for script interruption
trap "rm -rf $TD" 0 1 2 3 13 15

# extract the first tarball - all others will be merged sequentially into that one
tar -C $TD -xz < "$1"
shift 1
TOPD="$TD/$(ls "$TD")"
cp "$TOPD/mapping.txt" "$TOPD/mapping.txt.merged"
MAIN=`pwd`

TS=$(mktemp -d)
trap "rm -rf $TD $TS" 0 1 2 3 13 15

while [ "$#" != "1" ]; do
    tar -C $TS -xz < "$1"
    TOPS="$TS/$(ls "$TS")"

    # copy PO and POT files
    cd "$TOPS"
    find \( -name "*.po" -o -name "*.pot" \) -exec install -D -m 644 '{}' "$TOPD/{}" \;

    # timestamp
    cp "$TOPS/timestamp.txt" "$TOPD"

    # append domain maps
    cat "$TOPS/mapping.txt" >> "$TOPD/mapping.txt"

    shift 1
    cd $MAIN
    rm -rf $TS/*
done

# merge the domain maps
sort -u "$TOPD/mapping.txt.merged" > "$TOPD/mapping.txt"

rmdir $TS

if echo "$1" | grep -q '^/'; then
    # absolute path
    OUT="$1"
else
    # relative path
    OUT="$(pwd)/$1"
fi

cd "$TD"
tar c . | gzip -9 > "$OUT"