www.fgks.org   »   [go: up one dir, main page]

summaryrefslogtreecommitdiff
path: root/makeicecat
blob: 601f24cb7b9302c1be0ae43e9810415787c92d85 (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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
#!/bin/bash
#
#    Copyright (C) 2014,2015  Ruben Rodriguez <ruben@gnu.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#

set -e

FFMAJOR=38
FFMINOR=3
FFSUB=0
GNUVERSION=1
FFVERSION=$FFMAJOR.$FFMINOR.${FFSUB}
ICECATVERSION=$FFVERSION-gnu$GNUVERSION
SOURCEDIR=icecat-$FFVERSION

CODENAME=trusty
REVISION=1065
#CODENAME=precise
#REVISION=993

export DEBEMAIL=ruben@gnu.org
export DEBFULLNAME="Ruben Rodriguez"

DATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/data

mkdir output
cd output

###############################################################################
# Retrieve FF source code
###############################################################################

rm mozilla-esr${FFMAJOR} $SOURCEDIR -rf

wget -N http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/${FFVERSION}esr/source/firefox-${FFVERSION}esr.source.tar.bz2
#wget -N ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/${FFVERSION}esr/source/firefox-${FFVERSION}esr.source.tar.bz2.asc
#gpg --recv-keys --keyserver keyserver.ubuntu.com 15A0A4BC
#gpg --verify firefox-${FFVERSION}esr.source.tar.bz2.asc

echo Extracting Firefox tarball
tar -jxf firefox-${FFVERSION}esr.source.tar.bz2

mv mozilla-esr${FFMAJOR} $SOURCEDIR

###############################################################################
# Retrieve /debian from Ubuntu
###############################################################################

rm -rf firefox.$CODENAME
bzr branch https://code.launchpad.net/~mozillateam/firefox/firefox.$CODENAME
cd firefox.$CODENAME
bzr revert -r$REVISION
echo '3.0 (native)' > debian/source/format

for PATCH in ubuntu-bookmarks.patch ubuntu-ua-string-changes.patch unity-menubar.patch fix-broken-langpack-install-manifests.patch
do
  rm debian/patches/$PATCH
  sed "/$PATCH/d" -i debian/patches/series
done
cd ..

mv firefox.$CODENAME/debian $SOURCEDIR
rm -rf firefox.$CODENAME

###############################################################################
# Retrieve l10n
###############################################################################

hg clone http://hg.mozilla.org/build/compare-locales/
cd compare-locales/
hg checkout FIREFOX_${FFMAJOR}_${FFMINOR}_${FFSUB}esr_RELEASE
cd ..
rm compare-locales/.hg* compare-locales/.git* -rf
mv compare-locales $SOURCEDIR/python/

mkdir l10n
cd l10n
while read line;do
    line=$(echo $line |cut -d' ' -f1)
    #[ $line = "es-ES" ] || continue
    [ $line = "en-US" ] && continue
    hg clone http://hg.mozilla.org/releases/l10n/mozilla-release/$line
    cd $line
    hg checkout FIREFOX_31_0esr_RELEASE || true
    hg checkout FIREFOX_${FFMAJOR}_${FFMINOR}_${FFSUB}esr_RELEASE || true
    mkdir -p $line/browser/chrome/browser/preferences
    touch $line/browser/chrome/browser/preferences/advanced-scripts.dtd
    rm -rf .hg*
    cd ..
done < ../$SOURCEDIR/browser/locales/shipped-locales
cd ..

mv l10n $SOURCEDIR

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

cd $SOURCEDIR

for patch in $DATA/patches/*; do
    echo Patching with file: $patch
    patch -p1 < $patch
done

cp $DATA/Changelog.IceCat $DATA/README.IceCat .
cp $DATA/Changelog.IceCat $DATA/README.IceCat debian
echo 'debian/README.IceCat
debian/Changelog.IceCat' >>  debian/docs

###############################################################################
# Functions
###############################################################################

sedhelper2(){
  FILE="$1"
  EXPR="$2"";"

  while [ 1"$EXPR" != 1 ];do
    SUBEXPR=$(cut -d\; -f 1 <<< "$EXPR")
    MD5=$(md5sum "$FILE")
    echo Running modification-aware sed: sed "$SUBEXPR" -i "$FILE"
    /bin/sed "$SUBEXPR" -i "$FILE"
    if [ "$MD5" = "$(md5sum "$FILE")" ]; then
      echo File "$FILE" was not modified, stopping.
      exit 1
    fi
    EXPR=$(cut -d\; -f 2- <<< "$EXPR" )
    echo $EXPR | egrep ';' -q || break
  done
}

sedhelper(){
  FILE="$1"
  EXPR="$2"

  MD5=$(md5sum "$FILE")
  echo Running modification-aware sed: sed "$EXPR" -i "$FILE"
  /bin/sed "$EXPR" -i "$FILE"
  if [ "$MD5" = "$(md5sum "$FILE")" ]; then
    echo File "$FILE" was not modified, stopping.
    exit 1
  fi
}

sed (){
if ! echo $@ | grep -qw '\-i'; then
  echo Running fallback sed: /bin/sed "$@"
  /bin/sed "$@"
else

[ 1"$1" = "1-i" ] && shift

  SEDEXPR="$1"
  shift
  for FILE in "$@"; do
  [ 1"$FILE" = "1-i" ] && continue
  if [ -f "$FILE" ]; then
    sedhelper "$FILE" "$SEDEXPR"
  else
    echo File "$FILE" does not exist, stopping.
    exit 1
  fi
  done
fi
}

###############################################################################
# Set variables and build config files
###############################################################################

INFOURL="www.gnu.org/software/gnuzilla/"
LEGALINFOURL="www.gnu.org/software/gnuzilla/"
ADDONSURL="www.gnu.org/software/gnuzilla/addons.html"
LISTURL="lists.gnu.org/mailman/listinfo/bug-gnuzilla"

cat << EOF > debian/distribution.ini
[Global]
id=gnu
version=$ICECATVERSION
about=GNU IceCat

[Preferences]
app.distributor = "GNU"
app.distributor.channel = "GNU"
app.partner.ubuntu = "GNU"
EOF

###############################################################################
# Custom settings and features
###############################################################################

# Disable healthreport
sed '/mozilla.org\/legal/d' -i services/healthreport/healthreport-prefs.js
cat << EOF >>services/healthreport/healthreport-prefs.js
pref("datareporting.healthreport.infoURL", "https://$INFOURL");
EOF

# Custom privacy statement link
sed "s%https://www.mozilla.org/legal/privacy/%https://$LEGALINFOURL%" -i ./browser/app/profile/firefox.js ./toolkit/content/aboutRights.xhtml

# Replace versions for building on Trisquel
sed 's/1310/70/g; s/1204/60/g; s/1210/65/g; s/1404/70/g' -i debian/config/mozconfig.in debian/firefox-dev.install.in debian/firefox-dev.links.in

# Enable gst support
cat << EOF >> debian/config/mozconfig.in
%%if DISTRIB_VERSION < 70
ac_add_options --enable-gstreamer=0.10
%%endif
EOF

# Set vendor string
sed 's/com.ubuntu/org.gnu/' -i debian/config/mozconfig.in

# Unbrand url codes for google and amazon
find debian/searchplugins |grep google| xargs -i /bin/sed '/ubuntu/d; /channel/d' -i {}
find debian/searchplugins |grep duck| xargs -i /bin/sed "s/canonical/gnu/" -i {}
find debian/searchplugins |grep amazon| xargs -i /bin/sed '/canoniccom/d;' -i {}
sed 's%duckduckgo.com/%duckduckgo.com/html%' -i debian/searchplugins/en-US/duckduckgo.xml

cp debian/searchplugins/en-US/duckduckgo.xml browser/locales/en-US/searchplugins
cp debian/searchplugins/en-US/duckduckgo.xml mobile/locales/en-US/searchplugins
echo -e '\nduckduckgo' >> browser/locales/en-US/searchplugins/list.txt
echo -e '\nduckduckgo' >> mobile/locales/en-US/searchplugins/list.txt
for DIR in $(ls l10n -1); do
  [ -d l10n/$DIR/browser/searchplugins/ ] || continue
  cp debian/searchplugins/en-US/duckduckgo.xml l10n/$DIR/browser/searchplugins/
  grep -q duckduckgo l10n/$DIR/browser/searchplugins/list.txt || echo -e '\nduckduckgo' >> l10n/$DIR/browser/searchplugins/list.txt
done
for DIR in $(ls l10n -1); do
  [ -d l10n/$DIR/mobile/searchplugins/ ] || continue
  cp debian/searchplugins/en-US/duckduckgo.xml l10n/$DIR/mobile/searchplugins/
  grep -q duckduckgo l10n/$DIR/mobile/searchplugins/list.txt || echo -e '\nduckduckgo' >> l10n/$DIR/mobile/searchplugins/list.txt
done

LINE=$(grep "error Plugin" debian/build/rules.mk -n | /bin/sed s/:.*//)
LINE=$(expr $LINE - 1)
sed "$LINE,+1 d" debian/build/rules.mk -i

# contact link
#sed "s_https://input.mozilla.org/feedback_https://${LISTURL}_" -i browser/base/content/utilityOverlay.js
sed  "s/^MOZ_APP_NAME\t.*/MOZ_APP_NAME\t\t:= icecat/;" debian/build/config.mk -i
sed  "s/^MOZ_PKG_NAME\t.*/MOZ_PKG_NAME\t\t:= icecat/;" debian/build/config.mk -i

# Hide help buttons in newtab page
for file in browser/base/content/newtab/newTab.css browser/themes/linux/newtab/newTab.css browser/themes/windows/newtab/newTab.css browser/themes/osx/newtab/newTab.css; do
  echo '#newtab-customize-button, #newtab-intro-what{display:none}' >> $file
done

###############################################################################
# Branding
###############################################################################

# Branding files
rm browser/branding/* mobile/android/branding/* -rf
cp -a $DATA/branding/icecat/ browser/branding/official
cp -a $DATA/branding/icecat/ browser/branding/nightly
cp -a $DATA/branding/icecatmobile/ mobile/android/branding/official
cp -a $DATA/branding/icecatmobile/ mobile/android/branding/unofficial
cp -a $DATA/branding/icecatmobile/ mobile/android/branding/nightly
cat << EOF > debian/config/branch.mk
CHANNEL                 = release
MOZ_WANT_UNIT_TESTS     = 0
# MOZ_BUILD_OFFICIAL    = 1
MOZ_ENABLE_BREAKPAD     = 0

MOZILLA_REPO = http://hg.mozilla.org/releases/mozilla-release
L10N_REPO = http://hg.mozilla.org/releases/l10n/mozilla-release
EOF

# Replace about:home
rm browser/base/content/abouthome -rf
cp $DATA/abouthome -a browser/base/content
sed '/mozilla.*png/d' -i ./browser/base/jar.mn

# Delete stuff we don't use and that may contain trademaked logos
rm -rf ./browser/metro ./addon-sdk/source/doc/static-files/media ./b2g

# Custom bookmarks
cp $DATA/bookmarks.html.in browser/locales/generic/profile/bookmarks.html.in

[ -d $DATA/searchplugins ] && cp $DATA/searchplugins debian/search -a
[ -d $DATA/searchplugins ] && echo "debian/search/* /usr/lib/icecat-addons/searchplugins" >> debian/firefox.install.in

# Custom legal about pages

find -wholename '*/brand.dtd' |xargs /bin/sed 's/trademarkInfo.part1.*/trademarkInfo.part1 "">/' -i

for STRING in community.end3 community.exp.end community.start2 community.mozillaLink community.middle2 community.creditsLink community.end2 contribute.start contribute.getInvolvedLink contribute.end channel.description.start channel.description.end
do
 find -name aboutDialog.dtd | xargs sed -i "s/ENTITY $STRING.*/ENTITY $STRING \"\">/"
done

for STRING in rights.intro-point3-unbranded rights.intro-point4a-unbranded rights.intro-point4b-unbranded rights.intro-point4c-unbranded
do
 find -name aboutRights.dtd | xargs sed -i "s/ENTITY $STRING.*/ENTITY $STRING \"\">/"
done

sed '/helpus.start/d' -i browser/base/content/aboutDialog.xul

cp $DATA/aboutRights.xhtml toolkit/content/aboutRights.xhtml
cp $DATA/aboutRights.xhtml toolkit/content/aboutRights-unbranded.xhtml

sed -i 's/<a\ href\=\"http\:\/\/www.mozilla.org\/\">Mozilla\ Project<\/a>/<a\ href\=\"http\:\/\/www.gnu.org\/\"\>GNU\ Project<\/a>/g' browser/base/content/overrides/app-license.html

###############################################################################
# Batch rebranding
###############################################################################

# Replace Firefox branding
find -type d | grep fennec | xargs prename s/fennec/icecatmobile/
find -type f | grep fennec | xargs prename s/fennec/icecatmobile/
find -type f | grep Fennec | xargs prename s/Fennec/IceCatMobile/
find -type d | grep firefox | xargs prename -f s/firefox/icecat/
find -type f | grep firefox | xargs prename -f s/firefox/icecat/
find -type f | grep Firefox | xargs prename -f s/Firefox/IceCat/

echo "Running batch rebranding"
SEDSCRIPT="
s|marketplace.firefox.com|f-droid.org/repository/browse|g;
s/org.mozilla.firefox/org.gnu.icecat/g;
s/Adobe Flash/Flash/g;
s|addons.mozilla.org.*/mobile|directory.fsf.org/wiki/GNU_IceCat|g;
s|addons.mozilla.org.*/android|directory.fsf.org/wiki/GNU_IceCat|g;
s|support.mozilla.org.*/mobile|libreplanet.org/wiki/Group:IceCat/icecat-help|g;
s|fhr.cdn.mozilla.net.*mobile|127.0.0.1|g;
s/run-mozilla.sh/run-icecat.sh/g;
s/Firefox Marketplace/F-droid free software repository/g;
s|mozilla.com/plugincheck|$ADDONSURL|g;
s|www.mozilla.com/firefox/central|$INFOURL|g;
s|www.mozilla.*/legal/privacy.*html|$LEGALINFOURL|g;
s|www.mozilla.*/legal/privacy|$LEGALINFOURL|g;

s/Mozilla Firefox/GNU IceCat/g;
s/firefox/icecat/g;
s/fennec/icecatmobile/g;
s/Firefox/IceCat/g;
s/Fennec/IceCatMobile/g;
s/FIREFOX/ICECAT/g;
s/FENNEC/ICECATMOBILE/g;
s/ Mozilla / GNU /g;

s|PACKAGES/icecat|PACKAGES/firefox|g;
s/GNU Public/Mozilla Public/g;
s/GNU Foundation/Mozilla Foundation/g;
s/GNU Corporation/Mozilla Corporation/g;
s/icecat.com/firefox.com/g;
s/IceCat-Spdy/Firefox-Spdy/g;
s/icecat-accounts/firefox-accounts/g;
s/IceCatAccountsCommand/FirefoxAccountsCommand/g;
s|https://www.mozilla.org/icecat/?utm_source=synceol|https://www.mozilla.org/firefox/?utm_source=synceol|g;

s|www.gnu.org/software/gnuzilla/icecat-help|libreplanet.org/wiki/Group:IceCat/Help|g;
"
find . -type f -not -iregex '.*changelog.*' -not -iregex '.*copyright.*' -execdir /bin/sed --follow-symlinks -i "$SEDSCRIPT" '{}' ';'

SEDSCRIPT="
s/free and open source software/Free Software/g;
s/free and open source/Free Software/g;
s/Open Source/Free Software/g;
s/open source/Free Software/g;
s/opensourcesoftware/Free Software/g;
s/opensource/Free Software/g;
s/OpenSource/Free Software/g;
"

for extension in dtd inc properties; do
    find . -type f -name "*$extension" -execdir /bin/sed --follow-symlinks -i "$SEDSCRIPT" '{}' ';'
done

sed 's/which are both/which are/; s/free<\/a> and/Free Software<\/a>./; />open source</d; s/free and open source licenses/Free Software licenses/ ' -i toolkit/content/license.html

sed s/GNU/Mozilla/ python/compare-locales/scripts/compare-locales -i
sed s/GNU/Mozilla/ python/compare-locales/setup.py -i
sed 's/mozilla-bin/icecat-bin/' -i build/unix/run-mozilla.sh

find -type f | grep run-mozilla | xargs prename s/mozilla/icecat/

sed "/MOZILLA_UAVERSION/ s:IceCat/:Firefox/:" -i netwerk/protocol/http/nsHttpHandler.cpp

find . -name region.properties |xargs -i /bin/sed 's_https://www.mibbit.*__' -i {}

# Set migrator scripts
cp browser/components/migration/IceCatProfileMigrator.js browser/components/migration/FirefoxProfileMigrator.js
sed 's/IceCat/Firefox/g; s/icecat/firefox/g' -i browser/components/migration/FirefoxProfileMigrator.js

# Copy js settings
cat $DATA/settings.js >> browser/app/profile/icecat.js

cat << EOF >> browser/confvars.sh
# IceCat settings
MOZ_APP_VENDOR=GNU
MOZ_APP_VERSION=$FFVERSION
MOZ_APP_PROFILE=mozilla/icecat
MOZ_PAY=0
MOZ_SERVICES_HEALTHREPORT=0
MOZ_SERVICES_HEALTHREPORTER=0
MOZ_SERVICES_FXACCOUNTS=0
MOZ_SERVICES_METRICS=0
MOZ_DATA_REPORTING=0
MOZ_SERVICES_SYNC=0
MOZ_DEVICES=0
MOZ_ANDROID_GOOGLE_PLAY_SERVICES=0
EOF

sed 's/mozilla-esr/gnu-esr/' -i browser/confvars.sh

###############################################################################
# Icons
###############################################################################

favicon=$DATA/branding/icecat/icecat.ico
jpglogo=$DATA/../artwork/icecat.jpg

#Firefox logo
ff256=$DATA/branding/icecat/default256.png
ff128=$DATA/branding/icecat/mozicon128.png
ff64=$DATA/branding/icecat/content/icon64.png
ff48=$DATA/branding/icecat/default48.png
ff32=$DATA/branding/icecat/default32.png
ff24=$DATA/branding/icecat/default24.png
ff22=$DATA/branding/icecat/default22.png
ff16=$DATA/branding/icecat/default16.png

#Grey flat logo
gf300=$DATA/android-images/resources/drawable-xhdpi/icon_home_empty_icecat.png
gf225=$DATA/android-images/resources/drawable-hdpi/icon_home_empty_icecat.png
gf150=$DATA/android-images/resources/drawable-mdpi/icon_home_empty_icecat.png
gf32=$DATA/android-images/resources/drawable-xhdpi/ic_status_logo.png
gf24=$DATA/android-images/resources/drawable-hdpi/ic_status_logo.png
gf16=$DATA/android-images/resources/drawable-mdpi/ic_status_logo.png
# White flat
wf24=$DATA/android-images/resources/drawable-mdpi-v11/ic_status_logo.png
wf48=$DATA/android-images/resources/drawable-xhdpi-v11/ic_status_logo.png
wf36=$DATA/android-images/resources/drawable-hdpi-v11/ic_status_logo.png

#Market logo
ma50=$DATA/android-images/core/marketplace-logo.png
ma128=$DATA/android-images/resources/drawable-mdpi/marketplace.png

cp $ff256 browser/components/loop/content/shared/img/icecat-logo.png
cp $ff64 browser/devtools/framework/dev-edition-promo/dev-edition-logo.png
cp $ma128 mobile/android/base/resources/raw/bookmarkdefaults_favicon_marketplace.png
cp $ff128 mobile/android/base/resources/raw/bookmarkdefaults_favicon_support.png
cp $favicon addon-sdk/source/examples/toolbar-api/data/favicon.ico
cp $gf32 browser/themes/shared/icon.png
cp $gf150 mobile/android/base/resources/drawable-hdpi/icon_search_empty_icecat.png
cp $gf150 mobile/android/base/resources/drawable-mdpi/icon_search_empty_icecat.png
cp $gf150 mobile/android/base/resources/drawable-xhdpi/icon_search_empty_icecat.png
cp $gf150 mobile/android/base/resources/drawable-xxhdpi/icon_search_empty_icecat.png
cp $gf32 browser/themes/linux/theme-switcher-icon.png
cp $gf32 browser/themes/osx/theme-switcher-icon.png
cp $gf32 browser/themes/windows/theme-switcher-icon.png
cp $gf32 browser/themes/osx/theme-switcher-icon@2x.png
cp $gf32 browser/themes/windows/theme-switcher-icon-aero.png
cp $gf32 browser/base/content/aboutaccounts/images/fox.png
cp $ff256 browser/components/loop/standalone/content/legal/images/icecat.png
cp $ff256 browser/components/loop/content/shared/img/icecat-logo.png

cp $ff16 dom/canvas/test/crossorigin/image.png
cp $ff16 image/test/unit/image1.png
cp $jpglogo  image/test/unit/image1png16x16.jpg
cp $jpglogo  image/test/unit/image1png64x64.jpg
cp $ff16 image/test/unit/image2jpg16x16.png
cp $ff16 image/test/unit/image2jpg16x16-win.png
cp $ff32 image/test/unit/image2jpg32x32.png
cp $ff32 image/test/unit/image2jpg32x32-win.png
cp $ff16 dom/canvas/test/crossorigin/image-allow-credentials.png
cp $ff16 dom/html/test/image-allow-credentials.png
cp $ff16 dom/canvas/test/crossorigin/image-allow-star.png
cp $ff32 toolkit/webapps/tests/data/icon.png
cp $ff16 toolkit/components/places/tests/favicons/expected-favicon-big32.jpg.png
cp $ff16 toolkit/components/places/tests/favicons/expected-favicon-big64.png.png
cp $jpglogo  toolkit/components/places/tests/favicons/favicon-big32.jpg
cp $ff64 toolkit/components/places/tests/favicons/favicon-big64.png
cp $favicon image/test/unit/image4gif16x16bmp24bpp.ico
cp $favicon image/test/unit/image4gif16x16bmp32bpp.ico
cp $favicon image/test/unit/image4gif32x32bmp24bpp.ico
cp $favicon image/test/unit/image4gif32x32bmp32bpp.ico
cp $jpglogo  mobile/android/base/tests/IceCat.jpg
cp $jpglogo image/test/unit/image1png16x16.jpg
cp $jpglogo image/test/unit/image2.jpg
cp $jpglogo image/test/unit/image2jpg16x16cropped.jpg
cp $jpglogo image/test/unit/image2jpg16x16cropped2.jpg
cp $jpglogo image/test/unit/image2jpg16x32cropped3.jpg
cp $jpglogo image/test/unit/image2jpg16x32scaled.jpg
cp $jpglogo image/test/unit/image2jpg32x16cropped4.jpg
cp $jpglogo image/test/unit/image2jpg32x16scaled.jpg
cp $jpglogo image/test/unit/image2jpg32x32.jpg
cp $ff32 image/test/unit/image2jpg32x32.png
cp $ff32 image/test/unit/image2jpg32x32-win.png

###############################################################################
# Mobile
###############################################################################

sed  '/MOZ_SERVICES_HEALTHREPORT/d; /MOZ_DEVICES/d; /MOZ_ANDROID_RESOURCE_CONSTRAINED/,+2d' -i mobile/android/confvars.sh

cat << EOF >> mobile/android/confvars.sh
# IceCat settings
MOZ_APP_VENDOR=GNU
MOZ_APP_VERSION=$FFVERSION
MOZ_PAY=0
MOZ_SERVICES_HEALTHREPORT=0
MOZ_SERVICES_HEALTHREPORTER=0
MOZ_SERVICES_FXACCOUNTS=0
MOZ_SERVICES_METRICS=0
MOZ_DATA_REPORTING=0
MOZ_SERVICES_SYNC=0
MOZ_DEVICES=0
MOZ_ANDROID_GOOGLE_PLAY_SERVICES=0
EOF

rm -R mobile/android/gradle/
sed -i '/gradle/d' mobile/android/base/Makefile.in

cat $DATA/settings.js >> mobile/android/app/mobile.js

cat << EOF > mobile/locales/en-US/chrome/region.properties
browser.search.defaultenginename=DuckDuckGo
browser.search.order.1=DuckDuckGo
browser.search.order.2=Google
browser.search.order.3=Yahoo
EOF

cp $DATA/preferences_vendor.xml mobile/android/base/resources/xml/preferences_vendor.xml

sed '/public static void checkAndNotifyPolicy/ s/{/{ if(true) return;/; /private static void notifyDataPolicy/ s/{/{ if(true) return;/ ' mobile/android/base/DataReportingNotification.java -i

cp -a $DATA/android-images/core/* mobile/android/themes/core/images/
cp -a $DATA/android-images/resources mobile/android/base

###############################################################################
# Macos packaging
###############################################################################

cat << EOF > ./build/package/mac_osx/pkg-dmg
#!/bin/sh
set -e
export LC_ALL=C

cd \$2
DMGFILE=\$4

# We need group readability for some Macs to be able to handle /Applications
# installation. Still unclear exactly why this is -- it is not dependent on
# OSX version...
find . -executable -exec chmod 750 {} \;
find . ! -executable -exec chmod 640 {} \;

find . -type f | sed -e 's/^\.\///' | sort | xargs -i echo "{}={}" > /tmp/filelist.txt
find . -type l | sed -e 's/^\.\///' | sort | xargs -i echo "{}={}" >> /tmp/filelist.txt

mkisofs -D -V "\$6" -no-pad -R -apple -o /tmp/icecat-uncompressed.dmg -path-list /tmp/filelist.txt -graft-points -gid 20 -dir-mode 0750 -new-dir-mode 0750


dmg dmg /tmp/icecat-uncompressed.dmg \$4
rm /tmp/icecat-uncompressed.dmg

find . -executable -exec chmod 755 {} \;
find . ! -executable -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
EOF

###############################################################################
# Extensions
###############################################################################

# Disable search field at extensions panel
#sed  '/header-search/d; /search.placeholder/d' -i toolkit/mozapps/extensions/content/extensions.xul
cat << EOF >> toolkit/mozapps/extensions/content/extensions.css
#header-search {
  display:none;
}
EOF

# Add extensions to manifest
for EXTENSION in $(ls $DATA/extensions/); do
sed "/Browser Chrome Files/s%$%\n@BINPATH@/browser/extensions/$EXTENSION/*%" -i browser/installer/package-manifest.in mobile/android/installer/package-manifest.in
#echo "DIRS += ['$EXTENSION']" >> browser/app/profile/extensions/moz.build
#touch browser/app/profile/extensions/$EXTENSION/moz.build
done

cp $DATA/extensions/ extensions/gnu -a

cat << EOF >> browser/app/Makefile.in
libs::
	cp -a \$(topsrcdir)/extensions/gnu/* \$(FINAL_TARGET)/extensions/
	mkdir -p \$(DIST)/icecat/browser/extensions/ 
	cp -a \$(topsrcdir)/extensions/gnu/* \$(DIST)/icecat/browser/extensions/
EOF

cat << EOF >> mobile/android/app/Makefile.in
libs::
	mkdir -p \$(DIST)/bin/distribution
	cp -a \$(topsrcdir)/extensions/gnu/ \$(DIST)/bin/distribution/extensions
EOF

#sed '/^make-package-internal:/ s%$%\n\tcp $(topsrcdir)/extensions.gnu/* $(DIST)/icecat/browser/extensions -a%' -i toolkit/mozapps/installer/packager.mk
#sed '/972ce4c6/  s%$%\n/extensions.gnu/* @MOZ_ADDONDIR@/extensions%' -i debian/icecat.install.in

ABPDIR="extensions/gnu/spyblock@gnu.org"
ABPBRAND="SpyBlock"
SEDSCRIPT="
s/ABP/$ABPBRAND/g;
s/Adblock Plus/$ABPBRAND/g;
s/AdblockPlus/$ABPBRAND/g;
s/Adblock/$ABPBRAND/g;
s/Adblok/$ABPBRAND/g;
/This file is part of/ s_adblockplus.org_www.gnu.org/software/gnuzilla_;
/Copyright.*Eyeo GmbH/ s/\$/ (Adblock Plus) \\n * Copyright (C) $(date +%Y) $DEBFULLNAME <$DEBEMAIL>/;
"
find $ABPDIR  -type f -not -iregex '.*changelog.*' -not -iregex '.*copyright.*' -execdir /bin/sed --follow-symlinks -i "$SEDSCRIPT" '{}' ';'
sed '/\[Spy/s/SpyBlock/Adblock/g' -i $ABPDIR/lib/synchronizer.js

cp $DATA/adblock_artwork/48.png $ABPDIR/icon.png
cp $DATA/adblock_artwork/24.png $ABPDIR/chrome/skin/abp-status.png
cp $DATA/adblock_artwork/16.png $ABPDIR/chrome/skin/abp-status-16.png
cp $DATA/adblock_artwork/100.png $ABPDIR/chrome/skin/abp-icon-big.png
cp $DATA/adblock_artwork/32.png $ABPDIR/chrome/skin/abp-status-32.png
cp $DATA/adblock_artwork/64.png $ABPDIR/icon64.png

sed '/972ce4c6/d;' -i debian/icecat.install.in
echo "@MOZ_LIBDIR@/browser/extensions @MOZ_ADDONDIR@" >> debian/icecat.install.in

###############################################################################
# Deb generation specifics
###############################################################################
cat << EOF >> debian/abrowser.postinst.in

if [ "\$1" = "configure" ] || [ "\$1" = "abort-upgrade" ] ; then

[ -f /usr/bin/mozilla ] || ln -s /usr/bin/icecat /usr/bin/mozilla && true

for USER in \$(grep -v /bin/false /etc/passwd|grep :/home|cut -d: -f1)
do
    [ -d /home/\$USER/.mozilla/ ] || continue
    [ -d /home/\$USER/.mozilla/icecat ] && continue
    [ -d /home/\$USER/.mozilla/firefox ] && DIR=/home/\$USER/.mozilla/firefox
    [ -d /home/\$USER/.mozilla/abrowser ] && DIR=/home/\$USER/.mozilla/abrowser
    [ \$DIR ] || continue
    echo Copying \$DIR into /home/\$USER/.mozilla/icecat
    cp -a \$DIR /home/\$USER/.mozilla/icecat
done
fi
EOF

cat << EOF >> debian/icecat.preinst.in

EOF

cat << EOF >> debian/icecat.postrm.in

[ -L /usr/bin/mozilla ] && rm /usr/bin/mozilla -f || true
EOF

echo "This package generated from Mozilla Firefox by $DEBFULLNAME <$DEBEMAIL> on
$(date)
More info at http://www.gnu.org/software/gnuzilla/

===

$(cat debian/copyright)" > debian/copyright

# Remove icecat-globalmenu package
sed '/Package:.*globalmenu/,/^$/d' -i debian/control.in

# Don't recommend ubufox
sed 's/xul-ext-ubufox//' -i debian/control.in

# Provide iceweasel, firefox
sed 's/iceweasel,/iceweasel, firefox,/' -i debian/control.in

# Locale packages should provide firefox-locale-$LANG
sed "s/Provides.*/Provides: firefox-locale-@LANGCODE@, abrowser-locale-@LANGCODE@/" -i debian/control.langpacks

# icecat-dev should provide firefox-dev
sed '/Package: @MOZ_PKG_NAME@-dev/,/Description:/ s/Provides:/Provides:firefox-dev, /' debian/control.in -i

# icacat should provide and replace abrowser and firefox
sed '/Package: @MOZ_PKG_NAME@$/,/Description:/ s/Provides:/Provides:firefox, abrowser, /' debian/control.in -i
sed '/Package: @MOZ_PKG_NAME@$/,/Description:/ s/Replaces:/Replaces:firefox, abrowser, /' debian/control.in -i

sed '/Vcs-Bzr/d; s/from Mozilla/from GNU/' debian/control.in -i

sed "s_^Maintainer.*_Maintainer: $DEBFULLNAME <$DEBEMAIL>_g" -i debian/control.in
rm debian/control
debian/rules debian/control
touch -d "yesterday" debian/control
debian/rules debian/control

echo | dch -D stable -v "$ICECATVERSION"  "Converted into IceCat (http://www.gnu.org/software/gnuzilla/)"
sed "1s/firefox/icecat/" -i debian/changelog

touch configure js/src/configure

# Fix CVE-2009-4029
sed 's/777/755/;' -i toolkit/crashreporter/google-breakpad/Makefile.in
#(cd toolkit/crashreporter/google-breakpad; aclocal)
#(cd toolkit/crashreporter/google-breakpad; automake)

# Fix CVE-2012-3386
/bin/sed 's/chmod a+w/chmod u+w/' -i ./js/src/ctypes/libffi/Makefile.in ./toolkit/crashreporter/google-breakpad/Makefile.in ./toolkit/crashreporter/google-breakpad/src/third_party/glog/Makefile.in || true

./mach generate-addon-sdk-moz-build

cd ..
echo Packaging tarball
tar cfj icecat-$ICECATVERSION.tar.bz2 $SOURCEDIR