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

« back to all changes in this revision

Viewing changes to merge-tarballs

  • Committer: Sebastien Bacher
  • Date: 2021-11-22 16:04:05 UTC
  • mfrom: (594.2.1 langpack-o-matic)
  • Revision ID: seb128@ubuntu.com-20211122160405-17hx41i98tvg459q
The repository has been moved to git

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh -e
2
 
 
3
 
# this is part of langpack-o-matic, by Martin Pitt <martin.pitt@canonical.com>
4
 
#
5
 
# (C) 2005-2015 Canonical Ltd.
6
 
#
7
 
# Merge multiple translation tarballs.
8
 
 
9
 
[ $# -lt 3 ] && {
10
 
    echo "Usage: $0 <input tarball 1> <input tarball 2> ... <input tarball n> <output tarball>" >&2
11
 
    exit 1
12
 
}
13
 
 
14
 
TD=$(mktemp -d)
15
 
# initial trap for script interruption
16
 
trap "rm -rf $TD" 0 1 2 3 13 15
17
 
 
18
 
# extract the first tarball - all others will be merged sequentially into that one
19
 
tar -C $TD -xz < "$1"
20
 
shift 1
21
 
TOPD="$TD/$(ls "$TD")"
22
 
cp "$TOPD/mapping.txt" "$TOPD/mapping.txt.merged"
23
 
MAIN=`pwd`
24
 
 
25
 
TS=$(mktemp -d)
26
 
trap "rm -rf $TD $TS" 0 1 2 3 13 15
27
 
 
28
 
while [ "$#" != "1" ]; do
29
 
    tar -C $TS -xz < "$1"
30
 
    TOPS="$TS/$(ls "$TS")"
31
 
 
32
 
    # copy PO and POT files
33
 
    cd "$TOPS"
34
 
    find \( -name "*.po" -o -name "*.pot" \) -exec install -D -m 644 '{}' "$TOPD/{}" \;
35
 
 
36
 
    # timestamp
37
 
    cp "$TOPS/timestamp.txt" "$TOPD"
38
 
 
39
 
    # append domain maps
40
 
    cat "$TOPS/mapping.txt" >> "$TOPD/mapping.txt.merged"
41
 
 
42
 
    shift 1
43
 
    cd $MAIN
44
 
    rm -rf $TS/*
45
 
done
46
 
 
47
 
# merge the domain maps
48
 
sort -u "$TOPD/mapping.txt.merged" > "$TOPD/mapping.txt"
49
 
rm "$TOPD/mapping.txt.merged"
50
 
 
51
 
rmdir $TS
52
 
 
53
 
if echo "$1" | grep -q '^/'; then
54
 
    # absolute path
55
 
    OUT="$1"
56
 
else
57
 
    # relative path
58
 
    OUT="$(pwd)/$1"
59
 
fi
60
 
 
61
 
cd "$TD"
62
 
tar c . | gzip -9 > "$OUT"
63