#!ipxe

set server_ip 10.10.50.10
set base_url http://${server_ip}

# ------------------------------------------------------------------
# Ubuntu 24.04 Group A/B
# Kernel/initrd are loaded by HTTP.
# Root filesystem is mounted by NFS.
# Autoinstall user-data/meta-data are loaded by HTTP NoCloud.
# ------------------------------------------------------------------

set custom_kernel ${base_url}/images/ubuntu-24.04/group-a/custom-os/vmlinuz
set custom_initrd ${base_url}/images/ubuntu-24.04/group-a/custom-os/initrd
set custom_nfs 10.10.50.10:/srv/provision/nfs/ubuntu-24.04/group-a/custom-os
set custom_nocloud ${base_url}/autoinstall/group-a/


# ------------------------------------------------------------------
# Ubuntu 24.04 Group C - ANPRC v2
# ------------------------------------------------------------------

set anprc_c_kernel ${base_url}/images/ubuntu-24.04/group-c/anprc-v2/vmlinuz
set anprc_c_initrd ${base_url}/images/ubuntu-24.04/group-c/anprc-v2/initrd
set anprc_c_nfs 10.10.50.10:/srv/provision/nfs/ubuntu-24.04/group-c/anprc-v2
set anprc_c_nocloud ${base_url}/autoinstall/group-c/


# ------------------------------------------------------------------
# Clonezilla Group D - L1 v1.13
# Kernel/initrd/squashfs are loaded by HTTP.
# /home/partimag is mounted manually by ocs_prerun.
# Target disk is selected automatically by rutoll-auto-restore.sh.
# ------------------------------------------------------------------

set clonezilla_d_base ${base_url}/images/clonezilla/group-d/l1-v1.13
set clonezilla_d_kernel ${clonezilla_d_base}/vmlinuz
set clonezilla_d_initrd ${clonezilla_d_base}/initrd.img
set clonezilla_d_squashfs ${clonezilla_d_base}/filesystem.squashfs

set clonezilla_d_partimag_server 10.10.50.10
set clonezilla_d_partimag_path /srv/provision/nfs/ubuntu-24.04/group-d/l1-v1.13/home/partimag
set clonezilla_d_restore_script ${base_url}/scripts/rutoll-auto-restore.sh
set clonezilla_d_min_gb 50


# ------------------------------------------------------------------
# Main menu
# ------------------------------------------------------------------

:start
menu Provision Server

item --gap -- ---------------- Device Groups ----------------
item group_a Install device Group A - Ubuntu 24.04 dw
item group_b Install device Group B - Ubuntu 24.04 autoinstall
item group_c Install device Group C - Ubuntu 24.04 anprc-v2
item group_d Install device Group D - Clonezilla L1 v1.13

item --gap -- ---------------- Tools ----------------
item shell iPXE shell
item reboot Reboot

choose --default group_a --timeout 10000 target && goto ${target}
goto start


# ------------------------------------------------------------------
# Group A
# ------------------------------------------------------------------

:group_a
echo Selected: Group A
echo Ubuntu 24.04 autoinstall via NFS + HTTP NoCloud.
echo Kernel: ${custom_kernel}
echo Initrd: ${custom_initrd}
echo NFS: ${custom_nfs}
echo NoCloud: ${custom_nocloud}

imgfree

kernel ${custom_kernel} initrd=initrd ip=dhcp boot=casper netboot=nfs nfsroot=${custom_nfs} autoinstall ds=nocloud-net;s=${custom_nocloud} --- || goto group_a_failed
initrd --name initrd ${custom_initrd} || goto group_a_failed

imgstat

boot || goto group_a_failed


:group_a_failed
echo
echo ERROR: Group A boot failed.
echo Check kernel/initrd URLs, NFS export and NoCloud files.
echo
echo Kernel: ${custom_kernel}
echo Initrd: ${custom_initrd}
echo NFS: ${custom_nfs}
echo NoCloud: ${custom_nocloud}
echo
prompt Press any key to return to main menu...
goto start


# ------------------------------------------------------------------
# Group B
# Пока использует тот же custom-os и autoinstall, что Group A.
# ------------------------------------------------------------------

:group_b
echo Selected: Group B
echo Ubuntu 24.04 autoinstall via NFS + HTTP NoCloud.
echo Kernel: ${custom_kernel}
echo Initrd: ${custom_initrd}
echo NFS: ${custom_nfs}
echo NoCloud: ${custom_nocloud}

imgfree

kernel ${custom_kernel} initrd=initrd ip=dhcp boot=casper netboot=nfs nfsroot=${custom_nfs} autoinstall ds=nocloud-net;s=${custom_nocloud} --- || goto group_b_failed
initrd --name initrd ${custom_initrd} || goto group_b_failed

imgstat

boot || goto group_b_failed


:group_b_failed
echo
echo ERROR: Group B boot failed.
echo Check kernel/initrd URLs, NFS export and NoCloud files.
echo
echo Kernel: ${custom_kernel}
echo Initrd: ${custom_initrd}
echo NFS: ${custom_nfs}
echo NoCloud: ${custom_nocloud}
echo
prompt Press any key to return to main menu...
goto start


# ------------------------------------------------------------------
# Group C - Ubuntu 24.04 ANPRC v2
# ------------------------------------------------------------------

:group_c
echo Selected: Group C
echo Ubuntu 24.04 ANPRC v2 autoinstall via NFS + HTTP NoCloud.
echo Kernel: ${anprc_c_kernel}
echo Initrd: ${anprc_c_initrd}
echo NFS: ${anprc_c_nfs}
echo NoCloud: ${anprc_c_nocloud}

imgfree

kernel ${anprc_c_kernel} initrd=initrd ip=dhcp boot=casper netboot=nfs nfsroot=${anprc_c_nfs} autoinstall ds=nocloud-net;s=${anprc_c_nocloud} --- || goto group_c_failed
initrd --name initrd ${anprc_c_initrd} || goto group_c_failed

imgstat

boot || goto group_c_failed


:group_c_failed
echo
echo ERROR: Group C boot failed.
echo Check kernel/initrd URLs, NFS export and NoCloud files.
echo
echo Kernel: ${anprc_c_kernel}
echo Initrd: ${anprc_c_initrd}
echo NFS: ${anprc_c_nfs}
echo NoCloud: ${anprc_c_nocloud}
echo
prompt Press any key to return to main menu...
goto start


# ------------------------------------------------------------------
# Group D - Clonezilla image selection menu
# ------------------------------------------------------------------

:group_d
menu Group D - Clonezilla L1 v1.13 image selection

item --gap -- ---------------- Available images ----------------
item d_tp       Restore TP-v1.13 to auto disk >= 50GB
item d_avc      Restore AVC-v1.13 to auto disk >= 50GB
item d_dwlatm   Restore DW-LATM-v1.13 to auto disk >= 50GB
item d_dw       Restore DW-v1.14 to auto disk >= 50GB
item d_latm     Restore LATM-v1.13 to auto disk >= 50GB

item --gap -- ---------------- Tools ----------------
item d_clonezilla_shell Boot Clonezilla shell only
item main               Back to main menu
item reboot             Reboot

choose --default d_tp --timeout 15000 cz_target && goto ${cz_target}
goto start


:d_tp
set cz_image TP-v1.13
goto clonezilla_restore


:d_avc
set cz_image AVC-v1.13
goto clonezilla_restore


:d_dwlatm
set cz_image DW-LATM-v1.13
goto clonezilla_restore


:d_dw
set cz_image DW-v1.14
goto clonezilla_restore


:d_latm
set cz_image LATM-v1.13
goto clonezilla_restore


# ------------------------------------------------------------------
# Group D - Clonezilla shell mode
# ------------------------------------------------------------------

:d_clonezilla_shell
echo Booting Clonezilla shell mode...

imgfree

kernel ${clonezilla_d_kernel} initrd=initrd.img boot=live union=overlay username=user config components noeject noswap edd=on nomodeset locales=en_US.UTF-8 keyboard-layouts=NONE ip=dhcp net.ifnames=0 biosdevname=0 fetch=${clonezilla_d_squashfs} ocs_live_batch=no --- || goto clonezilla_failed
initrd --name initrd.img ${clonezilla_d_initrd} || goto clonezilla_failed

imgstat

boot || goto clonezilla_failed


# ------------------------------------------------------------------
# Group D - Clonezilla restore mode
# Disk is selected by /tmp/rutoll-auto-restore.sh.
# ------------------------------------------------------------------

:clonezilla_restore
echo Selected image: ${cz_image}
echo Target disk: auto, internal disk >= ${clonezilla_d_min_gb}GB
echo NFS repository: ${clonezilla_d_partimag_server}:${clonezilla_d_partimag_path}
echo Restore script: ${clonezilla_d_restore_script}
echo
echo WARNING: selected target disk will be overwritten after confirmation inside Clonezilla.

imgfree

kernel ${clonezilla_d_kernel} initrd=initrd.img boot=live union=overlay username=user config components noeject noswap edd=on nomodeset locales=en_US.UTF-8 keyboard-layouts=NONE ip=dhcp net.ifnames=0 biosdevname=0 fetch=${clonezilla_d_squashfs} ocs_prerun1="mkdir -p /home/partimag" ocs_prerun2="mount -t nfs -o ro,nolock ${clonezilla_d_partimag_server}:${clonezilla_d_partimag_path} /home/partimag" ocs_prerun3="wget -O /tmp/rutoll-auto-restore.sh ${clonezilla_d_restore_script}" ocs_prerun4="chmod +x /tmp/rutoll-auto-restore.sh" ocs_live_run="/tmp/rutoll-auto-restore.sh" ocs_live_batch=yes vga=788 nosplash rutoll_image=${cz_image} rutoll_min_gb=${clonezilla_d_min_gb} rutoll_target=auto rutoll_confirm=yes rutoll_allow_usb=no rutoll_allow_removable=no rutoll_dry_run=no --- || goto clonezilla_failed
initrd --name initrd.img ${clonezilla_d_initrd} || goto clonezilla_failed

imgstat

boot || goto clonezilla_failed


:clonezilla_failed
echo
echo ERROR: Clonezilla boot failed.
echo
echo Kernel: ${clonezilla_d_kernel}
echo Initrd: ${clonezilla_d_initrd}
echo SquashFS: ${clonezilla_d_squashfs}
echo NFS: ${clonezilla_d_partimag_server}:${clonezilla_d_partimag_path}
echo Restore script: ${clonezilla_d_restore_script}
echo
prompt Press any key to return to main menu...
goto start


# ------------------------------------------------------------------
# Tools
# ------------------------------------------------------------------

:main
goto start


:shell
shell


:reboot
reboot
