lokale Funktionen

Antworten
zitronent
Beiträge: 12
Registriert: 01 Feb 2019, 11:04

lokale Funktionen

Beitrag von zitronent »

Bin am verzweifeln.
Bastle grade an einer Funktion seit ein paar Tagen.
Seit heute (ohne einen für mich ersichtlichen Grund) bricht diese jedesmal ab mit der im weiteren genannten Fehlermeldung, wobei das Skript zuvor immer durchgelaufen ist.
Einziger Unterschied: Ich habe die Funktion in eine eigene Bibliotheksdatei kopiert, da die Funktion langsam zu groß geworden ist.

(95) [7] [Aug 29 14:21:46:209] [opsifunctest] Found ImportLib statement for file: p:\opsifunctest\..\lib\myOpsiLibrary\fs_adv.opsiscript and function: _doStd64
(96) [5] [Aug 29 14:21:46:251] [opsifunctest] Imported function : _doStd64 from file: p:\lib\myOpsiLibrary\fs_adv.opsiscript
(97) [2] [Aug 29 14:21:46:254] [opsifunctest] Found DefFunc without EndFunc
(98) [2] [Aug 29 14:21:46:254] [opsifunctest] Syntax Error in Section: Actions (Command in line 179 in section: Actions; file: testlib_aufruf.opsiscript; section start at line: 1; origin: testlib_aufruf.opsiscript; line: 179): -> Found DefFunc without EndFunc

Anbei der Code:

Code: Alles auswählen

DefFunc _doStd64(val $relPTI$ : string, val $MinimumSpace$ : string) : void
	DefStringList $ProductMap_List$
	DefVar $ProductId$
	DefVar $ProductName$
	DefVar $ProductVersion$
	DefVar $ActionRequest$
	Set $ProductMap_List$ = getProductMap
	Set $ProductId$ = getValue("id", $ProductMap_List$)
	Set $ProductName$ = getValue("name", $ProductMap_List$)
	Set $ProductVersion$ = getValue("productversion", $ProductMap_List$)
	Set $ActionRequest$ = getValue("actionrequest", $ProductMap_List$)

	comment "Search for product picture"
	if (FileExists("%ScriptPath%\..\lib\icons\%installingProdName%.png"))
		comment "logo at local library/icons found."
		ShowBitmap "%ScriptPath%\..\lib\icons\%installingProdName%.png" $ProductName$
	else
		comment "no logo at local library/icons, searching in ScriptPath ..."
		if (FileExists("%ScriptPath%\%installingProdName%.png"))
			comment "logo at %Scriptpath% found."
			ShowBitmap "%ScriptPath%\%installingProdName%.png" $ProductName$
		else
			comment "no logo was found. Proceeding without any logo."
		endif
	endif

	if($ActionRequest$ = "setup")
		Comment "Setup was called."
		Message "Installing " + $ProductId$
		DefVar $PTR$
		if (not(FileExistsSysNative("%ScriptPath%\" + $relPTI$)) OR (DirectoryExists("%ScriptPath%\" + $relPTI$)))
			Comment "Installer-runnable not found, trying to guess..."
			DefVar $pspolicysafe$
			DefStringList $runnablesList$
			DefStringList $installerKeywords$
			DefVar $counter$
			DefStringList $searchResults$
			DefStringList $tempSectionOutput$
			Set $pspolicysafe$ = takeString(0,shellCall('powershell.exe get-executionpolicy'))
			Set $installerKeywords$ = createStringList('setup','inst','64','win','amd')
			shellCall('powershell.exe set-executionpolicy Unrestricted')
			Set $runnablesList$ = getSubListByContaining("Microsoft.PowerShell.Core\FileSystem", getOutStreamFromSection("ExecWith_PS_searchForRunnables powershell.exe winst /SysNative"))
			if (count($runnablesList$) INT> "0")
				if (count($runnablesList$) INT= "1")
					Comment "A sole runnable (exe, msi or bin) was found in scriptpath or its respective childs."
					Comment "Try to check name for typical installer keywords."
					Set $PTR$ = takeString(1,splitString(takeString(0,$runnablesList$), "::"))
					Set $counter$ = "0"
					for $item$ in $installerKeywords$ do Sub_checkForInstKeywords
					Comment "Verifying..."
					if (($counter$ INT> "0") AND not(contains(lower($PTR$), "uninst")) AND not(contains(lower($PTR$), "deinst")))
						Comment $PTR$ + " seems to be an installer. Will take it and hope this does not end bad."
					else
						shellCall('powershell.exe set-executionpolicy ' + $pspolicysafe$)
						LogError "Could not verify runnable as an possible installer."
						isFatalError
					endif
				else
					Comment "There are several runnables (exe, msi or bin) in scriptpath or its respective childs. Try to guess further."
					DefStringList $hasKeyword$
					DefVar $loopHelperVar$
					for %i% = "0" to calculate(count($runnablesList$)+"-1") do Set $runnablesList$ = setStringInListAtIndex(takeString(1,splitString(takeString(%i%,$runnablesList$),"::")),$runnablesList$,"%i%")
					for %n% = "0" to calculate(count($runnablesList$)+"-1") do Sub_checkForInstKeywordsInList
					if not(count($runnablesList$) INT= count($hasKeyword$))
						shellCall('powershell.exe set-executionpolicy ' + $pspolicysafe$)
						LogError "Fatal Error in Function _doStd64. Aborting operation."
						isFatalError
					endif
					Set $counter$ = "0"
					for %u% = "0" to calculate(count($runnablesList$)+"-1") do Sub_countPossibInst
					if ($counter$ INT= "0")
						shellCall('powershell.exe set-executionpolicy ' + $pspolicysafe$)
						LogError "Fatal Error in Function _doStd64. Aborting operation."
						isFatalError
					else
						if not($counter$ INT= "1")
							shellCall('powershell.exe set-executionpolicy ' + $pspolicysafe$)
							LogError "There are more than one runnable (exe, msi or bin) in scriptpath or its respective childs, which could be potential installer files. Give relative path to installer with parameter to this function."
							isFatalError
						else
							Comment "Only a single runnable (exe, msi or bin) was found in scriptpath or its respective childs, which could be a potential installer file."
							for %x% = "0" to calculate(count($runnablesList$)+"-1") do Sub_getRunByMap
							Comment $PTR$ + " seems to be an installer. Will take it and hope this does not end bad."
						endif
					endif
				endif
			else
				shellCall('powershell.exe set-executionpolicy ' + $pspolicysafe$)
				LogError "No runnable (exe, msi or bin) installer was found in scriptpath or its respective childs."
				isFatalError
			endif
		else
			Set $PTR$ = "%ScriptPath%\" + $relPTI$
		endif
		shellCall('powershell.exe set-executionpolicy ' + $pspolicysafe$)
		Comment $PTR$

		if not (isRegexMatch($MinimumSpace$, "^[1-9][0-9]* MB$"))
			DefStringList $estMinSpcList$
			Comment "Invalid input for parameter MinimumSpace. Only input with matches regex pattern ^[1-9][0-9]* MB$ is allowed. Trying to estimate the required space on C: conservatively."
			shellCall('powershell.exe set-executionpolicy Unrestricted')
			
			Set $estMinSpcList$ = getSubListByContaining("Bytes", shellCall('powershell.exe robocopy "%ScriptPath%" "c:\tmp" /zb /e /l /r:1 /w:1 /nfl /ndl /nc /fp /bytes /np /njh'))

			shellCall('powershell.exe set-executionpolicy ' + $pspolicysafe$)
			if not(count($estMinSpcList$) INT= "1")
				LogError "Fatal Error in Function _doStd64. Aborting operation."
				isFatalError
			endif
			Set $MinimumSpace$ = takeString(2,splitStringOnWhiteSpace(takeString(0,$estMinSpcList$)))
			if not(isNumber($MinimumSpace$))
				LogError "Fatal Error in Function _doStd64. Aborting operation."
				isFatalError
			endif
			if ($MinimumSpace$ INT< "100000")
				LogError "Estimated minimum space too small to make sense. Aborting Operation."
				isFatalError
			endif
		endif
		if not (GetMsVersionInfo = "10.0")
			LogError "Sorry, this installation package is only for Windows 10."
			isFatalError
		endif
		if not (GetSystemType = "64 Bit System")
			LogError "Sorry, this installation package is only for 64bit systems."
			isFatalError
		endif
		if not(HasMinimumSpace ("%SystemDrive%", $MinimumSpace$))
			LogError "Not enough space on %SystemDrive%, at least " + $MinimumSpace$ + " on drive %SystemDrive% is needed."
			isFatalError
		endif

	else
		if($ActionRequest$ = "uninstall")
			;do uninstall routines
		else
			LogError "Only action requests <setup> and <uninstall> are allowed. Aborting Operation."
			isFatalError
		endif
	endif

	[ExecWith_PS_searchForRunnables]
	Get-ChildItem -Path '%ScriptPath%' -Recurse -force -ErrorAction SilentlyContinue | Where-Object {($_.Name -like '*.exe') -or ($_.Name -like '*.msi')  -or ($_.Name -like '*.bin')} | Select-Object PSPath

	[Sub_checkForInstKeywords]
	if contains(lower($PTR$),"$item$")
		Set $counter$ = calculate($counter$+"1")
	endif

	[Sub_checkForInstKeywordsInList]
	Set $loopHelperVar$ = "%n%"
	Set $counter$ = "0"
	for %t% = "0" to calculate(count($installerKeywords$)+"-1") do Sub_Sub_checkForInstKeywordsInList
	if (($counter$ INT> "0") AND not(contains(lower(takeString($loopHelperVar$,$runnablesList$)), "uninst")) AND not(contains(lower(takeString($loopHelperVar$,$runnablesList$)), "deinst")))
		Set $hasKeyword$ = addtolist($hasKeyword$, "true")
	else
		Set $hasKeyword$ = addtolist($hasKeyword$, "false")
	endif

	[Sub_Sub_checkForInstKeywordsInList]
	if ((contains(lower(takeString($loopHelperVar$,$runnablesList$)),takeString(%t%,$installerKeywords$))))
		Set $counter$ = calculate($counter$+"1")
	endif

	[Sub_countPossibInst]
	if (stringToBool(takeString(%u%, $hasKeyword$)))
		Set $counter$ = calculate($counter$+"1")
	endif

	[Sub_getRunByMap]
	if (stringToBool(takeString(%x%, $hasKeyword$)))
		Set $PTR$ = takeString(%x%, $runnablesList$)
	endif

	[ExecWith_PS_estMinSpc]
	robocopy "%ScriptPath%" "c:\tmp" /zb /e /l /r:1 /w:1 /nfl /ndl /nc /fp /bytes /np /njh

endfunc

zitronent
Beiträge: 12
Registriert: 01 Feb 2019, 11:04

Re: lokale Funktionen

Beitrag von zitronent »

Also nach dreivierteltägigem try and error habe ich jetzt die Ursache gefunden:

Wenn die Funktion als allerletztes in einem opsi-Installationsskript-Ablauf aufgerufen wird kommt der besagte Fehler. Z.B.:

Code: Alles auswählen

[Actions]
importLib "%ScriptPath%\..\lib\myOpsiLibrary\fs_adv.opsiscript"
_doStd64("","")
Kommt danach hingegen noch irgendeine andere Anweisung funktioniert alles. Z.B.:

Code: Alles auswählen

[Actions]
importLib "%ScriptPath%\..\lib\myOpsiLibrary\fs_adv.opsiscript"
_doStd64("","")
Comment "Hello World"
Weiß nicht ob das jemandem hilft oder nur ein Problem bei mir ist aber schaden kann es nicht...
Benutzeravatar
n.wenselowski
Ex-uib-Team
Beiträge: 3194
Registriert: 04 Apr 2013, 12:15

Re: lokale Funktionen

Beitrag von n.wenselowski »

Hi,

ich würde mal vermuten das ist ein Bug.
Nutzt du schon den aktuellen opsi-winst (4.12.1.5-1)?
Falls nein: Tritt das Verhalten damit noch immer auf?


Gruß

Niko

Code: Alles auswählen

import OPSI
zitronent
Beiträge: 12
Registriert: 01 Feb 2019, 11:04

Re: lokale Funktionen

Beitrag von zitronent »

Also laut opsi-configed ist auf dem Testrechner (auf welchem ich die Skripte getestet habe) opsi-winst 4.12.1.5 installiert.

Mit freundlichen Grüßen
zitronent
Benutzeravatar
n.wenselowski
Ex-uib-Team
Beiträge: 3194
Registriert: 04 Apr 2013, 12:15

Re: lokale Funktionen

Beitrag von n.wenselowski »

Hi zitronent,

danke für die Rückmeldung.
Ich habe daraus ein internes Ticket gemacht.


Gruß

Niko

Code: Alles auswählen

import OPSI
Benutzeravatar
d.oertel
uib-Team
Beiträge: 3319
Registriert: 04 Jun 2008, 14:27

Re: lokale Funktionen

Beitrag von d.oertel »

Hi,

ich verstehe den praktischen Sinn des Problems nicht:

Eine Funktion muß definiert oder importiert werden bevor sie aufgerufen werden kann.
Von daher macht eine Importanweisung als letzte Zeile in der [actions] sektion keinen Sinn.

Habe ich etwas falsch verstanden ?

gruß
d.oertel
opsi support - uib gmbh

For productive opsi installations we recommend support contracts.
http://www.uib.de
http://www.opsi.org
zitronent
Beiträge: 12
Registriert: 01 Feb 2019, 11:04

Re: lokale Funktionen

Beitrag von zitronent »

Ja es geht nicht um die Importanweisung, sondern um den Funktionsaufruf als letzte Zeile.
Benutzeravatar
d.oertel
uib-Team
Beiträge: 3319
Registriert: 04 Jun 2008, 14:27

Re: lokale Funktionen

Beitrag von d.oertel »

Ok - jetzt habe ichs.

Ich konnte das jetzt auch mit einem kleinen Test nachstellen
und habe diesen an das interne Ticke dran gehängt.

Danke für den Hinweis.
Ich kümmere mich demnächst darum.

gruß
d.oertel
opsi support - uib gmbh

For productive opsi installations we recommend support contracts.
http://www.uib.de
http://www.opsi.org
zitronent
Beiträge: 12
Registriert: 01 Feb 2019, 11:04

Re: lokale Funktionen

Beitrag von zitronent »

Vielen Dank für die schnelle Rückmeldung. :D

Mit freundlichen Grüßen
zitronent
Antworten