-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·149 lines (109 loc) · 3.8 KB
/
update.sh
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
#!/bin/sh
timestamp=$(date +%Y-%m-%d--%H:%M:%S)
if [[ $# -eq 0 ]]; then
v=`$0 bar 2>&1`
echo "$v" > $timestamp.log
exit
fi
# remove json documents older than 50 days
find json/* -mtime +50 -exec rm {} \;
############# create empty git repo ###########################################
if [ ! -f .do_not_redownload_everything ]; then
echo "running init on the GIT repository"
rm -Rf db
rm -Rf git
rm -Rf json
mkdir db
mkdir git
mkdir json
pushd git
git init
cp ../README.raw > README.md
git add README.md
git commit -m 'first commit'
git remote add origin git@github.com:nixcloud/wordpress-translations.git
git push -u origin master
popd
touch .do_not_redownload_everything
fi
############# /create empty git repo ###########################################
############# get a list of current versiosn ###########################################
versionFile="json/versions-$timestamp.json"
curl https://api.wordpress.org/core/version-check/1.7/ | jq '.' > $versionFile
num=$(cat $versionFile | jq '.offers | length ')
n=$(expr $num - 1)
foundVersions=""
for i in `seq 0 $n`; do
version=$(cat $versionFile| jq ".offers[$i].version" | egrep -o '[0-9]+.[0-9]+')
# echo $version
majorVersion=$(expr substr $version 1 1)
if [ $majorVersion -lt 4 ]; then
continue
fi
foundVersions+=$version
foundVersions+=" "
done
echo "this are the versions >= 4.x series"
echo " " $foundVersions
############# /get a list of current versiosn ###########################################
############# download all found languages ###########################################
for versionIterator in $foundVersions; do
languageJson=json/wp-languages-$timestamp-$versionIterator.json
curl "https://api.wordpress.org/translations/core/1.0/?version=$versionIterator" | jq '.' > $languageJson
num=$(cat $languageJson | jq '.translations | length ')
n=$(expr $num - 1)
echo "$n records found"
for i in `seq 0 $n`; do
language=$(cat $languageJson | jq ".translations[$i].language" | sed -e 's/\"//g')
package=$(cat $languageJson | jq ".translations[$i].package" | sed -e 's/\"//g')
version=$(cat $languageJson | jq ".translations[$i].version" | sed -e 's/\"//g')
updated=$(cat $languageJson | jq ".translations[$i].updated" | sed -e 's/\"//g')
echo "------ ${language}-${versionIterator} ----------------------------------------------"
echo $i $package $version $updated
touch db/${language}-${versionIterator}
l=$(cat db/${language}-${versionIterator})
if [ "$l" == "$updated" ]; then
echo "no update for ${language}-${versionIterator} needed as "$l" equals "$updated""
else
echo "update for ${language}-${versionIterator} needed"
mkdir tmp
rm -Rf tmp/*
wget "$package" -O tmp/${language}.zip
ret=$?
if [ $ret != 0 ]; then
echo "download of ${language}-${versionIterator} failed, skipping this one..."
continue
fi
pushd tmp
unzip ${language}.zip
rm ${language}.zip
popd
pushd git
# check if branch exists already
git checkout ${language}-${versionIterator}
ret=$?
if [ $ret != 0 ]; then
# create a orphan branch with no prior history
echo "git returned $ret, so creating orphan branch"
git checkout --orphan ${language}-${versionIterator}
git rm -rf .
else
rm -Rf *
fi
cp ../tmp/* .
git add *
git commit -m "${language}-${versionIterator}: update $updated"
popd
rm -Rf tmp/*
echo $updated > db/${language}-${versionIterator}
fi
done
done
############# /download all found languages ###########################################
pushd git
git checkout master
cp ../$0 .
git add $0
git commit -m "new version of $0"
git push --all origin
popd