updated on Wed Jan 11 00:07:16 UTC 2012
[aur-mirror.git] / firebrand / firebrand.sh
blobf1531d404d538d8cae1128b96517b05fe4585e29
1 #!/bin/bash
2 #README {{{
3 # firebrand - a script to brand firefox without recompilation
5 # This script replaces and changes (a few) files in an existing firefox
6 # installation. Run it after a firefox installation or upgrade, and restart
7 # firefox. The program icon may not be (visibly) replaced until your desktop
8 # environment is restarted.
10 # To revert to the original brand, simply reinstall firefox.
12 # Dependencies: wget, unzip, zip
14 # AUR...: https://aur.archlinux.org/packages.php?ID=34559
15 # FORUM.: https://bbs.archlinux.org/viewtopic.php?id=44320
16 #}}}
18 #config {{{
19 # Where firefox's data files resides. Usually something like
20 # /usr/lib/firefox-3.6. If empty, autodetection is attempted.
21 FXDIR=""
23 # If empty, the script uses a temporary directory for the replacement icons.
24 # If you want to avoid downloading the icons every time you rebrand firefox,
25 # point NEWICONSDIR to a suitable directory.
26 NEWICONSDIR=""
28 # The URL under which the "other-licenses" directory resides.
29 SOURCEBASE="http://mxr.mozilla.org/mozilla1.9.1/source"
30 #}}}
32 #function die {{{
33 die() {
34 local EXITCODE="${1:-9}"
35 local MESSAGE="$2"
37 [ "x$MESSAGE" == "x" ] || echo -e "$MESSAGE"
38 exit $EXITCODE
40 #}}}
42 #function: get_icon {{{
43 get_icon() {
44 local ICON="$1"
45 local SOURCEFILE="$2"
47 echo -n " - $ICON"
49 if [ -e "$NEWICONSDIR/$ICON" ]; then
50 if [ -f "$NEWICONSDIR/$ICON" ]; then
51 echo " is present."
52 return 0
53 else
54 die 1 " is present but is not a file. Quitting."
58 echo -n ": Downloading... "
60 if wget -q -O - "$SOURCEBASE$SOURCEFILE" > "$NEWICONSDIR/$ICON"; then
61 echo "Done."
62 return 0
63 else
64 die 1 "Failed."
67 #}}}
69 #requires {{{
70 if [ $EUID -ne 0 ]; then
71 die 1 "This script should be run as root."
74 for EXEC in wget unzip zip; do
75 if ! which $EXEC > /dev/null 2>&1; then
76 die 1 "This script requires $EXEC to work."
78 done
79 #}}}
81 #find_application_dir {{{
82 if [ "x$FXDIR" == "x" ]; then
83 FXDIR=$(ls -1d /usr/lib/firefox-* | sort | tail -1)
84 if [ "x$FXDIR" == "x" ] ; then
85 die 1 "Could not find the Firefox data directory."
87 echo "Firefox data directory is $FXDIR."
90 if [ ! -d "$FXDIR" ]; then
91 die 1 "$FXDIR is not a directory."
93 #}}}
95 #set_dirs {{{
96 CHROMEDIR=$FXDIR/chrome # Simply the firefox chrome directory.
98 BRAND_DTD="locale/branding/brand.dtd"
99 BRAND_PRO="locale/branding/brand.properties"
100 CBRAND="content/branding"
102 TEMPDIR=$(mktemp -d -t firebrand-work-XXXXXXXX)
103 if [ $? -ne 0 ]; then
104 die 1 "Could not create temporary work directory."
107 if [ "x$NEWICONSDIR" == "x" ] ; then
108 NEWICONSDIR=$(mktemp -d -t firebrand-icon-XXXXXXXX)
109 if [ $? -ne 0 ]; then
110 die 1 "Could not create temporary icon directory."
112 else
113 [ -e "$NEWICONSDIR" ] || mkdir -p "$NEWICONSDIR" || \
114 die 1 "Could not create icon directory $NEWICONSDIR."
116 #}}}
118 #get_icons {{{
119 echo -e "\033[1mChecking replacement icons\033[0m"
120 SOURCESUBBASE="/other-licenses/branding/firefox/"
121 get_icon "mozicon50.xpm" "${SOURCESUBBASE}/mozicon50.xpm?raw=1"
122 get_icon "mozicon16.xpm" "${SOURCESUBBASE}/mozicon16.xpm?raw=1"
123 get_icon "mozicon128.png" "${SOURCESUBBASE}/mozicon128.png?raw=1"
124 get_icon "document.png" "${SOURCESUBBASE}/document.png?raw=1"
125 get_icon "icon48.png" "${SOURCESUBBASE}/content/icon48.png?raw=1"
126 get_icon "icon64.png" "${SOURCESUBBASE}/content/icon64.png?raw=1"
127 get_icon "about.png" "${SOURCESUBBASE}/content/about.png?raw=1"
128 get_icon "aboutCredits.png" "${SOURCESUBBASE}/content/aboutCredits.png?raw=1"
129 get_icon "aboutFooter.png" "${SOURCESUBBASE}/content/aboutFooter.png?raw=1"
130 get_icon "default16.png" "${SOURCESUBBASE}/default16.png?raw=1"
131 get_icon "default22.png" "${SOURCESUBBASE}/default22.png?raw=1"
132 get_icon "default24.png" "${SOURCESUBBASE}/default24.png?raw=1"
133 get_icon "default32.png" "${SOURCESUBBASE}/default32.png?raw=1"
134 get_icon "default48.png" "${SOURCESUBBASE}/default48.png?raw=1"
135 get_icon "default256.png" "${SOURCESUBBASE}/default256.png?raw=1"
136 cp "$NEWICONSDIR/mozicon50.xpm" "$NEWICONSDIR/default.xpm"
137 #}}}
139 #branding {{{
140 echo -e "\033[1mBranding chrome/en-US.jar\033[0m"
141 echo -n " - Unzipping branding files in chrome/en-US.jar to temporary directory... "
142 unzip -q -d "$TEMPDIR" "$CHROMEDIR/en-US.jar" $BRAND_DTD $BRAND_PRO && \
143 echo "Done." || die 1 "Failed."
145 #brand.dtd
146 sed -r -i 's_(brandShortName[ \t]+)"[^"]+"_\1"Firefox"_g' \
147 $TEMPDIR/$BRAND_DTD && echo ' - Edited brand.dtd' || \
148 die 1 'Could not edit brand.dtd.'
150 sed -r -i 's_(brandFullName[ \t]+)"[^"]+"_\1"Mozilla Firefox"_g' $TEMPDIR/$BRAND_DTD
151 sed -r -i 's_(vendorShortName[ \t]+)"[^"]+"_\1"Mozilla"_g' $TEMPDIR/$BRAND_DTD
152 sed -r -i 's_(logoCopyright[ \t]+)"[^"]+"_\1"Firefox and the Firefox logos are trademarks of the Mozilla Foundation. All rights reserved."_g' $TEMPDIR/$BRAND_DTD
154 #brand.properties
155 sed -r -i 's_^(brandShortName)=.*$_\1=Firefox_g' \
156 $TEMPDIR/$BRAND_PRO && echo " - Edited brand.properties" || \
157 die 1 "Could not edit brand.properties."
159 sed -r -i 's_^(brandFullName)=.*$_\1=Mozilla Firefox_g' $TEMPDIR/$BRAND_PRO
160 sed -r -i 's_^(vendorShortName)=.*$_\1=Mozilla_g' $TEMPDIR/$BRAND_PRO
162 echo -n " - Replacing old branding files in chrome/en-US.jar... "
163 ( cd $TEMPDIR && zip -q -r "$CHROMEDIR/en-US.jar" locale/branding/* ) && \
164 echo "Done." || die 1 "Failed."
166 echo -e "\033[1mBranding chrome/browser.jar\033[0m"
167 echo -n " - Making new branding icon structure in temporary directory... "
168 mkdir -p "$TEMPDIR/$CBRAND" || die 1 "Could not create $TEMPDIR/$CBRAND."
169 cp "$NEWICONSDIR"/{about.png,aboutCredits.png,aboutFooter.png,icon48.png,icon64.png} \
170 "$TEMPDIR/$CBRAND/" || die 1 "Could not copy new icons to $TEMPDIR/$CBRAND/."
171 echo "Done."
173 echo -n " - Replacing old branding icon structure in chrome/browser.jar... "
174 ( cd $TEMPDIR && zip -q -r "$CHROMEDIR/browser.jar" $CBRAND/* ) && \
175 echo "Done." || die 1 "Failed."
177 echo -e "\033[1mBranding defaults/preferences/firefox.js\033[0m"
178 sed -r -i 's_^(pref\("general.useragent.extra.firefox", ")[^/]+(/.*"\);[ \t]*)$_\1Firefox\2_' \
179 $FXDIR/defaults/preferences/firefox.js && \
180 echo " - Successfully edited $FXDIR/defaults/preferences/firefox.js." || \
181 die 1 "Could not edit $FXDIR/defaults/preferences/firefox.js."
183 echo -e "\033[1mBranding icons\033[0m"
184 echo -n " - Replacing icons in chrome/icons/default/... "
185 cp "$NEWICONSDIR"/{default256.png,default48.png,default32.png,default24.png,default22.png,default16.png} \
186 $CHROMEDIR/icons/default/ && echo "Done." || die 1 "Failed."
188 echo -n " - Replacing icons in icons/... "
189 cp "$NEWICONSDIR"/{document.png,mozicon128.png,mozicon16.xpm,mozicon50.xpm} \
190 $FXDIR/icons/ && echo "Done." || die 1 "Failed."
192 chmod 644 $CHROMEDIR/icons/default/* $FXDIR/icons/*
193 chown root:root $CHROMEDIR/icons/default/* $FXDIR/icons/*
195 echo -n " - Replacing /usr/share/pixmaps/firefox.png: "
196 cp "$NEWICONSDIR/icon64.png" "/usr/share/pixmaps/firefox.png" && \
197 echo "Done." || die 1 "Failed."
199 chmod 644 /usr/share/pixmaps/firefox.png
200 chown root:root /usr/share/pixmaps/firefox.png
201 #}}}
202 # vim: ft=sh ts=2 sw=2 et fen: