Alte Firefox Version deinstallieren, wenn neues Firefox gepusht wird

Antworten
erdemv
Beiträge: 1
Registriert: 11 Mär 2020, 11:30

Alte Firefox Version deinstallieren, wenn neues Firefox gepusht wird

Beitrag von erdemv »

Hallo,

ich benutze derzeit OPSI auf einem Lubuntu und möchte gerne, dass bei der Installation einer neuen Firefox Version, dass alte Firefox automatisch deinstalliert wird.
Mit Scripten bin ich leider nicht sehr vertraut.

Ich habe nun folgendes Problem:
Die neue Firefox Version wird unter C:\Program Files\ installiert.
Die Alte Version liegt unter C:\Program Files (x86)

Im Script wird nur überprüft, ob eine alte Version im Installationsverzeichnis vorhandne ist (sprich: C:\Program Files\)
Über den Setup Detector sowie den OPSI Package builder habe ich ein Firefox Paket erstellt.

Die Scripte sehen wie folgt aus:


setup.opsiscript

Code: Alles auswählen

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

[Actions]
requiredWinstVersion >= "4.12.0.28"
ScriptErrorMessages = false

DefVar $ProductId$
DefVar $InstallDir$
DefVar $MinimumSpace$
DefVar $ExitCode$
DefVar $ErrorString$
DefVar $LicenseRequired$
DefVar $LicenseKey$
DefVar $LicensePool$
DefVar $LogDir$
DefVar $OS$
DefVar $oldProgFound$


Set $LogDir$ = "%opsiLogDir%"

; import complete file !
importlib "uib_exitcode.opsiscript"
importlib "%scriptpath%\osd-lib.opsiscript"


; ----------------------------------------------------------------
; $ProductId$ is the name of the product in opsi, only lower letters, no umlauts, no white spaces, use '-' as a seperator
Set $ProductId$		= "firefox 74.0"
; the path where we find the product after the installation
Set $InstallDir$	= "C:\Program Files\Mozilla Firefox\"
Set $LicenseRequired$ = "False"
Set $LicensePool$	  = "" 
Set $MinimumSpace$	 = "300 MB"
; ----------------------------------------------------------------

set $OS$ = GetOS

if not(($OS$ = "Windows_NT"))
	logError "Installation aborted: wrong OS version: only Windows"
	isFatalError "wrong OS"
endif

if not(HasMinimumSpace ("%SystemDrive%", $MinimumSpace$))
	LogError "Not enough space on %SystemDrive%, " + $MinimumSpace$ + " on drive %SystemDrive% needed for " + $ProductId$
	isFatalError "No Space"
	; Stop process and set installation status to failed
endif

comment "Show product picture"
ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$



if FileExists("%ScriptPath%\delsub.opsiscript")
	comment "Start uninstall sub section"
	Sub "%ScriptPath%\delsub.opsiscript"
endif

Message "Installing " + $ProductId$ + " ..."

if $LicenseRequired$ = "true"
	comment "Licensing required, reserve license and get license key"
	set $LicenseKey$ = get_licensekey_byPoolOrKey($LicensePool$)
endif


comment "Start setup program"
ChangeDirectory "%SCRIPTPATH%\files"
;----------------------------------------------
Winbatch_install	
;----------------------------------------------
Sub_check_exitcode




[Winbatch_install]
"%scriptpath%\files\setup.exe" /S

[sub_check_exitcode]
set $ExitCode$ = getlastexitcode
if stringtobool(isNsisExitcodeFatal($exitcode$, "true", $ErrorString$ ))
	LogError $ErrorString$
	isfatalerror $ErrorString$
else
	Comment $ErrorString$
endif


; ----------------------------------------------------------------
; ----------------------------------------------------------------
Uninstall.opsiscript

Code: Alles auswählen

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


[Actions]
requiredWinstVersion >= "4.12.0.28"
ScriptErrorMessages = false

DefVar $ProductId$
DefVar $InstallDir$
DefVar $MinimumSpace$
DefVar $ExitCode$
DefVar $ErrorString$
DefVar $LicenseRequired$
DefVar $LicenseKey$
DefVar $LicensePool$
DefVar $LogDir$
DefVar $OS$
DefVar $oldProgFound$


Set $LogDir$ = "%opsiLogDir%"


; import complete file !
importlib "uib_exitcode.opsiscript"
importlib "%scriptpath%\osd-lib.opsiscript"


; ----------------------------------------------------------------
; $ProductId$ is the name of the product in opsi, only lower letters, no umlauts, no white spaces, use '-' as a seperator
Set $ProductId$		 = "firefox 74.0"
; the path where we find the product after the installation
Set $InstallDir$	= "C:\Program Files\Mozilla Firefox\"
Set $LicenseRequired$ = "False"
Set $LicensePool$	  = ""
; ----------------------------------------------------------------

set $OS$ = GetOS

if not(($OS$ = "Windows_NT"))
	logError "Installation aborted: wrong OS version: only Windows"
	isFatalError "wrong OS"
endif


comment "Show product picture"
ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$



Message "Uninstalling " + $ProductId$ + " ..."

if FileExists("%ScriptPath%\delsub.opsiscript")
	comment "Start uninstall sub section"
	Sub "%ScriptPath%\delsub.opsiscript"
endif

if $LicenseRequired$ = "true"
	comment "Licensing required, free license used"
	Sub_free_license
endif

[Sub_free_license]
comment "License management is enabled and will be used"

comment "Trying to free license used for the product"
DefVar $result$
Set $result$ = FreeLicense($LicensePool$)
; If there is an assignment of a license pool to the product, it is possible to use
; Set $result$ = FreeLicense("", $ProductId$)
;
; If there is an assignment of a license pool to a windows software id, it is possible to use
; DefVar $WindowsSoftwareId$
; $WindowsSoftwareId$ = "..."
; set $result$ = FreeLicense("", "", $WindowsSoftwareId$)

delsub.opsiscript

Code: Alles auswählen

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

Message "Check for existing installation of " + $ProductId$ + " ..."

comment "Start the Uninstall check:"
set $oldProgFound$ = "false"
if fileexists($installdir$+"\uninstall\helper.exe")
	set $oldProgFound$ = "true"
endif



if $oldProgFound$ = "true"
	Message "Uninstalling " + $ProductId$ + " ..."
	
	comment "Start uninstall program"
	ChangeDirectory "%SCRIPTPATH%\files"
	;----------------------------------------------
	Winbatch_uninstall  /WaitForProcessEnding "Au_.exe" /TimeOutSeconds 20
	;----------------------------------------------
	Sub_check_exitcode_del
	
	if not(($InstallDir$ = '') or ($InstallDir$ = 'unknown'))
		Files_uninstall
	endif
	
endif

[Winbatch_uninstall]
"$Installdir$\uninstall\helper.exe" /S


[Sub_check_exitcode_del]
set $ExitCode$ = getlastexitcode
if stringtobool(isNsisExitcodeFatal($exitcode$, "true", $ErrorString$ ))
	LogError $ErrorString$
	isfatalerror $ErrorString$
else
	Comment $ErrorString$
endif

[Files_uninstall]
del -sf "$InstallDir$\"
del -sf "$oldProg$\"


;-----------------------------------------------------
Wie kann ich jetzt im Code sagen, wenn sowohl im Verzeichnis C:\Programm Files\ als auch im Verzeichnis C:\Program Files (x86), eine alte Firefox Version existiert, diese vor der Installation der neuen Version zu deinstallieren.

Danke im voraus.

Viele Grüße
Erdem
Jan.Schmidt
Beiträge: 439
Registriert: 08 Jul 2017, 12:02

Re: Alte Firefox Version deinstallieren, wenn neues Firefox gepusht wird

Beitrag von Jan.Schmidt »

Hi,

einer von vielen Wegen könnte sein:

* kopiere das Uninstall.opsiscript nach Uninstall_32.opsiscript
* ändere in der Kopie die Pfade zu x86

füge über/unter den Block (wobei ich den so schon öfters gesehen, aber nie verstanden habe, weil da ja nur das vorhandesein des deinstaller scripts aber nicht, ob eine alte Version existiert)

Code: Alles auswählen

if FileExists("%ScriptPath%\delsub.opsiscript")
   comment "Start uninstall sub section"
   Sub "%ScriptPath%\delsub.opsiscript"
endif
noch sowas rein:

Code: Alles auswählen

if FileExists("%ScriptPath%\delsub_32.opsiscript")
   if FileExists("C:\Program Files (x86)\Mozilla Firefox\\uninstall\helper.exe")
      comment "Start uninstall sub section 32bit"
      Sub "%ScriptPath%\delsub_32.opsiscript"
   endif
endif
Das kannste natürlich noch mit Variablen Pfaden machen, dafür war ich aber zu faul und testen musste das auch, weil mein opsiscriptbraindebugger schon Frei hat.
Benutzeravatar
ThomasT
uib-Team
Beiträge: 538
Registriert: 26 Jun 2013, 12:26

Re: Alte Firefox Version deinstallieren, wenn neues Firefox gepusht wird

Beitrag von ThomasT »

Wenn man das opsi-template nutzt, dann wird man genau auf diese Art von Workflow gestoßen
https://download.uib.de/opsi4.1/documen ... l-template
Kein Support per DM!
_________________________
opsi support - https://www.uib.de/
For productive opsi installations we recommend support contracts.
Antworten