updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / sunbrand / sunbrand.sh
blob14bdb6404cdb05dfdb77c4a541c4552ebd27765c
1 #!/bin/sh
3 # sunbrand - a script to brand sunbird without recompilation
6 # This script replaces and changes (a few) files in an existing sunbird
7 # installation. Run it after a sunbird installation or upgrade, and restart
8 # sunbird. The program icon may not be (visibly) replaced until your desktop
9 # environment is restarted.
11 # To revert to the original brand, simply reinstall sunbird.
13 # Dependencies: curl, zip, unzip, imagemagick
16 #SUNBIRDDIR: Where sunbird's data files resides.
18 SUNBIRDDIR=/usr/lib/sunbird
19 SUNBIRDSTRING="Calendar"
20 SUNBIRDSTRINGPREFS="Calendar"
22 NEWICONSDIR="./sunbird-icons" # If empty, the script uses a temporary directory for the replacement icons.
23 # If you want to avoid downloading the icons every time you rebrand sunbird,
24 # point NEWICONSDIR to a suitable directory.
26 SOURCEBASE="http://mxr.mozilla.org/seamonkey/source" # The URL under which the "other-licenses" directory resides.
29 CHROMEDIR=$SUNBIRDDIR/chrome # Simply the sunbird chrome directory.
33 die() {
34 EXITCODE="${1:-9}"
35 MESSAGE="$2"
37 echo -e "\n$MESSAGE"
39 exit $EXITCODE
44 get_icon() {
45 local ICON="$1"
46 local SOURCEFILE="$2"
48 echo -n " - $ICON"
50 if [ -e "$NEWICONSDIR/$ICON" ] ; then
51 if [ -f "$NEWICONSDIR/$ICON" ] ; then
52 echo " is present."
53 return 0
54 else
55 echo " is present but is not a file. Quitting."
56 exit 1
60 echo -n ": Downloading... "
61 if curl -sS "${SOURCEBASE}${SOURCEFILE}" > "$NEWICONSDIR/$ICON" ; then
62 echo "Done."
63 return 0
64 else
65 exit 1
71 TEMPDIR=$(mktemp -d -t sunbrand-work-XXXXXXXX)
73 if [ $? -ne 0 ] ; then
74 die 1 "Could not create temporary work directory."
77 if [ "x$NEWICONSDIR" == "x" ] ; then
78 NEWICONSDIR=$(mktemp -d -t sunbrand-icon-XXXXXXXX)
80 if [ $? -ne 0 ] ; then
81 die 1 "Could not create temporary icon directory."
83 else
84 [ -e "$NEWICONSDIR" ] || mkdir -p "$NEWICONSDIR" || die 1 "Could not create icon directory $NEWICONSDIR."
89 echo -e "\033[1mChecking replacement icons\033[0m"
90 get_icon "mozicon50.xpm" "/other-licenses/branding/sunbird/mozicon50.xpm?raw=1"
91 get_icon "mozicon16.xpm" "/other-licenses/branding/sunbird/mozicon16.xpm?raw=1"
92 get_icon "mozicon128.png" "/other-licenses/branding/sunbird/mozicon128.png?raw=1"
93 #get_icon "default.xpm" "/other-licenses/branding/sunbird/default.xpm?raw=1"
94 get_icon "icon48.png" "/other-licenses/branding/sunbird/content/icon48.png?raw=1"
95 get_icon "icon64.png" "/other-licenses/branding/sunbird/content/icon64.png?raw=1"
96 get_icon "about.png" "/other-licenses/branding/sunbird/content/about.png?raw=1"
97 get_icon "aboutCredits.png" "/other-licenses/branding/sunbird/content/aboutCredits.png?raw=1"
98 get_icon "aboutFooter.png" "/other-licenses/branding/sunbird/content/aboutFooter.png?raw=1"
100 cp "$NEWICONSDIR/mozicon50.xpm" "$NEWICONSDIR/default.xpm"
101 convert -resize 48x48 "$NEWICONSDIR/mozicon50.xpm" "$NEWICONSDIR/default48.png"
102 convert -resize 48x48 "$NEWICONSDIR/default.xpm" "$NEWICONSDIR/default.xpm"
103 convert -resize 32x32 "$NEWICONSDIR/mozicon50.xpm" "$NEWICONSDIR/default32.png"
104 convert -resize 16x16 "$NEWICONSDIR/mozicon50.xpm" "$NEWICONSDIR/default16.png"
108 echo -e "\033[1mBranding chrome/en-US.jar\033[0m"
109 echo -n " - Unzipping branding files in chrome/en-US.jar to temporary directory... "
110 unzip -q -d "$TEMPDIR" "$CHROMEDIR/en-US.jar" locale/branding/brand.dtd locale/branding/brand.properties && echo "Done." || die 1 "Failed."
112 for FILE in $TEMPDIR/locale/branding/* ; do
113 sed -i "s|$SUNBIRDSTRING|Sunbird|g" "$FILE" && echo " - Successfully edited ${FILE}" || die 1 "Could not edit ${FILE}."
114 done
116 echo -n " - Replacing old branding files in chrome/en-US.jar... "
117 ( cd $TEMPDIR && zip -q -r "$CHROMEDIR/en-US.jar" locale/branding/* ) && echo "Done." || die 1 "Failed."
121 echo -e "\033[1mBranding chrome/calendar.jar\033[0m"
122 echo -n " - Making new branding icon structure in temporary directory... "
123 mkdir -p "$TEMPDIR/content/branding" || die 1 "Could not create $TEMPDIR/content/branding."
124 cp "$NEWICONSDIR"/{about.png,aboutCredits.png,aboutFooter.png,icon48.png,icon64.png} "$TEMPDIR/content/branding/" || die 1 "Could not copy new icons to $TEMPDIR/content/branding/."
125 echo "Done."
126 echo -n " - Replacing old branding icon structure in chrome/calendar.jar... "
127 ( cd $TEMPDIR && zip -q -r "$CHROMEDIR/calendar.jar" content/branding/* ) && echo "Done." || die 1 "Failed."
131 echo -e "\033[1mBranding defaults/preferences/sunbird.js\033[0m"
132 sed -i "s|$SUNBIRDSTRINGPREFS|Sunbird|g" $SUNBIRDDIR/defaults/pref/sunbird.js && echo " - Successfully edited $SUNBIRDDIR/defaults/pref/sunbird.js." || die 1 "Could not edit $SUNBIRDDIR/defaults/pref/sunbird.js."
136 echo -e "\033[1mBranding icons\033[0m"
137 echo -n " - Replacing icons in chrome/icons/default/... "
138 cp "$NEWICONSDIR"/{default48.png,default32.png,default16.png,default.xpm} $SUNBIRDDIR/chrome/icons/default/ && echo "Done." || die 1 "Failed."
140 echo -n " - Replacing icons in icons/... "
141 #cp "$NEWICONSDIR"/{document.png,mozicon128.png,mozicon16.xpm,mozicon50.xpm} $SUNBIRDDIR/icons/ && echo "Done." || die 1 "Failed."
142 cp "$NEWICONSDIR"/{mozicon128.png,mozicon16.xpm,mozicon50.xpm} $SUNBIRDDIR/icons/ && echo "Done." || die 1 "Failed."
144 chmod 644 $SUNBIRDDIR/chrome/icons/default/* $SUNBIRDDIR/icons/*
145 chown root:root $SUNBIRDDIR/chrome/icons/default/* $SUNBIRDDIR/icons/*
147 echo -n " - Replacing /usr/share/pixmaps/sunbird.png: "
148 convert "$NEWICONSDIR/default.xpm" /usr/share/pixmaps/sunbird.png && echo "Done." || die 1 "Failed."
149 chmod 644 /usr/share/pixmaps/sunbird.png
150 chown root:root /usr/share/pixmaps/sunbird.png