set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
set grub_draw_border=1
set gfxmode=auto
set midx=x
set sidx=x
set wimbootfiles=x
set hdd=hd1

#declar functie increment
#folosesc menuindex si submenuindex ca hotkey si ma opresc la d daca apas e imi face edit ci nu lanseaza meniul,oricum pe 1024x786 nu vad mai mult de 14 linii
function mincrement {
    if [ x$midx == xx ]; then midx=1; elif [ x$midx == x1 ]; then midx=2; elif [ x$midx == x2 ]; then midx=3; elif [ x$midx == x3 ]; then midx=4; elif [ x$midx == x4 ]; then midx=5; elif [ x$midx == x5 ]; then midx=6; elif [ x$midx == x6 ]; then midx=7; elif [ x$midx == x7 ]; then midx=8; elif [ x$midx == x8 ]; then midx=9; elif [ x$midx == x9 ]; then midx=0; elif [ x$midx == x0 ]; then midx=a; elif [ x$midx == xa ]; then midx=b; elif [ x$midx == xb ]; then midx=c; elif [ x$midx == xc ]; then midx=d; else midx=x; fi
}

function sincrement {
    if [ x$sidx == xx ]; then sidx=1; elif [ x$sidx == x1 ]; then sidx=2; elif [ x$sidx == x2 ]; then sidx=3; elif [ x$sidx == x3 ]; then sidx=4; elif [ x$sidx == x4 ]; then sidx=5; elif [ x$sidx == x5 ]; then sidx=6; elif [ x$sidx == x6 ]; then sidx=7; elif [ x$sidx == x7 ]; then sidx=8; elif [ x$sidx == x8 ]; then sidx=9; elif [ x$sidx == x9 ]; then sidx=0; elif [ x$sidx == x0 ]; then sidx=a; elif [ x$sidx == xa ]; then sidx=b; elif [ x$sidx == xb ]; then sidx=c; elif [ x$sidx == xc ]; then sidx=d; else sidx=x; fi
}

mincrement
menuentry $midx'. HBCD152 syslinux Menu' --hotkey=$midx {
    root=$rootfat
    chainloader +1
}

if [ -f "($rootfat)/boot/memtest86+.bin" ]; then
    mincrement
    menuentry $midx'. Memtest86+ ' --hotkey=$midx {
        linux16 ($rootfat)/boot/memtest86+.bin
    }
fi
if [ -f "($rootfat)/boot/hdt-052.img" ]; then
    mincrement
    menuentry $midx'. Hardware Detection Tool (HDT) version 0.5.2 (Manon) img memdisk' --hotkey=$midx {
        linux16 ($rootfat)/boot/memdisk raw
        initrd16 ($rootfat)/boot/hdt-052.img
    }
fi
mincrement
menuentry $midx'. HBCD Programs Dos Boot Menu memdisk' --hotkey=$midx {
        linux16 ($rootfat)/boot/memdisk
        initrd16 ($rootfat)/HBCD/Dos/dos.gz
}
#
if [ -f "($rootfat)/bootmgr" ]; then
    wimbootfiles=m$wimbootfiles
#   va da eroare la BCD
#    mincrement
#    menuentry $midx'. Bootmgr from HBCD152 for MiniWindows7' --hotkey=$midx {
#        root=$rootfat
#        ntldr /bootmgr
#    }
fi
if [ -f "($rootfat)/boot/bcdexe" ]; then wimbootfiles=b$wimbootfiles; fi
if [ -f "($rootfat)/boot/boot.sdi" ]; then wimbootfiles=s$wimbootfiles; fi
if [ -f "($rootfat)/boot/wimboot" ]; then wimbootfiles=k$wimbootfiles; fi
if [ x$wimbootfiles == xksbmx ];then
    mincrement
    submenu $midx'. Wimboot to load Windows >' --hotkey=$midx {
        sidx=x
        if [ -d  "($rootfat)/HBCD/7" ]; then
            sincrement
            menuentry $sidx'. MiniWindows 7 HBCD' --hotkey=$sidx {
                root=$rootfat
                echo load wimboot
                linux16 /boot/wimboot
                echo load images of bcd,boot.sdi,7.wim from HBCD
                initrd16 \
                    newc:boot.sdi:/HBCD/7/7D \
                    newc:BCD:/boot/bcdexe \
                    newc:bootmgr:/bootmgr \
                    newc:boot.wim:/HBCD/7/7.wim
            }
        fi
        if [ -f  "($rootfat)/boot/winpe7x86.wim" ]; then
            sincrement
            menuentry $sidx'. WindowsPE 7 x86' --hotkey=$sidx {
                root=$rootfat
                echo load wimboot
                linux16 /boot/wimboot
                echo load images of bcd,boot.sdi,winpe7x86 from boot
                initrd16 \
                    newc:boot.sdi:/boot/boot.sdi \
                    newc:BCD:/boot/bcdexe \
                    newc:boot.wim:/boot/winpe7x86.wim
            }
        fi
        if [ -f  "($rootfat)/boot/dart7x86.wim" ]; then
            sincrement
            menuentry $sidx'. DaRT 7 x86' --hotkey=$sidx {
                root=$rootfat
                echo load wimboot
                linux16 /boot/wimboot
                echo load images of bcd,boot.sdi,dart7x86 from boot
                initrd16 \
                    newc:boot.sdi:/boot/boot.sdi \
                    newc:BCD:/boot/bcdexe \
                    newc:boot.wim:/boot/dart7x86.wim

                if [ -s "($hdd)" ]; then drivemap -s hd0 $hdd ; fi
            }
        fi
        if [ -f  "($rootfat)/win7x86/sources/setup.exe" ]; then
            sincrement
            menuentry $sidx'. Windows 7 Setup x86 from win7x86' --hotkey=$sidx {
                root=$rootfat
                echo load wimboot
                linux16 /boot/wimboot
                echo load images of bcdexe,boot.sdi,winpe7x86.wim from boot and start setup from win7x86
                initrd16 \
                    newc:setup.bat:/boot/setup7x86.bat \
                    newc:winpeshl.ini:/boot/winpeshl.ini \
                    newc:boot.sdi:/boot/boot.sdi \
                    newc:BCD:/boot/bcdexe \
                    newc:boot.wim:/boot/winpe7x86.wim

                if [ -s "($hdd)" ]; then drivemap -s hd0 $hdd ; fi
            }
        fi
    }
fi
if [ -d  "($rootfat)/HBCD/Boot/pmagic" ]; then
    mincrement
    menuentry $midx'. Parted Magic Linux 2012' --hotkey=$midx {
        root=$rootfat
        echo load kernel
        linux /HBCD/Boot/pmagic/bzImage edd=off load_ramdisk=1 prompt_ramdisk=0 rw loglevel=9 max_loop=256 vmalloc=256MiB directory=/HBCD/Boot
        echo load initrd
        initrd /HBCD/Boot/pmagic/initrd.img
        echo done,boot
    }
fi
if [ -d  "($rootfat)/mint" ]; then
    mincrement
    submenu $midx'. Linux Mint >' --hotkey=$midx {
        sidx=x
        if [ -d  "($rootfat)/mint/193" ]; then
            sincrement
            menuentry $sidx'. Linux Mint 19.3 "Tricia" - Release i386' --hotkey=$sidx {
                root=$rootfat
                probe -u $root --set=devuuid
                echo UUID=$devuuid
                set gfxpayload=keep
                echo load kernel
                linux /mint/193/casper/vmlinuz  file=/cdrom/mint/193/preseed/linuxmint.seed boot=casper uuid=$devuuid live-media=/dev/disk/by-uuid/$devuuid live-media-path=/mint/193/casper net.ifnames=0 ro nopersistent --
                echo load initrd
                initrd /mint/193/casper/initrd.lz
            }
        fi
    }
fi
if [ -d  "($rootfat)/ubuntu" ]; then
    mincrement
    submenu $midx'. Ubuntu >' --hotkey=$midx {
        sidx=x
        if [ -d  "($rootfat)/ubuntu/1606" ]; then
            sincrement
            menuentry $sidx'. Ubuntu 16.04.6 LTS "Xenial Xerus" - Release i386' --hotkey=$sidx {
                root=$rootfat
                probe -u $root --set=devuuid
                echo UUID=$devuuid
                set gfxpayload=keep
                echo load kernel
                linux /ubuntu/1606/casper/vmlinuz file=/cdrom/ubuntu/1606/preseed/ubuntu.seed boot=casper uuid=$devuuid live-media=/dev/disk/by-uuid/$devuuid live-media-path=/ubuntu/1606/casper net.ifnames=0 ro nopersistent --
                echo load initrd
                initrd /ubuntu/1606/casper/initrd
            }
        fi
    }
fi