Announcement

Collapse
No announcement yet.

Automated FireFox Extensions Install

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Semperfidelis
    replied
    Yeah
    Ive been keeping an eye on 0.9's development
    Could prove to be intresting

    Leave a comment:


  • Scott MacVicar
    replied
    Its not an install that you dont agree too but silent means it wont throw any error messages when something bad happens or ask you to click buttons to configure options.

    Leave a comment:


  • Surrix
    replied
    With the upcoming version 0.9 the are completely changing the xpi format and some other things I suggest you look at http://www.bengoodger.com/software/m...xtensions.html before coming any further with the project.

    Hope that helps.

    Leave a comment:


  • Semperfidelis
    started a topic Automated FireFox Extensions Install

    Automated FireFox Extensions Install

    Ive been playing around with creating my ultimate unattended install of XP

    And there is only one thing missing : firefox extensions

    Extensions are installed via XPI files
    Which in reality are just a zip file with a js install routine

    When you download an XPI, extract one of them out and you will be presented with something like :
    - install.js
    - {extensionname}.jar

    Seeing things like :

    Code:
    profileInstall: true,
    silentInstall: false,
    makes me think this is entirely possible to do a silent install of them all

    My silent install of Firefox drops it at : C:\Program Files\Mozilla Firefox

    What Im looking for is a way of packaging all those extensions into one silently installable package.
    I dont need all the prompt
    Or any of the sanity checks
    Install location can be hardcoded if need be

    Anyone ideas ?


    Below are some examples of install.js files to save you the download if your just curious

    They vary from XPI to XPI


    Code:
    initInstall("Autohide", "autohide", "0.8.9");
    var programInst=false
    
    if (File.exists(getFolder("chrome","autohide.jar")))
    {  programInst=true
    }
    else
    {  isInProfile=File.exists(getFolder(getFolder("Profile","chrome"),"autohide.jar"));
       if (!isInProfile && !File.exists(getFolder("chrome","browser.jar")))
          programInst=confirm("OK to install into program folder\n\nCancel to install into profile folder");
    }
    
    if (programInst)
    {  cFolder=getFolder("chrome");
       target=DELAYED_CHROME;
    }
    
    else
    {  cFolder=getFolder("Profile", "chrome");
       target=PROFILE_CHROME;
    }
    
    addFile("Autohide","autohide.jar",cFolder,"");
    registerChrome(CONTENT | target, getFolder(cFolder,"autohide.jar"), "content/");
    
    if (getLastError()==0)
       performInstall();
    else
       cancelInstall();

    Code:
    /* ***** BEGIN LICENSE BLOCK *****
     * Version: MPL 1.1/GPL 2.0/LGPL 2.1
     *
     * The contents of this file are subject to the Mozilla Public License Version
     * 1.1 (the "License"); you may not use this file except in compliance with
     * the License. You may obtain a copy of the License at
     * http://www.mozilla.org/MPL/
     *
     * Software distributed under the License is distributed on an "AS IS" basis,
     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
     * for the specific language governing rights and limitations under the
     * License.
     *
     * The Original Code is from autoform.
     *
     * The Initial Developer of the Original Code is
     * Michael Kessler, Bluewin AG <[email protected]>.
     * Portions created by the Initial Developer are Copyright (C) 2003
     * the Initial Developer. All Rights Reserved.
     *
     * AutoForm Contributor(s):
     * Michael Kessler, Bluewin AG <[email protected]>
     *
     * Alternatively, the contents of this file may be used under the terms of
     * either the GNU General Public License Version 2 or later (the "GPL"), or
     * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
     * in which case the provisions of the GPL or the LGPL are applicable instead
     * of those above. If you wish to allow use of your version of this file only
     * under the terms of either the GPL or the LGPL, and not to allow others to
     * use your version of this file under the terms of the MPL, indicate your
     * decision by deleting the provisions above and replace them with the notice
     * and other provisions required by the GPL or the LGPL. If you do not delete
     * the provisions above, a recipient may use your version of this file under
     * the terms of any one of the MPL, the GPL or the LGPL.
     *
     * ***** END LICENSE BLOCK ***** */
     
    // ============================================================
    // application settings
    // ============================================================
    
    var APP_NAME = "autoform";
    var APP_VERSION = "0.5";
    var APP_PACKAGE = "/mozdev/autoform";
    var APP_JARNAME = "autoform.jar";
    
    installAutoForm();
    
    // ============================================================
    // installation
    // ============================================================
    
    function installAutoForm() {
    	
       // ============================================================
       // installation location
       // ============================================================
       
       var location = PROFILE_CHROME;
       var installFolder = getFolder("Current User", "chrome");
       var existsInApplication = File.exists(getFolder(getFolder("Chrome"), APP_JARNAME));
       var existsInProfile = File.exists(getFolder(installFolder, APP_JARNAME));
       var msgLocationCheck = "Welcome to the autoform installation!\n\n\n" + "Hit [OK] to install into your personal folder\n" + "Hit [Cancel] to install globally (needs administrator privileges) !\n\n";
       
       // Initialise installation
       initInstall(APP_NAME, APP_PACKAGE, APP_VERSION);
       
       // If this is first install of AutoForm, ask where XPI should be installed
       if(existsInApplication ||(!existsInProfile && !confirm(msgLocationCheck))) {
          location = DELAYED_CHROME;
          installFolder = getFolder("Chrome");
       }
       
       setPackageFolder(installFolder);
       
       // ============================================================
       // install autoform.jar
       // ============================================================
       
       err = addFile(APP_PACKAGE, APP_VERSION, APP_JARNAME, installFolder, "");
       if(err != SUCCESS) {
          alert("Error adding autoform.jar:\n" + getErrorMsg(err));
          cancelInstall(err);
          return err;
       }
       var jarFolder = getFolder(installFolder, APP_JARNAME);
       
       // ============================================================
       // registering content
       // ============================================================
       
       err = registerChrome(CONTENT | location, jarFolder, "content/");
       if(err != SUCCESS) {
          alert("Error registering the content:\n" + getErrorMsg(err));
          cancelInstall(err);
          return err;
       }
       
       // ============================================================
       // registering locale en_US
       // ============================================================
       
       err = registerChrome(LOCALE | location, jarFolder, "locale/en_US/autoform/");
       if(err != SUCCESS) {
          alert("Error registering the locale en_US:\n" + getErrorMsg(err));
          cancelInstall(err);
          return err;
       }
       
       // ============================================================
       // registering locale de_CH
       // ============================================================
       
       err = registerChrome(LOCALE | location, jarFolder, "locale/de_CH/autoform/");
       if(err != SUCCESS) {
          alert("Error registering the locale de_CH:\n" + getErrorMsg(err));
          cancelInstall(err);
          return err;
       }
       
       // ============================================================
       // registering skin
       // ============================================================
       
       err = registerChrome(SKIN | location, jarFolder, "skin/classic/autoform/");
       if(err != SUCCESS) {
          alert("Error registering the skin:\n" + getErrorMsg(err));
          cancelInstall(err);
          return err;
       }
       
       // ============================================================
       // perform install
       // ============================================================
       
       var err = performInstall();
       if(err != SUCCESS && err != 999) {
          cancelInstall(err);
          alert("Performing the installation failed:\n" + getErrorMsg(err));
          return err;
       }
       
       // ============================================================
       // successful Installation
       // ============================================================
       
       refreshPlugins();
       return SUCCESS;
    }
    
    // ============================================================
    // error messages
    // ============================================================
    
    function getErrorMsg(err) {
       switch(err) {
          case 999:
             return "The files were installed, but one or more components were in use.\nRestart the computer and Communicator to complete the installation process.\nOn Windows NT, you may only need to restart Communicator as long as you did not replace operating system files.";
             break;
          case -100:
             return "The Software Installation setting in your browser is disabled.\nYou need to (re)enable this setting in the Advanched pref panel section of preferences before you can use XPInstall.";
             break;
          case -101:
             return "Your browser software can not be used to install our packages.\nSolution: install the mozilla browser from the Mozilla Foundation and restart the installation process.";
             break;
          case -102:
             return "JavaScript is currently disabled in your browser.\nSolution: Enable JavaScript and reload the installation page.";
             break;
          case -200:
             return "A problem occurred with the package name supplied to initInstall.";
             break;
          case -102:
             return "An unrecognized error occurred.";
             break;
          case -202:
             return "The user did not grant the required security privilege.\nSolution: login as root and restart the installation process.";
             break;
          case -203:
             return "Installation script was signed by more than one certificate.";
             break;
          case -204:
             return "Installation script was not signed.";
             break;
          case -205:
             return "Extracted file is not signed or the file (and, therefore, its certificate) could not be found.";
             break;
          case -206:
             return "Extracted file was not signed by the certificate used to sign the installation script.";
             break;
          case -207:
             return "XPI package cannot be read.";
             break;
          case -208:
             return "Bad parameters to a function.";
             break;
          case -209:
             return "Illegal relative path.";
             break;
          case -210:
             return "User clicked Cancel on Install dialog.";
             break;
          case -211:
             return "A problem occurred with the parameters to initInstall, or initInstall was not called first.";
             break;
          case -212:
             return "The silent installation privilege has not been granted.";
             break;
          case -213:
             return "The specified component is not present in the Client Version Registry.";
             break;
          case -214:
             return "The specified file cannot be deleted because it does not exist.";
             break;
          case -215:
             return "The specified file cannot be deleted because its permissions are set to read only.";
             break;
          case -216:
             return "The specified file cannot be deleted because it is a directory.";
             break;
          case -217:
             return "The specified file cannot be deleted because it is in use.";
             break;
          case -218:
             return "An error occurred when unpacking a file in AppleSingle format.";
             break;
          case -219:
             return "The path provided to getFolder was invalid.";
             break;
          case -220:
             return "An error occurred in GDIFF.";
             break;
          case -221:
             return "The checksum generated for the source file does not match the checksum in the XPI file.";
             break;
          case -222:
             return "The checksum of the patched file failed.";
             break;
          case -223:
             return "An error occurred while uninstalling a package.";
             break;
          case -224:
             return "Install folder not set in installation script";
             break;
          case -225:
             return "Extraction of XPI file failed.";
             break;
          case -226:
             return "Same filename being used in install.";
             break;
          case -227:
             return "Raised when installation is cancelled in medias res.";
             break;
          case -228:
             return "Problem with download.";
             break;
          case -229:
             return "Error in the script.";
             break;
          case -230:
             return "File already exists locally.";
             break;
          case -231:
             return "Expected targer directoy and got file.";
             break;
          case -232:
             return "Source file/dir not found.";
             break;
          case -233:
             return "Expected file and got directory.";
             break;
          case -234:
             return "Expected directory and got file.";
             break;
          case - 235:
             return "Not enough disk space for install.";
             break;
          case -299:
             return "Insufficient memory for operation.";
             break;
          case -236:
             return "Filename too long.";
             break;
          case -237:
             return "Unable to locate library function.";
             break;
          case -238:
             return "Unable to load library.";
             break;
          case -239:
             return "Chrome registration error. This can happend when the extension is already installed.";
             break;
          case -240:
             return "Malformed install.";
             break;
          default:
             return "This is an unknown error.";
       }
    }

    Code:
    // XpiInstaller
    // By Pike (Heavily inspired by code from Henrik Gemal and Stephen Clavering)
    
    var XpiInstaller = {
    
    	// --- Editable items begin ---
    	extFullName: 'Bookmark Backup', // The name displayed to the user (don't include the version)
    	extShortName: 'bookmarkbackup', // The leafname of the JAR file (without the .jar part)
    	extVersion: '0.3',
    	extAuthor: 'Pike',
    	extLocaleNames: ['en-US'], // e.g. ['en-US', 'en-GB']
    	extSkinNames: null, // e.g. ['classic', 'modern']
    	extPostInstallMessage: null, // Set to null for no post-install message
    	// --- Editable items end ---
    	
    	profileInstall: true,
    	silentInstall: false,
    	
    	install: function()
    	{
      var jarName = this.extShortName + '.jar';
      var profileDir = Install.getFolder('Profile', 'chrome');
      
      // Parse HTTP arguments
      this.parseArguments();
      
      // Check if extension is already installed in profile
      if (File.exists(Install.getFolder(profileDir, jarName)))
      {
      	if (!this.silentInstall)
      	{
        Install.alert('Updating existing Profile install of ' + this.extFullName + ' to version ' + this.extVersion + '.');
      	}
      	this.profileInstall = true;
      }
      else if (!this.silentInstall)
      {
      	// Ask user for install location, profile or browser dir?
      	this.profileInstall = Install.confirm('Install ' + this.extFullName + ' ' + this.extVersion + ' to your Profile directory (OK) or your Browser directory (Cancel)?');
      }
      
      // Init install
      var dispName = this.extFullName + ' ' + this.extVersion;
      var regName = '/' + this.extAuthor + '/' + this.extShortName;
      Install.initInstall(dispName, regName, this.extVersion);
      
      // Find directory to install into
      var installPath;
      if (this.profileInstall) installPath = profileDir;
      else installPath = Install.getFolder('chrome');
      
      // Add JAR file
      Install.addFile(null, 'chrome/' + jarName, installPath, null);
      
      // Register chrome
      var jarPath = Install.getFolder(installPath, jarName);
      var installType = this.profileInstall ? Install.PROFILE_CHROME : Install.DELAYED_CHROME;
      
      // Register content
      Install.registerChrome(Install.CONTENT | installType, jarPath, 'content/' + this.extShortName + '/');
      
      // Register locales
      for (var locale in this.extLocaleNames)
      {
      	var regPath = 'locale/' + this.extLocaleNames[locale] + '/' + this.extShortName + '/';
      	Install.registerChrome(Install.LOCALE | installType, jarPath, regPath);
      }
      
      // Register skins
      for (var skin in this.extSkinNames)
      {
      	var regPath = 'skin/' + this.extSkinNames[skin] + '/' + this.extShortName + '/';
      	Install.registerChrome(Install.SKIN | installType, jarPath, regPath);
      }
      
      // Perform install
      var err = Install.performInstall();
      if (err == Install.SUCCESS || err == Install.REBOOT_NEEDED)
      {
      	if (!this.silentInstall && this.extPostInstallMessage)
      	{
        Install.alert(this.extPostInstallMessage);
      	}
      }
      else
      {
      	this.handleError(err);
      	return;
      }
    	},
    	
    	parseArguments: function()
    	{
      // Can't use string handling in install, so use if statement instead
      var args = Install.arguments;
      if (args == 'p=0')
      {
      	this.profileInstall = false;
      	this.silentInstall = true;
      }
      else if (args == 'p=1')
      {
      	this.profileInstall = true;
      	this.silentInstall = true;
      }
    	},
    	
    	handleError: function(err)
    	{
      if (!this.silentInstall)
      {
      	Install.alert('Error: Could not install ' + this.extFullName + ' ' + this.extVersion + ' (Error code: ' + err + ')');
      }
      Install.cancelInstall(err);
    	}
    };
    
    XpiInstaller.install();

Related Topics

Collapse

Working...
X