#!ipxe

set api_host test.baldr.yandex.net
set alt_api_host api.baldr.yandex.net
set cur_env Testing
set alt_env Production
set base_handler_url https://${api_host}/v1/task
set alt_base_handler_url https://${alt_api_host}/v1/task
set handler_url ${base_handler_url}
set alt_handler_url ${alt_base_handler_url}

:net-boot
menu iPXE boot menu
  item --gap -- -------------------------------- Testing    ----------------------------------
  item --gap -- ------------------------------ Standard workflow -----------------------------
  item auto-deploy   Automatic deploy system
  item --gap -- ----------------------------- Additional workflow ----------------------------
  item market_warehouse         Market Warehouse
  item saratov_call_center      Saratov Call Center
  item windows_11_21h2          Windows 11 Enterprise 21H2
  item windows_10_21h1          Windows 10 Enterprise 21H1
  item windows_10_20h2          Windows 10 Enterprise 20H2
  item windows_10_20h1          Windows 10 Enterprise 20H1
  item animals                  Animals
  item animals_test             Animals (Test)
  item wipe                     Wipe
  item linux_pre_deploy         Linux Pre-deployment
  item --gap -- ----------------------------- Change environment -----------------------------
  item change-env    Go to ${alt_env}
  choose --default auto-deploy --timeout 5000 target && goto ${target} || goto net-boot

:auto-deploy
params
set idx:int32 0
  :loop isset ${net${idx}/mac} || goto loop_done
    isset ${macs} || set macs ${net${idx}/mac:hexhyp} && inc idx && goto loop
    set macs ${macs},${net${idx}/mac:hexhyp}
    inc idx && goto loop
  :loop_done
param mac ${macs}
param serial_number ${serial}
param uuid ${uuid}
param platform ${platform}
param manufacturer ${manufacturer}
param product ${product}
param next_server ${next-server}
param filename ${filename}
param hostname ${hostname}
param user_class ${user-class}
param asset ${asset}

chain --timeout 30000 ${handler_url}##params || goto auto-deploy

:market_warehouse
set handler_url ${base_handler_url}?template=market_warehouse
goto auto-deploy

:saratov_call_center
set handler_url ${base_handler_url}?template=saratov_call_center
goto auto-deploy

:windows_11_21h2
set handler_url ${base_handler_url}?template=windows_11_21h2
goto auto-deploy

:windows_10_21h1
set handler_url ${base_handler_url}?template=windows_10_21h1
goto auto-deploy

:windows_10_20h2
set handler_url ${base_handler_url}?template=windows_10_20h2
goto auto-deploy

:windows_10_20h1
set handler_url ${base_handler_url}?template=windows_10_20h1
goto auto-deploy

:animals
set handler_url ${base_handler_url}?template=animals
goto auto-deploy

:animals_test
set handler_url ${base_handler_url}?template=animals_test
goto auto-deploy

:wipe
set handler_url ${base_handler_url}?template=wipe
goto auto-deploy

:linux_pre_deploy
set handler_url ${base_handler_url}?template=linux_pre_deploy
goto auto-deploy

:change-env
chain ${alt_handler_url} || goto change-env
