Welcome to mirror list, hosted at ThFree Co, Russian Federation.

updateLanguageFiles.sh « misc - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ad201446ede830ac0ed334f4d9bc008d1f46a74 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
PIWIKPATH=$PWD/..

################################
# Configuration
#
GitBranchName="translationupdates"
OTranceUser="downloaduser"
#
################################

################################
#  Perform initial git actions
#
# update master branch
git checkout master > /dev/null 2>&1
git pull > /dev/null 2>&1

# check if branch exists local (assume its the correct one if so)
git branch | grep $GitBranchName > /dev/null 2>&1

if [ $? -eq 1 ]; then
    git checkout -b $GitBranchName origin/$GitBranchName > /dev/null 2>&1
fi

# switch to branch and merge with master
git checkout $GitBranchName > /dev/null 2>&1
git merge master > /dev/null 2>&1
git push origin $GitBranchName > /dev/null 2>&1
#
################################

################################
# Fetch package from oTrance
#
read -s -p "Please provide the OTrance password for 'downloaduser'? " OTrancePassword

# download package
echo "Starting to fetch latest language pack"
wget --save-cookies $PIWIKPATH/tmp/cookies.txt \
     --quiet \
     -O - \
     --keep-session-cookies \
     --post-data "user=$OTranceUser&pass=$OTrancePassword&autologin=1" \
     http://translations.piwik.org/public/index/login \
     > /dev/null 2>&1

# create a new download package if wanted
while true; do
    read -p "Shall we create a new language pack? " yn
    case $yn in
        [Yy]* ) wget --load-cookies $PIWIKPATH/tmp/cookies.txt \
                     --quiet \
                     -O - \
                     http://translations.piwik.org/public/export/update.all \
                     > /dev/null 2>&1; break;;
        [Nn]* ) echo "Searching for existing packs instead"; break;;
        * ) echo "Please answer yes or no. ";;
    esac
done

# Search for package and download it
downloadfile=(`wget --load-cookies $PIWIKPATH/tmp/cookies.txt \
                    --quiet \
                    -O - \
                    http://translations.piwik.org/public/downloads/ \
                    | grep -Pom 1 '(language\_pack\-[0-9]{8}\-[0-9]{6}\.tar\.gz)'`)

while true; do
    read -p "Found language pack $downloadfile. Proceed? " yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no. ";;
    esac
done

wget --load-cookies $PIWIKPATH/tmp/cookies.txt \
     -O $PIWIKPATH/tmp/language_pack.tar.gz \
     http://translations.piwik.org/public/downloads/download/file/$downloadfile

# remove cookie file
rm -f $PIWIKPATH/tmp/cookies.txt

# extract package
echo "Extracting package..."
cd $PIWIKPATH/tmp
gunzip -q -c $PIWIKPATH/tmp/language_pack.tar.gz | tar xvf - > /dev/null 2>&1

if [ $? -gt 0 ]; then
    echo "Error: Unable to extract download package. Aborting..."
    exit;
fi

# remove downloaded file
rm -f $PIWIKPATH/tmp/language_pack.tar.gz

#
################################

################################
# Check extracted files
#
# remove some useless files from package data
rm -f en.php
rm -f pt_BR.php
rm -f zh_CN.php
rm -f zh_TW.php

# copy all files to /lang (except en.php)
mv *.php ../lang/

# get untracked files and ask if each file should be removed or added
cd $PIWIKPATH
list=(`git ls-files --other --exclude-standard lang`)

echo "Untracked language files detected:
    Please choose the files that should be added to git.
    Other files will be removed.";

for file in ${list[@]}
do
    while true; do
        read -p "Add new file $file to git? " yn
        case $yn in
            [Yy]* ) git add $file; break;;
            [Nn]* ) rm $file; break;;
            * ) echo "Please answer yes or no. ";;
        esac
    done
done
#
################################

################################
# Cleanup / Test new files
#
# run tests to cleanup files as long as tests are failing
counter=0
while true; do

    # if tests fail 3 times, abort as they won't pass
    if [ $counter -eq 3 ]; then
        echo "Tests have failed 3 times. Aborting..."
        exit;
    fi

    # run tests to cleanup files
    echo "Running unittests to cleanup language files. This may take some time..."
    cd $PIWIKPATH/tests/PHPUnit
    phpunit --group LanguagesManager > /dev/null 2>&1

    # If all tests pass, break loop
    if [ $? -eq 0 ]; then
        echo "All files OK."
        break;
    fi

    echo "Files cleaned."

    # move cleaned files from /tmp to /lang
    echo "Moving cleaned language files from /tmp to /lang"
    cd $PIWIKPATH/tmp
    mv *.php ../lang/

    counter=$(($counter + 1))
done
#
################################

################################
# Perform finish git actions & create pull request
#
# commit files
cd $PIWIKPATH
git add lang/. > /dev/null 2>&1
git commit -m "language update refs #3430"
git push

while true; do
    read -p "Please provide your github username (to create a pull request using Github API): " username

    returnCode=(`curl \
         -X POST \
         -k \
         --silent \
         --write-out %{http_code} \
         --stderr /dev/null \
         -o /dev/null \
         -u $username \
         --data "{\"title\":\"automatic translation update\",\"body\":\"autogenerated translation update out of $downloadfile\",\"head\":\"$GitBranchName\",\"base\":\"master\"}" \
         -H 'Accept: application/json' \
         https://api.github.com/repos/piwik/piwik/pulls`);

    if [ $returnCode -eq 401 ]; then
        echo "Pull request failed. Bad credentials... Please try again"
        continue;
    fi

    if [ $returnCode -eq 422 ]; then
        echo "Pull request failed. Unprocessable Entity. Maybe a pull request was already created before."
        break;
    fi

    if [ $returnCode -eq 201 ]; then
        echo "Pull request successfully created."
        break;
    fi

    if [ $returnCode -eq 200 ]; then
        echo "Pull request successfully created."
        break;
    fi

    echo "Pull request failed."

done;

git checkout master > /dev/null 2>&1
#
################################