Set $INST_Resultlist$ = getMSVersionMap
Das Copyright an diesem Handbuch liegt bei der uib gmbh in Mainz.
Dieses Handuch ist veröffentlicht unter der creative commons Lizenz
Namensnennung - Weitergabe unter gleichen Bedingungen (by-sa).
Eine Beschreibung der Lizenz finden Sie hier:
http://creativecommons.org/licenses/by-sa/3.0/de/
Der rechtsverbindliche Text der Lizenz ist hier:
http://creativecommons.org/licenses/by-sa/3.0/de/legalcode
Die Software von opsi ist in weiten Teilen Open Source.
Nicht Open Source sind die Teile des Quellcodes, welche neue Erweiterungen enthalten die noch unter Kofinanzierung stehen, also noch nicht bezahlt sind.
siehe auch:
http://uib.de/de/opsi-erweiterungen/erweiterungen/
Der restliche Quellcode ist veröffentlicht unter der AGPLv3:
Der rechtsverbindliche Text der AGPLv3 Lizenz ist hier:
http://www.gnu.org/licenses/agpl-3.0-standalone.html
Deutsche Infos zur AGPL: http://www.gnu.org/licenses/agpl-3.0.de.html
Für Lizenzen zur Nutzung von opsi im Zusammenhang mit Closed Source Software kontaktieren Sie bitte die uib gmbh.
Die Namen opsi, opsi.org, open pc server integration und das opsi-logo sind eingetragene Marken der uib gmbh.
GetMsVersionInfo |
Windows Version |
|
5.0 |
Windows 2000 |
|
5.1 |
Windows XP (Home, Prof) |
|
…. |
…. |
|
6.1 |
Windows 7, 2008 R2 |
|
6.2 |
Windows 8, 2012 |
|
6.3 |
Windows 8.1, 2012 R2 |
|
10.0 |
Windows 10 |
Set $INST_Resultlist$ = getMSVersionMap
(string 0)major_version=5 (string 1)minor_version=1 (string 2)build_number=2600 (string 3)platform_id=2 ....
DefVar $result$ set $result$ = getValue("build_number", $INST_Resultlist$)
Set $INST_Resultlist$ = getLinuxVersionMap
(string 0)Distributor ID=Ubuntu (string 1)Description=Ubuntu 16.04.3 LTS (string 2)Release=16.04 (string 3)Codename=xenial (string 4)SubRelease= (string 5)kernel name=Linux ...
shellCall("echo Hallo Welt")
set $string$ = shellCall("echo Hallo Welt")
set $stringlist$ = shellCall("echo Hallo Welt")
shellCall(’net start’)
DosInAnIcon_netstart winst /sysnative [DosInAnIcon_netstart] net start
DefVar $exitcode$ set $exitcode$ = shellCall(’net start’)
DefVar $exitcode$ DosInAnIcon_netstart winst /sysnative set $exitcode$ = getLastExitcode [DosInAnIcon_netstart] net start
DefStringList $list$ set $list$ = shellCall(’net start’)
DefStringList $list$ set $list$ = getOutStreamFromSection (’DosInAnIcon_netstart winst /sysnative’) [DosInAnIcon_netstart] net start
processCall(<string>) :string (exitcode) [W/L]
Startet das Programm <string> als Prozess und liefert den Exitcode zurück.
set $exitcode$ = processCall('setup.exe /S')
Winbatch_setup set $exitcode$ = getLastExitcode [Winbatch_setup] setup.exe /S
Message "Try to get Package Lock..." if waitForPackageLock("300","false") comment "we got the package lock." if $distroName$ = 'Univention' comment "UCS: Extra check if package lock is available." ... endif else LogError "could not get Package Lock" isFatalError "package lock failed" endif
getLastExitCode :string (exitcode) [W/L] markErrorNumber / errorsOccurredSinceMark [W/L] LogError
getLastExitCode :string (exitcode) [W/L]
cmd.exe
[DosInAnIcon_exit1] rem create an errolevel= 1 VERIFY OTHER 2> NUL exit %ERRORLEVEL%
bash
[ShellInAnIcon_Upgrade_ucs] set -x univention-upgrade --noninteractive --ignoreterm exit $?
[ShellInAnIcon_Upgrade_deb] set -x export DEBIAN_FRONTEND=noninteractive apt-get update apt-get --yes dist-upgrade exit $?
[ShellInAnIcon_Upgrade_deb] set -x export DEBIAN_FRONTEND=noninteractive EXITCODE=0 apt-get update EC=$?; if [ $EC -ne 0 ]; then EXITCODE=$EC; fi apt-get --yes dist-upgrade EC=$?; if [ $EC -ne 0 ]; then EXITCODE=$EC; fi exit $EXITCODE
set $exitcode$ = shellCall("apt-get update") if $exitcode$ = 0 set $exitcode$ = shellCall("apt-get --yes dist-upgrade") if NOT ($exitcode$ = 0) logError("dist-updrade failed with exitcode: " + $exitcode) endif else logError("apt-get update failed with exitcode: " + $exitcode) endif
Beispiel:
markErrorNumber logError "test error" if errorsOccurredSinceMark > 0 comment "error occured" else comment "no error occured" endif
isFatalError [W/L] isSuspended [W/L] isSuccess [W/L] noUpdateScript [W/L]
isFatalError isFatalError "short message"
DefStringList $ErrorList$ Message "Configure depotadmin as depotadmin..." ShellInAnIcon_config_depotadmin if not("0" = getLastExitCode) LogError "failed config_depotadmin" set $fatal_error$ = "true" set $errorList$ = addtolist($errorList$, " failed config_depotadmin") endif if count($errorList$) > "0" logError "Error summary:" setloglevel = 6 for %akterror% in $errorList$ do LogError "%akterror%" endif if $fatal_error$ = "true" isFatalError endif
isSuccess
//since 4.11.3.7 [W/L]noUpdateScript
//since 4.11.3.7 [W/L]isSuspended
//since 4.11.4.1 [W/L]Ein Beispiel:
DefFunc myFunc(val $str1$ : string, $str2$ : string) : string set $result$ = $str1$ + $str2$ endfunc
string
oder stringlist
ist. Der Aufruf eine solchen Funktion kann überall da Erfolgen, wo ein Stringausdruck bzw.eine Stringliste erwartet wird.
string
oder stringlist
sein.val
. CallByValue bedeutet, das beim Aufruf der Inhalt einer beim Aufruf verwendeten Variable auf die Aufrufvariable kopiert wird.
ref
) bedeutet, dass beim Aufruf eine Verbindung zwischen der aufrufenden Varibalen und des lokalen Aufrufparameters erstellt wird. Eine Änderung der lokalen Variable des Aufrufparameters, wirkt sich direkt auf die beim Aufruf verwendete Variable aus.$result$
welche vom Typ des Rückgabewertes ist. Darüberhinaus können weitere Variablen innerhalb der Funktion definiert werden.DefFunc <func name>([calltype parameter type][,[calltype parameter type]]) : type <function body> endfunc
DefFunc
das Schlüsselwort zur Beginn der Definition einer lokalen Funktion.
val
| ref
]. Wird kein Aufruftyp angegeben, so gilt val
als gesetzt.
DefFunc <func name>([calltype parameter type][,[calltype parameter type]]) : type <function body> endfunc
string
oder stringlist
.
$result$
,
welche den Datentyp der Funktion hat (String/Stringliste) und dazu dient den Rückgabewert aufzunehmen.
endfunc
zeigt als Schlüsselwort das Ende einer Funktionsdefinition an.
[actions] DefVar $mystr$ DefVar $str1$ set $str1$ = 'ha' DefFunc myFunc(val $str1$ : string, $str2$ : string) : string set $result$ = $str1$ + $str2$ endfunc set $mystr$ = myFunc("he","ho") set $mystr$ = myFunc("he",timeStampAsFloatStr) set $mystr$ = myFunc("he",$str1$)
.... set $mystr$ = myFunc("he","ho") set $mystr$ = myFunc("he",timeStampAsFloatStr) set $mystr$ = myFunc("he",$str1$) ....
[actions] DefVar $mystr$ DefVar $str1$ DefStringlist $list1$ DefStringlist $list2$ set $str1$ = 'ha' DefFunc myFunc1(val $str1$ : string, $list1$ : stringlist) : stringlist set $result$ = createStringlist($str1$ , takeString(2,$list1$)) endfunc set $list2$ = splitstring("/etc/opsi/huhu","/") set $list1$ = myFunc1("hi",$list2$)
[actions] DefFunc myFunc2($str1$ : string) : string if $str1$ > "0" set $result$ = "true" else set $result$ = "false" endif endfunc if stringtobool(myfunc2("1")) comment "true" else comment "false" endif
(defined_functions3.opsiscript)
[actions] DefVar $mystr$ DefFunc myFunc3($str1$ : string) : string DefVar $locstr1$ set $locstr1$ = '123' set $result$ = $locstr1$ + $str1$ endfunc set $mystr$ = myFunc3("he")
[actions] DefVar $mystr$ DefFunc myFunc4($str1$ : string) : string DefVar $locstr1$ DefFunc myFunc5($str1$ : string) : string set $result$ = 'inner' + $str1$ endfunc set $locstr1$ = '123' set $result$ = $str1$ + myFunc5($locstr1$) endfunc set $mystr$ = myFunc4("outer")
[actions] DefStringlist $list1$ DefFunc myFunc8($str1$ : string) : stringlist DefStringlist $loclist1$ set $loclist1$ = getoutstreamfromsection("shellInAnIcon_test") set $result$ = $loclist1$ [shellinanicon_test] set -x $str1$ endfunc if GetOS = 'Linux' set $list1$ = myFunc8('set -x ; pwd') else set $list1$ = myFunc8('echo %cd%') endif
$list1$ = [pwd, /home/uib/gitwork/lazarus/opsi-script]
The value of the variable "$list1$" is now: (string 0) (string 1)W:\opsi-script-test\CLIENT_DATA\standalone-tests>echo W:\opsi-script-test\CLIENT_DATA\standalone-tests (string 2)W:\opsi-script-test\CLIENT_DATA\standalone-tests
`importLib` <string expr> ; import library // since 4.12.0.0 <string expr> : <file name>[.<file extension>][`::`<function name>] Wenn keine '.<file extension>' (Dateierweiterung übergeben wird, so wird `.opsiscript` als Default verwendet. Wenn kein '::<function name>' über geben wird, so werden alle Funktionen der angegebenen Datei importiert.
%ScriptPath%
[W/L]
%opsiScriptHelperPath%\lib
[W]
(Entspricht: %ProgramFiles32Dir%\opsi.org\opsiScriptHelper\lib)
%ScriptPath%/../lib
//since 4.11.5.2 [W/L]
%WinstDir%\lib
[W]
DefFunc myFunc(val $str1$ : string, $str2$ : string) : string set $result$ = $str1$ + $str2$ endfunc
[actions] DefVar $mystr$ DefVar $str1$ importLib "%scriptpath%\myfirstlib.opsiscript" set $str1$ = 'ha' set $mystr$ = myFunc("he","ho") set $mystr$ = myFunc("he",timeStampAsFloatStr) set $mystr$ = myFunc("he",$str1$)
Die Zeile
importLib "%scriptpath%\myfirstlib.opsiscript"
könnte auch folgende Form haben:
importLib "myfirstlib.opsiscript"
%scriptpath%
ist im Suchpfad;importLib "myfirstlib"
.opsiscript
ist der Default;importLib "myfirstlib.opsiscript::myFunc"
opsi-script Library im opsi-winst Paket
Seit opsi-script 4.12.0.13 enthält das Unterverzeichnis lib
Librarydateien welche von Standard opsi Produkten verwendet werden:
Diese Library wird direkt von uib gepflegt und dient hauptsächlich für interne Zwecke.
Wir starten hiermit den Aufbau einer öffentlichen opsi-script Bibliothek die zum Austauch innerhalb der opsi Community dienen soll
Namespace:
Ob und wie sollen die Funktionen aus dieser Library am Namen erkennbar sein ?
z.B. opsi als Post- oder Prefix ?
Damit Funktionen einer Library auch verwendet werden, müssen sie nach Funktion und Syntax auffindbar sein.
D.h. sie müssen dokumentiert und in einer zentralen Dokumentation aufgefürt sein. Dazu wird zur Zeit ein Werkzeug entwickelt, welches auf Basis von Kommentaren innerhalb der Funktion eine Dokumentation in den Formaten HTML, PDF, ASCIIDOC erstellen kann.
Wir planen die Bereitstellung der Library in unserem öffentlichen Versionskontrollsystem GIT.
Zur Verteilung soll die Library natürlich auch als opsi-Paket Bereitgestellt werden
Für die Funktionen müssen Tests bereit stehen:
/
#