[Initial]
Message=Installiere HP UEFI Einstellungen...
DefVar $PropPlacehldr$
DefVar $Uefioldpw$
DefVar $Uefinewpw$
DefVar $Uefibootorder$
DefVar $Uefilanguage$
DefVar $Uefikeyboardlayout$
DefVar $Uefipxeboot$
DefVar $Uefiipv6pxeboot$
DefVar $Uefirestrictusb$
DefVar $Uefimodponpw$
DefVar $Uefipassforbootmn$
DefVar $Uefipassforrecover$
DefVar $Uefipassforpxe$
DefVar $Uefiintspkr$
DefVar $Uefisecureboot$
DefVar $Uefiwakeonlan$
DefVar $Uefiwakeonlanpw$
DefStringList $Result$
DefStringList $PowershellResult$
DefVar $Value$
DefVar $Hostname$
DefVar $Invnumber$
DefVar $ExitCode$


[Actions]
ShowBitmap "%ScriptPath%\logo.png" "HP ProDesk G6 UEFI-Settings"
Sub_GetProperties
Files_Copy
Sub_GetVars
Winbatch_setup /Sysnative
Sub_HandlePw
ExecWith_powershell "powershell.exe" -ExecutionPolicy Bypass
Sub_HandleFirstExitCode
Files_Cleanup
Sub_HandleExitCode


[Sub_GetProperties]
Set $PropPlacehldr$ = GetProductProperty("propplaceholder", "")
Set $Uefioldpw$ = GetProductProperty("oldpw", "")
Set $Uefinewpw$ = GetProductProperty("newpw", "")
Set $Uefibootorder$ = GetProductProperty("uefibootorder", "")
Set $Uefilanguage$ = GetProductProperty("language", "")
Set $Uefikeyboardlayout$ = GetProductProperty("keyboardlayout", "")
Set $Uefipxeboot$ = GetProductProperty("pxeboot", "")
Set $Uefiipv6pxeboot$ = GetProductProperty("ipv6pxeboot", "")
Set $Uefirestrictusb$ = GetProductProperty("restrictusb", "")
Set $Uefimodponpw$ = GetProductProperty("modponpw", "")
Set $Uefipassforbootmn$ = GetProductProperty("passforbootmn", "")
Set $Uefipassforrecover$ = GetProductProperty("passforrecover", "")
Set $Uefipassforpxe$ = GetProductProperty("passforpxe", "")
Set $Uefiintspkr$ = GetProductProperty("intspkr", "")
Set $Uefisecureboot$ = GetProductProperty("secureboot", "")
Set $Uefiwakeonlan$ = GetProductProperty("wakeonlan", "")
Set $Uefiwakeonlanpw$ = GetProductProperty("wakeonlanpw", "")

[Sub_GetVars]
Set $Result$ = GetReturnListFromSection("opsiservicecall_GetPcname")
Set $Hostname$ = TakeString("0", $Result$)
Set $Result$ = GetReturnListFromSection("opsiservicecall_GetInventoryNumber")
Set $Invnumber$ = TakeString("0", $Result$)

comment "Hostname is: " + $Hostname$
comment "Inventory Number is: " + $Invnumber$

[Winbatch_setup]
"%opsiTmpDir%\%installingProdName%\files\hp-cmsl-latest.exe" /silent

[Sub_HandlePw]
Set $PowershellResult$ = PowershellCall('Get-HPBIOSSetupPasswordIsSet')
Set $Value$ = TakeString("0", $PowershellResult$)
comment "BIOS Password set?: " + $Value$

if ($Value$ = "True")
   if not ($Uefioldpw$ = $Uefinewpw$) 
   PowershellCall('Clear-HPBIOSSetupPassword "'+$Uefioldpw$+'"')
   PowershellCall('Set-HPBIOSSetupPassword "'+$Uefinewpw$+'"')
   endif
 else
   PowershellCall('Set-HPBIOSSetupPassword "'+$Uefinewpw$+'"')
endif



[ExecWith_powershell]
Set-HPBIOSSettingValue "$Uefinewpw$" "UEFI Boot Order" "$Uefibootorder$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Select Language" "$Uefilanguage$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Select Keyboard Layout" "$Uefikeyboardlayout$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Network (PXE) Boot" "$Uefipxeboot$"
Set-HPBIOSSettingValue "$Uefinewpw$" "IPv6 during UEFI Boot" "$Uefiipv6pxeboot$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Restrict USB Devices" "$Uefirestrictusb$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Allow User to Modify Power-on Password" "$Uefimodponpw$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Prompt for Admin authentication on F9 (Boot Menu)" "$Uefipassforbootmn$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Prompt for Admin authentication on F11 (System Recovery)" "$Uefipassforrecover$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Prompt for Admin authentication on F12 (Network Boot)" "$Uefipassforpxe$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Internal Speakers" "$Uefiintspkr$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Secure Boot" "$Uefisecureboot$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Wake On LAN" "$Uefiwakeonlan$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Ownership Tag" "$PropPlacehldr$-$Hostname$"
Set-HPBIOSSettingValue "$Uefinewpw$" "Wake on LAN Power-on Password Policy" "$Uefiwakeonlanpw$"

[Files_Copy]
copy -s "\\iserv\deploy\install\%installingProdName%\files\*" "%opsiTmpDir%\%installingProdName%\files\"

[Files_Cleanup]
delete -sf "%opsiTmpDir%\%installingProdName%\"

[Sub_HandleFirstExitCode]
; check return code
Set $ExitCode$ = GetLastExitCode
; checking possible errors on first run
Switch $ExitCode$
         Case "0"
                 comment "Looks good: setup program gives exitcode zero. Proceed."
         EndCase
         DefaultCase
                 comment "We can't handle this Exitcode here: " + $exitcode$
         EndCase
EndSwitch

[Sub_HandleExitCode]
; check return code
Set $ExitCode$ = GetLastExitCode
comment "GetLastExitCode: " + $ExitCode$
if not($ExitCode$ = "0")
  LogError "Fatal: setup returned exit code " + $ExitCode$
  IsFatalError
endif


[opsiservicecall_GetPcname]
"method":"collect_wlan_mac_hostName"
"params":[]

[opsiservicecall_GetInventoryNumber]
"method":"collect_wlan_mac_inventoryNumber"
"params":[]
