# By			: Nguyen Tu.
# Website		: https://www.aioboot.com/en/grub2-parttool-command/.
# Last modified	: 05.03.2018.
# Description	: Partition Tools - Active, inactive, hidden, unhide and delete partitions.

echo ${scanpartmessage}
set k="_"
for dev in (hd0,msdos*); do
	regexp -s device '\((.*)\)' $dev
	if ! searchindevice "$device"; then continue; fi
	probe -f -s fstype $device
	if [ -z "$fstype" ] -o [ "$fstype" == "procfs" ]; then continue; fi
	probe -s vollabel -l $device
	probe -s voluuid -u $device
	if [ -z "$vollabel" ]; then set vollabel="${noname}"; fi
	GetHotkey
	submenu "[${k}] ${device} - ${vollabel} - ${fstype} - ${voluuid}" $device --hotkey="${k}" {
		menuentry "[1] ${cancel}" --hotkey=1 {
			configfile ${prefix}/PartitionTool.cfg
		}
		menuentry "[2] ${active}" $2 --hotkey=2 {
			parttool ${2} boot+
		}
		menuentry "[3] ${inactive}" $2 --hotkey=3 {
			parttool ${2} boot-
		}
		menuentry "[4] ${hide}" $2 --hotkey=4 {
			parttool ${2} hidden+
		}
		menuentry "[5] ${unhide}" $2 --hotkey=5 {
			parttool ${2} hidden-
		}
		if [ x$2 != x$root ] -a [ -f ($2)/AIO/grub/grub.cfg ]; then
			menuentry "[6] ${setroot}" $2 --hotkey=6 {
				set root="${2}"
				set prefix="(${2})/AIO/grub"
				configfile $prefix/grub.cfg
			}
		fi
		if [ x$2 != x$root ]; then 
			menuentry "[7] ${delete}" $2 --hotkey=7 {
				parttool $2 type=0x00
				configfile ${prefix}/PartitionTool.cfg
			}
		fi
	}
	unset vollabel
	unset voluuid
	unset fstype
done
if [ -n "$pc" ]; then
menuentry "[x] ${backup} MBR [${press} x]" --hotkey=x {
	regexp -s disk 'hd(.*),' "$root"
	grub4dosroot
	set opt="debug off; root ${g4droot} > nul; /AIO/Tools/grub4dos/backupmbr.g4b ${disk} ${lang}"
	linux /AIO/Tools/grub4dos/grub.exe --config-file=${opt}
}
menuentry "[z] ${restore} MBR [${press} z]" --hotkey=z {
	regexp -s disk 'hd(.*),' "$root"
	grub4dosroot
	set opt="debug off; root ${g4droot} > nul; /AIO/Tools/grub4dos/restorembr.g4b ${disk} ${lang}"
	linux /AIO/Tools/grub4dos/grub.exe --config-file=${opt}
}
fi
source ${prefix}/ReturnMain.cfg