HowTo.Gumph.Org

Step by step solutions to IT problems

Customize the Firefox Installer

If you have to deploy Firefox to lots of machines, then it is often a good idea to build a custom setup for Firefox, with your own prefered bookmarks, homepage and default settings, rather than having to manually tweak each installation.

Thankfully, as Firefox uses scripts and text files for most of it setup, it can be customized without needing to compile anything. All you will need is a copy of the free compression program 7-Zip, a text editor and some header files from the mozilla site.

Getting the files you need

The firefox files are put together with the free compression tool 7-Zip available for linux and windows, so download and install that first.

Next up, grab these header files app.tag and 7zSD.sfx from the mozilla site. For brief official details of how to customize firefox read the mozilla page on Creating Localized Installers

The mozilla page says you need UPX as well, but because we are customizing Firefox for internal use, not public distribution I just skip that step, but you are welcome to follow the official instructions.

Finally you will need a good text editor to edit the config files. Unfortunately notepad will not do, as it doesn't handle unix format text files, something like editpad, textpad or jedit will be fine.

Extracting the files

In order to make the instructions easier to follow, I'm going to be using the commandline version of 7-Zip, which is installed as part of the windows version. In order to use 7-Zip from the command line, you will need to make sure that the 7-Zip program folder is in your path. So after starting a Command Prompt type

set path=%path%;c:\program files\7-Zip

Now extract the files from Firefox Setup 1.5.0.3.exe into a folder called firefox-1503

 7z x -ofirefox-1503 "Firefox Setup 1.5.0.3.exe"

In the newly created folder you should find a browser.xpi file and a localisation file called something like en-US.xpi or en-GB.xpi depending on what localised version of the Firefox setup you downloaded. I'm going to be using a en-GB localisation, so replace en-GB anywhere in the code with whatever localisation you are using.

Now extract the contents of those xpi files.

cd firefox-1503
7z x -obrowser browser.xpi
7z x -oen-GB en-GB.xpi

Automatic or Unattended Installs

If you don't want any user interaction with the Firefox install then edit line 8 of the config.ini file
Run Mode=Normal
Changing the value from Normal to either Auto or Silent

Changing the default bookmarks and settings

The default settings file and bookmarks are in the en-GB\bin\defaults\profile\ folder. Usually there is the bookmarks.html file but no prefs.js file. The best way to generate clean copies of these files, is to install Firefox onto a clean machine, then change the bookmarks and settings to what you want the defaults to be, and then copy the two files from the
"C:\Documents and Settings\username\Application Data\Mozilla\Firefox\Profiles\default.random" folder on the clean machine into the en-GB\bin\defaults\profile\ folder, overwriting the original bookmarks.html file.

If you have modified any of the toolbar positions from their defaults then you will also need to copy the localstore.rdf file also, however the localstore.rdf also contains the name of the last tab you used in the Options Dialog, so make sure you close the options dialog from the General tab, before copying the localstore.rdf file.

Removing the Desktop and Quicklaunch Icons for Normal Installs

If you don't want the Firefox icon to be installed on the Desktop, or Quicklaunch bar, or even in the Start Menu, then scroll down to line 281 of the config.ini file and change the default checkbox values from TRUE to FALSE
[Windows Integration-Item0]
CheckBoxState=TRUE
Description={WININT_DESKTOP}
Archive=

[Windows Integration-Item1] CheckBoxState=TRUE Description={WININT_START} Archive=

[Windows Integration-Item2] CheckBoxState=TRUE Description={WININT_QUICKL} Archive=

If you are installing to windows 98 machines then the icons are installed whether the checkboxes are ticked or not, so for windows 98 clients you'll need to use the method listed for silent and auto installs for removing the icons in windows 98 Normal installs.

Removing the Desktop and Quicklaunch Icons for Auto and Silent Installs

If you are installing in either Auto or Silent mode, changing the default checkbox values as detailed above won't actually make any difference, as they get ignored, and the Firefox icons are installed on the desktop, quicklaunch bar and startmenu whether you like it or not. So, we have to be a bit more brutal, and actually comment out the code that installs the icons.

You need to edit the file en-GB\install.js depending on which localisation you are using , the code could be on slightly different line numbers, but should be at about line 237 - 260.

To remove the desktop shortcut comment out lines 250-251 so that

 if (winreg.getValueNumber(subkey, "Create Desktop Shortcut") != 0)
  File.windowsShortcut(fileExe, fFolderDesktop, scExeDesc, fProgram, "", fileExe, 0);
becomes
 // if (winreg.getValueNumber(subkey, "Create Desktop Shortcut") != 0)
 //  File.windowsShortcut(fileExe, fFolderDesktop, scExeDesc, fProgram, "", fileExe, 0);

To remove the Start Menu shortcuts comment out lines 252 to 255 so that

 if (winreg.getValueNumber(subkey, "Create Start Menu Shortcut") != 0) {
File.windowsShortcut(fileExe, fFolderPrograms, scExeDesc, fProgram, "", fileExe, 0); File.windowsShortcut(fileExe, fFolderPrograms, scSafeModeDesc, fProgram, scSafeModeParam, fileExe, 0); }
becomes
 // if (winreg.getValueNumber(subkey, "Create Start Menu Shortcut") != 0) {
 //  File.windowsShortcut(fileExe, fFolderPrograms, scExeDesc, fProgram, "", fileExe, 0);
 //  File.windowsShortcut(fileExe, fFolderPrograms,  scSafeModeDesc, fProgram, scSafeModeParam,  fileExe, 0);
 // }

To remove the Quicklaunch shortcut, comment out lines 256 to 257 so that

 if (winreg.getValueNumber(subkey, "Create Quick Launch Shortcut") != 0 && folderQuickLaunchExists)
  File.windowsShortcut(fileExe, fFolderQuickLaunch, scExeDesc, fProgram,  "", fileExe, 0);
becomes
 // if (winreg.getValueNumber(subkey, "Create Quick Launch Shortcut") != 0 && folderQuickLaunchExists)
 //  File.windowsShortcut(fileExe, fFolderQuickLaunch, scExeDesc, fProgram,  "", fileExe, 0);

Removing the Random Quality Feedback Agent Installs

The Quality feedback agent is configured to be randomly selected for installation 20% of the time. To unselect it for installation all the time, change line 219 of the config.ini file, commenting out the QFA component so it reads
; C3=Component QFA

Overriding the "Whats Changed" page

The first time Firefox is run after it is installed or upgraded the default homepage is overridden with a "Whats Changed" page from the Mozilla Site. If you want to cancel this override, then you need to edit the firefox.js file found in browser\bin\defaults\pref\

Edit line 46 removing the override url location, so it looks like

pref("startup.homepage_override_url","");

Removing the initial Import Settings Dialog

When a user runs Firefox for the Firefox for the first time, they are prompted to import settings from Internet Explorer (or whatever other browser they have). If they do this, then their settings will override the default settings you set up earlier, so to disable this dialog we need to delve a little deeper.

I'm sure there is probably a better way of doing this, but we are going to have to edit the code for this window so it doesn't appear the first time Firefox is run. We need to edit the migration.js file inside the browser.jar file located in the browser\bin\chrome folder. So type in the following commands from the firefox folder.

cd browser\bin\chrome
7z x -obrowserjar browser.jar
Now edit the migration.js file in the browserjar\content\browser\migration folder, commenting out lines 34 and 35, and inserting 2 new lines after them.
      if (this._autoMigrate) {
        // Show the "nothing" option in the automigrate case to provide an
        // easily identifiable way to avoid migration and create a new profile.
        // var nothing = document.getElementById("nothing");
        // 	nothing.hidden = false;
	    document.documentElement.cancel();
        return;
      }
If you want to permanently disable the import window, even when a user clicks on import in the file menu, then move the two inserted lines to above the "if (this._autoMigrate) {" line.

Now rebuild the browser.jar file and delete the created folders so they don't exist when we rebuild the xpi file.

cd browserjar
7z u -r ..\browser.jar *
cd ..
rmdir /S /Q browserjar

Build the customized setup file

Now we have made all the customizations we want, it's time to build a new setup executable. Firstly we need to rebuild the xpi files (assuming you didn't just edit the config.ini file), so from the firefox folder type in the following commands
cd browser
7z u ..\browser.xpi *
cd ..
cd en-GB
7z u ..\en-GB.xpi *

We don't need to delete the browser and en-GB folders as the following commands are not recursive.

Next we need to create the new setup executable, so from the firefox folder type in the following commands

7z a -t7z ..\custom.7z *.* -mx -m0=BCJ2 -m1=LZMA:d24 -m2=LZMA:d19 -m3=LZMA:d19 -mb0:1 -mb0s1:2 -mb0s2:3
cd ..
copy /b 7zSD.sfx + app.tag + custom.7z FirefoxCustom.exe

And there you have it your own custom Firefox Setup. The page was last updated for Firefox 1.5.0.4 en-GB for windows. I've noticed that very little changes in the script files between versions, so this howto should be good for a while yet.

If you are going to be customizing Firefox every release, then most of the work can be scripted using diff and patch files. Once you have created a patch file using diff you can use this patch script to automatically generate your patched setup exe. Whilst the commands and script are designed for a windows environment, they could be very easily converted to run on any other platform.

Submit to     del.icio.us    digg    reddit    simpy