1 #!/bin/bash |
1 #!/bin/bash |
2 |
2 |
3 # TODO |
3 function print_usage_and_exit() { |
4 # http://ftp.mozilla.org/pub/firefox/candidates/48.0-candidates/build2/linux-x86_64/en-US/firefox-48.0.json |
4 echo "Usage: create-tar.sh tar_stamp" |
5 # "moz_source_stamp": "c1de04f39fa956cfce83f6065b0e709369215ed5" |
5 echo "" |
6 # http://ftp.mozilla.org/pub/firefox/candidates/48.0-candidates/build2/l10n_changesets.txt |
6 echo "Where tar_stamp should look like this:" |
7 |
7 echo "" |
8 CHANNEL="release" |
8 cat << EOF |
|
9 # Node ID: 64ee63facd4ff96b3e8590cff559d7e97ac6b061 |
|
10 PRODUCT="firefox" # "firefox" or "thunderbird" |
|
11 CHANNEL="esr60" |
|
12 VERSION="60.7.0" |
|
13 VERSION_SUFFIX="esr" |
|
14 FF_RELEASE_TAG="" # Needs only to be set if no tar-ball can be downloaded |
|
15 TB_RELEASE_TAG="" # Only relevant for Thunderbird |
|
16 PREV_VERSION="60.6.3" # Prev. version only needed for locales (leave empty to force l10n-generation) |
|
17 PREV_VERSION_SUFFIX="esr" |
|
18 #SKIP_LOCALES="" # Uncomment to skip l10n and compare-locales-generation |
|
19 EOF |
|
20 |
|
21 exit 1 |
|
22 } |
|
23 |
|
24 if [ $# -ne 1 ]; then |
|
25 print_usage_and_exit |
|
26 fi |
|
27 |
|
28 # Sourcing the given tar_stamp-file to have the variables available |
|
29 source "$1" || print_usage_and_exit |
|
30 |
|
31 # Internal variables |
9 BRANCH="releases/mozilla-$CHANNEL" |
32 BRANCH="releases/mozilla-$CHANNEL" |
10 RELEASE_TAG="ea5154beddff08b919697e3bed6f38cfe3a3d82f" |
33 if [ "$PRODUCT" = "firefox" ]; then |
11 VERSION="67.0.4" |
34 LOCALE_FILE="firefox-$VERSION/browser/locales/l10n-changesets.json" |
12 VERSION_SUFFIX="" |
35 else |
13 LOCALE_FILE="firefox-$VERSION/browser/locales/l10n-changesets.json" |
36 LOCALE_FILE="thunderbird-$VERSION/comm/mail/locales/l10n-changesets.json" |
|
37 fi |
|
38 |
|
39 SOURCE_TARBALL="$PRODUCT-$VERSION$VERSION_SUFFIX.source.tar.xz" |
|
40 FTP_URL="https://ftp.mozilla.org/pub/$PRODUCT/releases/$VERSION$VERSION_SUFFIX/source" |
|
41 # Make first letter of PRODCUT upper case |
|
42 PRODUCT_CAP="${PRODUCT^}" |
|
43 LOCALES_URL="https://product-details.mozilla.org/1.0/l10n/$PRODUCT_CAP" |
|
44 # Exit script on CTRL+C |
|
45 trap "exit" INT |
|
46 |
|
47 function check_tarball_source () { |
|
48 TARBALL=$1 |
|
49 # Print out what is going to be done: |
|
50 if [ -e $TARBALL ]; then |
|
51 echo "Reuse existing file" |
|
52 elif wget --spider $FTP_URL/$TARBALL 2> /dev/null; then |
|
53 echo "Download file" |
|
54 else |
|
55 echo "Mercurial checkout" |
|
56 fi |
|
57 } |
|
58 |
|
59 function ask_cont_abort_question() { |
|
60 while true; do |
|
61 read -p "$1 [(c)ontinue/(a)bort] " ca |
|
62 case $ca in |
|
63 [Cc]* ) return 0 ;; |
|
64 [Aa]* ) return 1 ;; |
|
65 * ) echo "Please answer c or a.";; |
|
66 esac |
|
67 done |
|
68 } |
|
69 |
|
70 function check_for_binary() { |
|
71 if ! test -x $1; then |
|
72 echo "$1 is missing: execute zypper in $2" |
|
73 exit 5 |
|
74 fi |
|
75 } |
|
76 |
|
77 function locales_get() { |
|
78 TMP_VERSION="$1" |
|
79 URL_TO_CHECK="${LOCALES_URL}-${TMP_VERSION}" |
|
80 |
|
81 LAST_FOUND="" |
|
82 # Unfortunately, locales-files are not associated to releases, but to builds. |
|
83 # And since we don't know which build was the final build, we go from 1 to |
|
84 # the last we find and try to find the latest one that exists. |
|
85 # Error only if not even the first one exists |
|
86 for BUILD_ID in $(seq 1 9); do |
|
87 FINAL_URL="${URL_TO_CHECK}-build${BUILD_ID}.json" |
|
88 if wget --quiet --spider "$FINAL_URL"; then |
|
89 LAST_FOUND="$FINAL_URL" |
|
90 elif [ $BUILD_ID -gt 1 ]; then |
|
91 echo "$LAST_FOUND" |
|
92 return 0 |
|
93 else |
|
94 echo "Error: Could not find locales-file (json) for Firefox $TMP_VERSION !" 1>&2 |
|
95 return 1 |
|
96 fi |
|
97 done |
|
98 } |
|
99 |
|
100 function locales_parse() { |
|
101 URL="$1" |
|
102 curl -s "$URL" | python -c "import json; import sys; \ |
|
103 print('\n'.join(['{} {}'.format(key, value['changeset']) \ |
|
104 for key, value in sorted(json.load(sys.stdin)['locales'].items())]));" |
|
105 } |
|
106 |
|
107 function locales_unchanged() { |
|
108 # If no json-file for one of the versions can be found, we say "they changed" |
|
109 prev_url=$(locales_get "$PREV_VERSION$PREV_VERSION_SUFFIX") || return 1 |
|
110 curr_url=$(locales_get "$VERSION$VERSION_SUFFIX") || return 1 |
|
111 |
|
112 prev_content=$(locales_parse "$prev_url") || exit 1 |
|
113 curr_content=$(locales_parse "$curr_url") || exit 1 |
|
114 |
|
115 diff -y --suppress-common-lines -d <(echo "$prev_content") <(echo "$curr_content") |
|
116 } |
14 |
117 |
15 # check required tools |
118 # check required tools |
16 test -x /usr/bin/hg || ( echo "hg missing: execute zypper in mercurial"; exit 5 ) |
119 check_for_binary /usr/bin/hg "mercurial" |
17 test -x /usr/bin/jq || ( echo "jq missing: execute zypper in jq"; exit 5 ) |
120 check_for_binary /usr/bin/jq "jq" |
|
121 which python > /dev/null || exit 1 |
18 |
122 |
19 # use parallel compression, if available |
123 # use parallel compression, if available |
20 compression='-J' |
124 compression='-J' |
21 pixz -h > /dev/null 2>&1 |
125 pixz -h > /dev/null 2>&1 |
22 if (($? != 127)); then |
126 if (($? != 127)); then |
23 compression='-Ipixz' |
127 compression='-Ipixz' |
24 fi |
128 fi |
25 |
129 |
|
130 if [ -z ${SKIP_LOCALES+x} ]; then |
|
131 # TODO: Thunderbird has usually "default" as locale entry. |
|
132 # There we probably need to double-check Firefox-locals |
|
133 # For now, just download every time for Thunderbird |
|
134 if [ "$PRODUCT" = "firefox" ] && [ "$PREV_VERSION" != "" ] && locales_unchanged; then |
|
135 printf "%-40s: Did not change. Skipping.\n" "locales" |
|
136 LOCALES_CHANGED=0 |
|
137 else |
|
138 printf "%-40s: Need to download.\n" "locales" |
|
139 LOCALES_CHANGED=1 |
|
140 fi |
|
141 else |
|
142 printf "%-40s: User forced skip (SKIP_LOCALES set)\n" "locales" |
|
143 fi |
|
144 |
|
145 # Check what is going to be done and ask for consent |
|
146 for ff in $SOURCE_TARBALL $SOURCE_TARBALL.asc; do |
|
147 printf "%-40s: %s\n" $ff "$(check_tarball_source $ff)" |
|
148 done |
|
149 |
|
150 $(ask_cont_abort_question "Is this ok?") || exit 0 |
|
151 |
|
152 # Try to download tar-ball from officiall mozilla-mirror |
|
153 if [ ! -e $SOURCE_TARBALL ]; then |
|
154 wget https://ftp.mozilla.org/pub/$PRODUCT/releases/$VERSION$VERSION_SUFFIX/source/$SOURCE_TARBALL |
|
155 fi |
|
156 # including signature |
|
157 if [ ! -e $SOURCE_TARBALL.asc ]; then |
|
158 wget https://ftp.mozilla.org/pub/$PRODUCT/releases/$VERSION$VERSION_SUFFIX/source/$SOURCE_TARBALL.asc |
|
159 fi |
|
160 |
26 # we might have an upstream archive already and can skip the checkout |
161 # we might have an upstream archive already and can skip the checkout |
27 if [ -e firefox-$VERSION$VERSION_SUFFIX.source.tar.xz ]; then |
162 if [ -e $SOURCE_TARBALL ]; then |
28 echo "skip firefox checkout and use available archive" |
163 if [ -z ${SKIP_LOCALES+x} ]; then |
29 # still need to extract the locale information from the archive |
164 # still need to extract the locale information from the archive |
30 echo "extract locale changesets" |
165 echo "extract locale changesets" |
31 tar -xf firefox-$VERSION$VERSION_SUFFIX.source.tar.xz $LOCALE_FILE |
166 tar -xf $SOURCE_TARBALL $LOCALE_FILE |
|
167 fi |
32 else |
168 else |
|
169 # We are working on a version that is not yet published on the mozilla mirror |
|
170 # so we have to actually check out the repo |
|
171 |
33 # mozilla |
172 # mozilla |
34 if [ -d firefox-$VERSION ]; then |
173 if [ -d $PRODUCT-$VERSION ]; then |
35 pushd firefox-$VERSION |
174 pushd $PRODUCT-$VERSION || exit 1 |
36 _repourl=$(hg paths) |
175 _repourl=$(hg paths) |
37 case "$_repourl" in |
176 case "$_repourl" in |
38 *$BRANCH*) |
177 *$BRANCH*) |
39 echo "updating previous tree" |
178 echo "updating previous tree" |
40 hg pull |
179 hg pull |
41 popd |
180 popd || exit 1 |
42 ;; |
181 ;; |
43 * ) |
182 * ) |
44 echo "removing obsolete tree" |
183 echo "removing obsolete tree" |
45 popd |
184 popd || exit 1 |
46 rm -rf firefox-$VERSION |
185 rm -rf $PRODUCT-$VERSION |
47 ;; |
186 ;; |
48 esac |
187 esac |
49 fi |
188 fi |
50 if [ ! -d firefox-$VERSION ]; then |
189 if [ ! -d $PRODUCT-$VERSION ]; then |
51 echo "cloning new $BRANCH..." |
190 echo "cloning new $BRANCH..." |
52 hg clone http://hg.mozilla.org/$BRANCH firefox-$VERSION |
191 hg clone http://hg.mozilla.org/$BRANCH $PRODUCT-$VERSION |
53 fi |
192 if [ "$PRODUCT" = "thunderbird" ]; then |
54 pushd firefox-$VERSION |
193 hg clone http://hg.mozilla.org/releases/comm-$CHANNEL thunderbird-$VERSION/comm |
55 hg update --check |
194 fi |
56 [ "$RELEASE_TAG" == "default" ] || hg update -r $RELEASE_TAG |
195 fi |
|
196 pushd $PRODUCT-$VERSION || exit 1 |
|
197 hg update --check $FF_RELEASE_TAG |
|
198 [ "$FF_RELEASE_TAG" == "default" ] || hg update -r $FF_RELEASE_TAG |
57 # get repo and source stamp |
199 # get repo and source stamp |
58 echo -n "REV=" > ../source-stamp.txt |
200 echo -n "REV=" > ../source-stamp.txt |
59 hg -R . parent --template="{node|short}\n" >> ../source-stamp.txt |
201 hg -R . parent --template="{node|short}\n" >> ../source-stamp.txt |
60 echo -n "REPO=" >> ../source-stamp.txt |
202 echo -n "REPO=" >> ../source-stamp.txt |
61 hg showconfig paths.default 2>/dev/null | head -n1 | sed -e "s/^ssh:/http:/" >> ../source-stamp.txt |
203 hg showconfig paths.default 2>/dev/null | head -n1 | sed -e "s/^ssh:/http:/" >> ../source-stamp.txt |
62 popd |
204 |
|
205 if [ "$PRODUCT" = "thunderbird" ]; then |
|
206 pushd comm || exit 1 |
|
207 hg update --check $TB_RELEASE_TAG |
|
208 popd || exit 1 |
|
209 rm -rf thunderbird-${VERSION}/{,comm/}other-licenses/7zstub |
|
210 fi |
|
211 popd || exit 1 |
63 |
212 |
64 echo "creating archive..." |
213 echo "creating archive..." |
65 tar $compression -cf firefox-$VERSION$VERSION_SUFFIX.source.tar.xz --exclude=.hgtags --exclude=.hgignore --exclude=.hg --exclude=CVS firefox-$VERSION |
214 tar $compression -cf $PRODUCT-$VERSION$VERSION_SUFFIX.source.tar.xz --exclude=.hgtags --exclude=.hgignore --exclude=.hg --exclude=CVS $PRODUCT-$VERSION |
66 fi |
215 fi |
67 |
216 |
68 # l10n |
217 if [ ! -z ${SKIP_LOCALES+x} ]; then |
69 echo "fetching locales..." |
218 echo "Skipping locales-creation." |
70 test ! -d l10n && mkdir l10n |
219 exit 0 |
71 jq -r 'to_entries[]| "\(.key) \(.value|.revision)"' $LOCALE_FILE | \ |
220 fi |
72 while read locale changeset ; do |
221 |
73 case $locale in |
222 if [ $LOCALES_CHANGED -ne 0 ]; then |
74 ja-JP-mac|en-US) |
223 # l10n |
75 ;; |
224 echo "fetching locales..." |
76 *) |
225 test ! -d l10n && mkdir l10n |
77 echo "reading changeset information for $locale" |
226 jq -r 'to_entries[]| "\(.key) \(.value|.revision)"' $LOCALE_FILE | \ |
78 echo "fetching $locale changeset $changeset ..." |
227 while read locale changeset ; do |
79 hg clone http://hg.mozilla.org/l10n-central/$locale l10n/$locale |
228 case $locale in |
80 [ "$RELEASE_TAG" == "default" ] || hg -R l10n/$locale up -C -r $changeset |
229 ja-JP-mac|en-US) |
81 ;; |
230 ;; |
82 esac |
231 *) |
83 done |
232 echo "reading changeset information for $locale" |
84 echo "creating l10n archive..." |
233 echo "fetching $locale changeset $changeset ..." |
85 tar $compression -cf l10n-$VERSION$VERSION_SUFFIX.tar.xz --exclude=.hgtags --exclude=.hgignore --exclude=.hg l10n |
234 if [ -d "l10n/$locale/.hg" ]; then |
|
235 pushd "l10n/$locale" || exit 1 |
|
236 hg pull |
|
237 popd || exit 1 |
|
238 else |
|
239 hg clone "http://hg.mozilla.org/l10n-central/$locale" "l10n/$locale" |
|
240 fi |
|
241 [ "$FF_RELEASE_TAG" == "default" ] || hg -R "l10n/$locale" up -C -r "$changeset" |
|
242 ;; |
|
243 esac |
|
244 done |
|
245 echo "creating l10n archive..." |
|
246 if [ "$PRODUCT" = "thunderbird" ]; then |
|
247 TB_TAR_FLAGS="--exclude=browser --exclude=suite" |
|
248 fi |
|
249 tar $compression -cf l10n-$VERSION$VERSION_SUFFIX.tar.xz \ |
|
250 --exclude=.hgtags --exclude=.hgignore --exclude=.hg \ |
|
251 $TB_TAR_FLAGS \ |
|
252 l10n |
|
253 fi |
86 |
254 |
87 # compare-locales |
255 # compare-locales |
88 echo "creating compare-locales" |
256 echo "creating compare-locales" |
89 hg clone http://hg.mozilla.org/build/compare-locales |
257 if [ -d compare-locales/.hg ]; then |
|
258 pushd compare-locales || exit 1 |
|
259 hg pull |
|
260 popd || exit 1 |
|
261 else |
|
262 hg clone http://hg.mozilla.org/build/compare-locales |
|
263 fi |
90 tar $compression -cf compare-locales.tar.xz --exclude=.hgtags --exclude=.hgignore --exclude=.hg compare-locales |
264 tar $compression -cf compare-locales.tar.xz --exclude=.hgtags --exclude=.hgignore --exclude=.hg compare-locales |
91 |
265 |