Skip to content

opsi.orgheader image

opsi.org
Views

firefox

Document Actions
last edited 3 months ago by doertel
Three scripts: install (firefox.ins) and uninstall (delsub.ins; delfirefox.ins)

Qualified for opsi 3.4
---------------------------------------------------------------------
firefox.ins

******************************************************************
; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.

[Initial]
LogLevel=2
;  Log Errors in Logfile but don't abort:
ExitOnError=false
; Show syntax errors in the script:
ScriptErrorMessages=on
; Dont trace step by step through the script:
TraceMode=off
; let started programs run in front of the winst window
StayOnTop=false

[Aktionen]
DefVar $ProductId$
DefVar $InstallDir$
DefVar $NewExe$
DefVar $PRODUCTPATH$
DefStringList $profiles$
DefVar $akt_profile_ini$
DefVar $rel_prefs_path$
DefVar $akt_prefs_path$
DefVar $TEMP$
DefVar $OS$
DefVar $UninstallCommand$
DefVar $MozInstallDir$
DefVar $MozVersion$
DefVar $MozInstallPathRegKey$
DefVar $PROXY_HOSTNAME_OR_IP$
DefVar $PROXY_PORT$
DefVar $NOPROXY_HOSTS$
DefVar $PREF_FILE$
DefStringList $languageInfo$
DefVar $language$
DefVar $AppData$
DefVar $SilentSwitch$
DefVar $ExitCode$

Set $TEMP$ = EnvVar("TEMP")
Set $PRODUCTPATH$="%ProgramFilesDir%\Mozilla Firefox"
set $InstallDir$=$PRODUCTPATH$
set $NewExe$= $PRODUCTPATH$+"\firefox.exe"
set $ProductId$ = "firefox"
set $OS$ = GetNTVersion

if not(HasMinimumSpace ("%SYSTEMDRIVE%", "100 MB"))
	LogError "Nicht gengend Platz auf C: . 100 MB auf C: fuer Firefox erforderlich."
	isFatalError
	comment "Bearbeitung beenden und Produktschalter auf failed setzen"
else
	comment "show product picture"
	ShowBitmap /3 "%scriptpath%\firefox.png" "Firefox"

	comment "what is the name of the Application Data Dir ?"
	set $AppData$ = "\Anwendungsdaten"
	DefVar $InterestingFile$
	set $InterestingFile$ = "%system%\kernel32.dll"
	DefStringList $FileInfo$
	set $FileInfo$ = getFileInfoMap($InterestingFile$)
	set $language$ = getValue("language name 0", $FileInfo$ )

	if $language$ = "Deutsch (Deutschland)"
		set $AppData$ = "\Anwendungsdaten"
	else
		if $language$ = "English (United States)"
			set $AppData$ = "\Application Data"
		else
			comment "Name of Application Data Dir here not defined for "+$language$
		endif
	endif

	if GetNTVersion = "Windows Vista"
		set $AppData$ = "\AppData\Roaming"
	endif

	set $MozVersion$ = GetRegistryStringValue ("[HKEY_LOCAL_MACHINE\Software\Mozilla\Mozilla Firefox] CurrentVersion")
	set $MozInstallPathRegKey$ = "[HKEY_LOCAL_MACHINE\Software\Mozilla\Mozilla Firefox\"+$MozVersion$+"\Main]"
	set $MozInstallDir$ = GetRegistryStringValue ($MozInstallPathRegKey$+" Install Directory")

	if FileExists("%ScriptPath%\delsub.ins")
		comment "start uninstall"
		sub "%ScriptPath%\delsub.ins"
	endif

	comment "Message at install time:"
	Message=Installing Firefox...
	comment "kill a running firefox"
	killtask "firefox.exe"

	comment "check for depotshare"
	if not (FileExists("%SCRIPTPATH%"))
		DosInAnIcon_TryToReconnect
	endif
	comment "start setup program"

	DefVar $FIREFOXVER$
 
	if (IniVar ("firefox3-version") = "3.0.x")
		set $FIREFOXVER$ = "Firefox Setup 3.0.19.exe"
		set $SilentSwitch$ = "/S"
	else 
		if (IniVar ("firefox3-version") = "3.5.x")
			set $FIREFOXVER$ = "Firefox Setup 3.5.9.exe"
			set $SilentSwitch$ = "-ms"
		else
	
			if (IniVar ("firefox3-version") = "3.6.x")
				set $FIREFOXVER$ = "Firefox Setup 3.6.3.exe"
				set $SilentSwitch$ = "-ms"
			else
				logError "Unhandled firefox version: " + IniVar("firefox3-version")
				isFatalError
      			endif
		endif
	endif

	Files_copy_local
	Winbatch_firefox
	sub_check_exitcode

;	set $MozVersion$ = GetRegistryStringValue ("[HKEY_LOCAL_MACHINE\Software\Mozilla\Mozilla Firefox] CurrentVersion")
;	comment "if failed - try again"
;	if ($MozVersion$="")
;		Winbatch_firefox
;	endif
;	set $MozVersion$ = GetRegistryStringValue ("[HKEY_LOCAL_MACHINE\Software\Mozilla\Mozilla Firefox] CurrentVersion")

	comment "kill a running firefox"
	killtask "firefox.exe"

	if not(FileExists($NewExe$))
		logError "Fatal: After Installation "+$NewExe$+" not found"
		isFatalError
	endif

	comment "del temporary files"
	Files_del

	comment "now we do the customizing"
	comment "should we patch user.js or prefs.js ?"
	set $PREF_FILE$ = IniVar("pref_file")
	set $PREF_FILE$ = $PREF_FILE$+".js"

	if (IniVar("NoAutoUpdate") = "on") or ((IniVar("SetProxy") = "off") or not(IniVar("SetProxy") = ""))
		comment "there is something to customize"
		comment "now we patch the default profiles"
		if (IniVar("NoAutoUpdate") = "on")
			PatchTextFile_profile_noautoupdate $PRODUCTPATH$+"\defaults\profile\"+$PREF_FILE$
		endif
		if not(((IniVar("SetProxy") = "off") or (IniVar("SetProxy") = "")))
			set $NOPROXY_HOSTS$ = IniVar("noproxy_hosts")
			if (IniVar("SetProxy") = "direct")
				PatchTextFile_profile_proxy_direct $PRODUCTPATH$+"\defaults\profile\"+$PREF_FILE$
			endif
			if (IniVar("SetProxy") = "manual")
				set $PROXY_HOSTNAME_OR_IP$ = IniVar("Proxysetting")
				set $PROXY_PORT$           = takeString(1,splitString($PROXY_HOSTNAME_OR_IP$,":"))
				set $PROXY_HOSTNAME_OR_IP$ = takeString(0,splitString($PROXY_HOSTNAME_OR_IP$,":"))
				PatchTextFile_profile_proxy_manual $PRODUCTPATH$+"\defaults\profile\"+$PREF_FILE$
			endif
			if (IniVar("SetProxy") = "file")
				set $PROXY_HOSTNAME_OR_IP$ = IniVar("Proxysetting")
				PatchTextFile_profile_proxy_file $PRODUCTPATH$+"\defaults\profile\"+$PREF_FILE$
			endif
			if (IniVar("SetProxy") = "automatic")
				PatchTextFile_profile_proxy_automatic $PRODUCTPATH$+"\defaults\profile\"+$PREF_FILE$
			endif
		endif
		comment "now we patch the existing user profiles"
		comment "get user directories via dosbatch dir command"
		Set $profiles$ = getOutStreamFromSection ('dosbatch_profiledir')
		comment "loop over the result"
		for $x$ in $profiles$ do sub_patch_prefs_file
	else
		comment "there is nothing to customize"
	endif

	comment "custom specific stuff"
	if FileExists("%ScriptPath%\custom_ins_dir\custom.ins")
		sub "%ScriptPath%\custom_ins_dir\custom.ins"
	endif
endif

[Files_copy_local]
copy -x "%SCRIPTPATH%\$FIREFOXVER$" c:\tmp

[Files_del]
delete -f "c:\tmp\$FIREFOXVER$"

[Winbatch_firefox]
; see http://wiki.mozilla.org/Installer:Command_Line_Arguments
"c:\tmp\$FIREFOXVER$" $SilentSwitch$

[dosbatch_profiledir]
@echo off
dir "%ProfileDir%" /b

[sub_patch_prefs_file]
Set $akt_profile_ini$ = "%ProfileDir%\"+"$x$"+$AppData$+"\Mozilla\Firefox\profiles.ini"
if FileExists($akt_profile_ini$)
	Set $rel_prefs_path$ = GetIni ($akt_profile_ini$ [Profile0] Path)
	Set $akt_prefs_path$ = "%ProfileDir%\"+"$x$"+$AppData$+"\Mozilla\Firefox\"+$rel_prefs_path$
	if FileExists($akt_prefs_path$+"\"+$PREF_FILE$)
		if (IniVar("NoAutoUpdate") = "on")
			PatchTextFile_profile_noautoupdate $akt_prefs_path$+"\"+$PREF_FILE$
		endif
		if not(((IniVar("SetProxy") = "off") or (IniVar("SetProxy") = "")))
			if (IniVar("SetProxy") = "direct")
				PatchTextFile_profile_proxy_direct $akt_prefs_path$+"\"+$PREF_FILE$
			endif
			if (IniVar("SetProxy") = "manual")
				set $PROXY_HOSTNAME_OR_IP$ = IniVar("Proxysetting")
				set $PROXY_PORT$           = takeString(1,splitString($PROXY_HOSTNAME_OR_IP$,":"))
				set $PROXY_HOSTNAME_OR_IP$ = takeString(0,splitString($PROXY_HOSTNAME_OR_IP$,":"))
				PatchTextFile_profile_proxy_manual $akt_prefs_path$+"\"+$PREF_FILE$
			endif
			if (IniVar("SetProxy") = "file")
				set $PROXY_HOSTNAME_OR_IP$ = IniVar("Proxysetting")
				PatchTextFile_profile_proxy_file $akt_prefs_path$+"\"+$PREF_FILE$
			endif
			if (IniVar("SetProxy") = "automatic")
				PatchTextFile_profile_proxy_automatic $akt_prefs_path$+"\"+$PREF_FILE$
			endif
		endif
	endif
endif

[PatchTextFile_profile_noautoupdate]
Set_Netscape_User_Pref ("app.update.enabled", false)

[DosInAnIcon_TryToReconnect]
net use
set TIMEOUT=
:TRY
if exist "%SCRIPTPATH%\." goto READY
%ScriptDrive%
set TIMEOUT=%TIMEOUT%1
if %TIMEOUT% == 1111111111111111 goto READY
sleep 1
net use
goto TRY
:READY

[PatchTextFile_profile_proxy_direct]
Set_Netscape_User_Pref ("network.proxy.type", 0)

[PatchTextFile_profile_proxy_automatic]
Set_Netscape_User_Pref ("network.proxy.type", 4)

[PatchTextFile_profile_proxy_manual]
Set_Netscape_User_Pref ("network.proxy.type", 1)
Set_Netscape_User_Pref ("network.proxy.backup.ftp", "$PROXY_HOSTNAME_OR_IP$")
Set_Netscape_User_Pref ("network.proxy.backup.ftp_port", $PROXY_PORT$)
Set_Netscape_User_Pref ("network.proxy.backup.gopher", "$PROXY_HOSTNAME_OR_IP$")
Set_Netscape_User_Pref ("network.proxy.backup.gopher_port", $PROXY_PORT$)
Set_Netscape_User_Pref ("network.proxy.backup.socks", "$PROXY_HOSTNAME_OR_IP$")
Set_Netscape_User_Pref ("network.proxy.backup.socks_port", $PROXY_PORT$)
Set_Netscape_User_Pref ("network.proxy.backup.ssl", "$PROXY_HOSTNAME_OR_IP$")
Set_Netscape_User_Pref ("network.proxy.backup.ssl_port", $PROXY_PORT$)
Set_Netscape_User_Pref ("network.proxy.ftp", "$PROXY_HOSTNAME_OR_IP$")
Set_Netscape_User_Pref ("network.proxy.ftp_port", $PROXY_PORT$)
Set_Netscape_User_Pref ("network.proxy.gopher", "$PROXY_HOSTNAME_OR_IP$")
Set_Netscape_User_Pref ("network.proxy.gopher_port", $PROXY_PORT$)
Set_Netscape_User_Pref ("network.proxy.socks", "$PROXY_HOSTNAME_OR_IP$")
Set_Netscape_User_Pref ("network.proxy.socks_port", $PROXY_PORT$)
Set_Netscape_User_Pref ("network.proxy.http", "$PROXY_HOSTNAME_OR_IP$")
Set_Netscape_User_Pref ("network.proxy.http_port", $PROXY_PORT$)
Set_Netscape_User_Pref ("network.proxy.no_proxies_on", "$NOPROXY_HOSTS$")
Set_Netscape_User_Pref ("network.proxy.share_proxy_settings", true)
Set_Netscape_User_Pref ("network.proxy.ssl", "$PROXY_HOSTNAME_OR_IP$")
Set_Netscape_User_Pref ("network.proxy.ssl_port", $PROXY_PORT$)

[PatchTextFile_profile_proxy_file]
Set_Netscape_User_Pref ("network.proxy.type", 2)
Set_Netscape_User_Pref ("network.proxy.autoconfig_url", "file:///$PROXY_HOSTNAME_OR_IP$")

[sub_check_exitcode]
comment "test for installation success via exit code"
set $ExitCode$ = getLastExitCode
; informations to exit codes see
; http://msdn.microsoft.com/en-us/library/aa372835(VS.85).aspx
; http://msdn.microsoft.com/en-us/library/aa368542.aspx
if ($ExitCode$ = "0")
	comment "looks good: setup program gives exitcode zero"
else
	comment "Setup program gives a exitcode unequal zero: "+$ExitCode$
	if ($ExitCode$ = "1605")
		comment "ERROR_UNKNOWN_PRODUCT	1605	This action is only valid for products that are currently installed."
		comment "Uninstall of a not installed product failed - no problem"
	else
		if ($ExitCode$ = "1641")
			comment "looks good: setup program gives exitcode 1641"
			comment "ERROR_SUCCESS_REBOOT_INITIATED	1641	The installer has initiated a restart. This message is indicative of a success."
		else
			if ($ExitCode$ = "3010")
				comment "looks good: setup program gives exitcode 3010"
				comment "ERROR_SUCCESS_REBOOT_REQUIRED	3010	A restart is required to complete the install. This message is indicative of a success."
			else
				logError "Fatal: Setup program gives an unknown exitcode unequal zero: "+$ExitCode$
				isFatalError
			endif
		endif
	endif
endif



************************************************************

delsub.ins

************************************************************
; Message at install time:
Message "Deinstalling "+$ProductId$+" ..."

; kill a running firefox
killtask "firefox.exe"

; if firefox uninstall program exists then start it

if not ($MozVersion$="")
	; ab V 2.0.0.2
	if FileExists(""+$MozInstallDir$+"\uninstall\helper.exe")
		set $UninstallCommand$ = ""+$MozInstallDir$+"\uninstall\helper.exe"
		set $UninstallCommand$ = '"'+$UninstallCommand$+'" /S'
		WinBatch_start_FirefoxUninstall /WaitSeconds 20
		sub_check_exitcode
	endif
	; ab V 2.0
	if FileExists(""+$MozInstallDir$+"\uninstall\Uninst.exe")
		set $UninstallCommand$ = ""+$MozInstallDir$+"\uninstall\Uninst.exe"
		set $UninstallCommand$ = '"'+$UninstallCommand$+'" /S'
		WinBatch_start_FirefoxUninstall /WaitSeconds 20
		sub_check_exitcode
	endif
	; ab V 1.0.4
	if FileExists(""+$MozInstallDir$+"\uninstall\UninstallFirefox.exe")
		set $UninstallCommand$ = ""+$MozInstallDir$+"\uninstall\UninstallFirefox.exe"
		set $UninstallCommand$ = '"'+$UninstallCommand$+'" /ma'
		WinBatch_start_FirefoxUninstall /WaitSeconds 20
		sub_check_exitcode
	endif
	; bis V1.0.1
	if FileExists("%SYSTEMROOT%\UninstallFirefox.exe")
		set $UninstallCommand$ = "%SYSTEMROOT%\UninstallFirefox.exe"
		set $UninstallCommand$ = '"'+$UninstallCommand$+'" /ma'
		WinBatch_start_FirefoxUninstall
		sub_check_exitcode
	endif
	; delete registry entry to the current installed version
	Registry_delete_current_version
	; delete files of current version
	if not ($MozInstallDir$ = "")
		Files_copy_deinstall
	endif
endif


[WinBatch_start_FirefoxUninstall]
$UninstallCommand$
;%SCRIPTPATH%\sleep 5

[Files_copy_deinstall]
delete -sf "$MozInstallDir$\"

[Registry_delete_current_version]
OpenKey [HKEY_LOCAL_MACHINE\Software\Mozilla\Mozilla Firefox]
set "CurrentVersion" = ""

[sub_check_exitcode]
comment "test for installation success via exit code"
set $ExitCode$ = getLastExitCode
; informations to exit codes see
; http://msdn.microsoft.com/en-us/library/aa372835(VS.85).aspx
; http://msdn.microsoft.com/en-us/library/aa368542.aspx
if ($ExitCode$ = "0")
	comment "looks good: setup program gives exitcode zero"
else
	comment "Setup program gives a exitcode unequal zero: "+$ExitCode$
	if ($ExitCode$ = "1605")
		comment "ERROR_UNKNOWN_PRODUCT	1605	This action is only valid for products that are currently installed."
		comment "Uninstall of a not installed product failed - no problem"
	else
		if ($ExitCode$ = "1641")
			comment "looks good: setup program gives exitcode 1641"
			comment "ERROR_SUCCESS_REBOOT_INITIATED	1641	The installer has initiated a restart. This message is indicative of a success."
		else
			if ($ExitCode$ = "3010")
				comment "looks good: setup program gives exitcode 3010"
				comment "ERROR_SUCCESS_REBOOT_REQUIRED	3010	A restart is required to complete the install. This message is indicative of a success."
			else
				logError "Fatal: Setup program gives an unknown exitcode unequal zero: "+$ExitCode$
				isFatalError
			endif
		endif
	endif
endif



***********************************************************

delfirefox.ins

***********************************************************
; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.

[Initial]
LogLevel=2
;  Log Errors in Logfile but don't abort:
ExitOnError=false
; Show syntax errors in the script:
ScriptErrorMessages=on
; Dont trace step by step through the script:
TraceMode=off
; let started programs run in front of the winst window
StayOnTop=false

[Aktionen]
DefVar $ProductId$
DefVar $InstallDir$
DefVar $MozInstallDir$
DefVar $MozVersion$
DefVar $MozInstallPathRegKey$
DefVar $UninstallCommand$
DefVar $ExitCode$

; This should be edited
set $ProductId$ = "firefox"
set $InstallDir$="%ProgramFilesDir%\Mozilla Firefox"

set $MozVersion$ = GetRegistryStringValue ("[HKEY_LOCAL_MACHINE\Software\Mozilla\Mozilla Firefox] CurrentVersion")
set $MozInstallPathRegKey$ = "[HKEY_LOCAL_MACHINE\Software\Mozilla\Mozilla Firefox\"+$MozVersion$+"\Main]"
set $MozInstallDir$ = GetRegistryStringValue ($MozInstallPathRegKey$+" Install Directory")


DefVar $TEMP$
Set $TEMP$ = EnvVar("TEMP")
;Variables for OS version
	; show product picture
	ShowBitmap /3 "%scriptpath%\"+$ProductId$+".png" $ProductId$

if FileExists("%ScriptPath%\delsub.ins")
	;  start uninstall
	sub "%ScriptPath%\delsub.ins"
endif