require "rexml/document" require "fileutils" FIREFOX_PROFILES_LOCATION = "Library/Application Support/Firefox/Profiles/" TEMP_DIRECTORY = "comcast_temp_000123" FIREFOX_TOOLBAR_FILENAME = "XfinitydotcomToolbarMAC.xpi" abs_path_xpi_directory = File.dirname($0) # user may pass a commandline argument to override the default location # of the xpi if (ARGV[0] != nil) abs_path_xpi_directory = ARGV[0] end # add all our settings to this profile def add_settings_to_ff_profile(profile_name, abs_path_xpi_directory) clsid = nil Dir.chdir(abs_path_xpi_directory) do if (File.exist?TEMP_DIRECTORY) `rm -rf '#{TEMP_DIRECTORY}'` end Dir.mkdir(TEMP_DIRECTORY) `unzip '#{FIREFOX_TOOLBAR_FILENAME}' -d '#{TEMP_DIRECTORY}'` manifest = File.new(TEMP_DIRECTORY+"/manifest.xml") doc = REXML::Document.new manifest clsid = doc.get_elements("toolbar-manifest/dtx")[0].attributes["clsid"].to_s() manifest.close end Dir.chdir() do dirlocation = FIREFOX_PROFILES_LOCATION+profile_name+"/extensions/"+clsid if (!File.exist?(dirlocation) || Dir.entries(dirlocation).length < 3) if (File.exists?(dirlocation)) puts "exists, delete it" Dir.delete(dirlocation) end FileUtils.mkdir_p(dirlocation) puts "copy file: "+abs_path_xpi_directory+"/"+TEMP_DIRECTORY+"/." FileUtils.cp_r(abs_path_xpi_directory+"/"+TEMP_DIRECTORY+"/.", dirlocation) puts "toolbar installed" else puts "it seems the firefox toolbar is already installed" end end Dir.chdir(File.dirname($0)) do `rm -rf '#{TEMP_DIRECTORY}'` end end Dir.chdir() do puts "running script from "+File.expand_path($0) ff_profile_list = `ls '#{FIREFOX_PROFILES_LOCATION}'`.split("\n") ff_profile_list.each { |profile_folder| Dir.chdir() do ## This check is necessary because Firefox seems to throw random non-folders in the ## profile directory (when profiles have spaces in the names) if (File.directory?(FIREFOX_PROFILES_LOCATION+profile_folder)) puts "\n--------\nprofile folder: "+profile_folder+"\n--------" add_settings_to_ff_profile(profile_folder, abs_path_xpi_directory) else puts 'seems this profile is not a directory '+profile_folder end end } end