#------------------------------------------------------------------ # some common functions # #------------------------------------------------------------------ # function check_keys { for k in x x; do sleep 0.2 if keystatus --shift; then if [ -z "$enable_theme" ]; then set enable_theme="true" break fi if [ "$enable_theme" == "true" ]; then set enable_theme="false" break fi if [ "$enable_theme" == "false" ]; then set enable_theme="true" break fi fi if keystatus --ctrl; then set terminal="console" break fi done unset k } function set_default_entry { if [ "${grub_platform}" = "pc" ]; then set timeout="-1" fi if [ -n "$last_chosen" ]; then set default="$last_chosen" fi if [ -n "$kopts" ]; then set default="linux" else set default='language_keyboard_timezone' fi } function secure_boot { if [ "x$lockdown" = "xy" ]; then return 0 fi return 1 } function efi { if [ "${grub_platform}" = "efi" ]; then return 0 fi return 1 } function pc { if [ "${grub_platform}" = "pc" ]; then return 0 fi return 1 } # in_64_bit function in_64_bit { if [ "${grub_cpu}" = "x86_64" ]; then set in_64_bit=y export in_64_bit return 0 fi return 1 } function load_video_module_orig { if [ x$feature_all_video_module = xy ]; then insmod all_video else insmod vbe insmod vga insmod video_bochs insmod video_cirrus # insmod ieee1275_fb # insmod 915resolution fi if efi; then insmod efi_gop insmod efi_uga fi } function load_video_module { if [ x$feature_all_video_module = xy ]; then insmod all_video else if efi; then insmod efi_gop insmod efi_uga fi insmod ieee1275_fb insmod vbe insmod vga insmod video_bochs insmod video_cirrus fi } function load_theme_fonts { export fonts_loaded if [ x"$fonts_loaded" = x"true" ]; then return; fi if [ x$feature_default_font_path = xy ] ; then font=unicode else if [ -f $prefix/boot/grub/fonts/unicode.pf2 ]; then font=$prefix/boot/grub/fonts/unicode.pf2 fi fi if loadfont $font ; then set gfxmode=1024x768 load_video_module insmod gfxterm fonts_loaded=true fi if secure_boot; then return; fi for font in font.pf2 7x13.pf2 dejavu-sans-14.pf2 dejavu-sans-16.pf2; do if [ -f $prefix/fonts/$font ]; then loadfont $prefix/fonts/$font fonts_loaded=true fi done unset font } function load_gfxterm_fonts { export fonts_loaded if [ x"$fonts_loaded" = x"true" ]; then return; fi if [ -f $prefix/fonts/unicode.pf2 ]; then if loadfont $prefix/fonts/unicode.pf2; then fonts_loaded=true fi fi } function load_images { insmod jpeg insmod png } function load_locale { insmod gettext set locale_dir="$prefix/locale" set secondary_locale_dir="$prefix/config/locale" export locale_dir export secondary_locale_dir } function getdrive { getdrive="$2" if regexp -s tmp '^\((.*)\).*' "$getdrive"; then getdrive="$tmp" fi if regexp -s tmp '^(.*),.*' "$getdrive"; then getdrive="$tmp" fi $1="$getdrive" unset tmp export $1 } function main_menu { set root="$boot_root" set prefix="$boot_prefix" set_theme configfile $boot_prefix/grub.cfg } function back_to_main_menu { menuentry "<=== "$"Back to main menu (or press »ESC«)" --hotkey=Q --class=cancel { main_menu } } function menu_reload { l10n=true main_menu } function switch_to_syslinux { if [ "${root}" = "loop" ]; then return; fi if [ "${grub_platform}" = "efi" ]; then return; fi if [ -e /boot/isolinux/isolinux.bin ]; then menuentry " "$"Switch to Syslinux" "$root" { insmod chain set root=($2) if regexp '^cd' "${root}"; then reboot; fi unset theme terminal_output console terminal_output gfxterm chainloader +1 /boot/isolinux/isolinux.bin } elif [ -e /boot/syslinux/syslinux.bin ]; then menuentry " "$"Switch to Syslinux" "$root" { insmod chain set root=($2) if regexp '^cd' "${root}"; then reboot; fi unset theme terminal_output console terminal_output gfxterm chainloader +1 /boot/syslinux/syslinux.bin } fi } function set_kopts { # check iso_path kopts="" if [ -n "$iso_path" ]; then if [ -z "$isobuuid" ]; then search --no-floppy --file --set=isoroot $iso_path probe -u $isoroot --set=isobuuid export isobuuid fi kopts="${kopts}buuid=$isobuuid " kopts="${kopts}fromiso=$iso_path " fi #l10n lopts="" export lopts if [ -z "$blang" ]; then lang=en else lopts="${lopts}lang=$blang " lang=$blang KEYMAP_SHORT="enter: boot, `e': options, `c': cmd-line" if [ "$KEYMAP_SHORT" = $"enter: boot, `e': options, `c': cmd-line" ]; then lang=en export lang fi fi export lang export blang # eval won't work in secure boot export kbd ; if [ -n "$kbd" ]; then lopts="${lopts}kbd=$kbd "; fi export kbvar ; if [ -n "$kbvar" ]; then lopts="${lopts}kbvar=$kbvar "; fi export kbopt ; if [ -n "$kbopt" ]; then lopts="${lopts}kbopt=$kbopt "; fi export tz ; if [ -n "$tz" ]; then lopts="${lopts}tz=$tz "; fi kopts="${kopts}$lopts" if [ -n "$blabel" ]; then blab="$blabel"; elif [ -n "$bootlabel" ]; then blab="$bootlabel"; fi if [ -n "$blab" ]; then export blab; kopts="${kopts}blab=$blab "; fi if [ -n "$bootdev" ]; then bdev="$bootdev"; fi if [ -n "$bdev" ]; then export bdev; kopts="${kopts}bdev=$bdev "; fi if [ -n "$bootuuid" ]; then buuid="$bootuuid"; fi if [ -n "$buuid" ]; then export buuid; kopts="${kopts}buuid=$buuid "; fi if [ -n "$bootdir" ]; then bdir="$bootdir"; fi if [ -n "$bdir" ]; then export bdir; kopts="${kopts}bdir=$bdir "; fi if [ -n "$btry" ]; then export btry; kopts="${kopts}btry=$btry "; fi if [ -n "$flab" ]; then export flab ; kopts="${kopts}flab=$flab "; fi if [ -n "$fuuid" ]; then export fuuid; kopts="${kopts}fuuid=$fuuid "; fi if [ -n "$fdir" ]; then export fdir ; kopts="${kopts}fdir=$fdir "; fi if [ -n "$fdev" ]; then export fdev ; kopts="${kopts}$fdev "; fi if [ -n "$ftry" ]; then export ftry ; kopts="${kopts}$ftry "; fi if [ -n "$plabel" ]; then plab="$plabel"; elif [ -n "$persistlabel" ]; then plab="$persistlabel"; fi if [ -n "$plab" ]; then export plab; kopts="${kopts}plab=$plab "; fi if [ -n "$persistdev" ]; then pdev="$persistdev"; fi if [ -n "$pdev" ]; then export pdev; kopts="${kopts}pdev=$pdev "; fi if [ -n "$persistuuid" ]; then puuid="$persistuuid"; fi if [ -n "$puuid" ]; then export puuid; kopts="${kopts}puuid=$puuid "; fi if [ -n "$persistdir" ]; then pdir="$persistdir"; fi if [ -n "$pdir" ]; then export pdir; kopts="${kopts}pdir=$pdir "; fi if [ -n "$ptry" ]; then export ptry; kopts="${kopts}ptry=$ptry "; fi export persistence ; if [ -n "$persistence" ]; then kopts="${kopts}$persistence "; fi export menus ; if [ -n "$menus" ]; then kopts="${kopts}$menus "; fi export check ; if [ -n "$check" ]; then kopts="${kopts}$check "; fi export toram ; if [ -n "$toram" ]; then kopts="${kopts}$toram "; fi export from ; if [ -n "$from" ]; then kopts="${kopts}$from "; fi export nousb2 ; if [ -n "$nousb2" ]; then kopts="${kopts}$nousb2 "; fi export automount ; if [ -n "$automount" ]; then kopts="${kopts}$automount "; fi export acpi ; if [ -n "$acpi" ]; then kopts="${kopts}$acpi "; fi export invert ; if [ -n "$invert" ]; then kopts="${kopts}$invert "; fi export hwclock ; if [ -n "$hwclock" ]; then kopts="${kopts}$hwclock "; fi export password ; if [ -n "$password" ]; then kopts="${kopts}$password "; fi export vcard ; if [ -n "$vcard" ]; then kopts="${kopts}$vcard "; fi export norepo ; if [ -n "$norepo" ]; then kopts="${kopts}$norepo "; fi export noremaster ; if [ -n "$noremaster" ]; then kopts="${kopts}noremaster "; fi export rollback ; if [ -n "$rollback" ]; then kopts="${kopts}rollback "; fi export store ; if [ -n "$store" ]; then kopts="${kopts}$store "; fi export savestate ; if [ -n "$savestate" ]; then kopts="${kopts}$savestate "; fi export save ; if [ -n "$save" ]; then kopts="${kopts}$save "; fi export live_swap ; if [ -n "$live_swap" ]; then kopts="${kopts}$live_swap "; fi export splasht ; if [ -n "$splasht" ]; then kopts="${kopts}$splasht "; fi export failsafe ; if [ -n "$failsafe" ]; then kopts="${kopts}$failsafe "; fi export efi ; if [ -n "$efi" ]; then kopts="${kopts}$efi "; fi #export vga ; if [ -n "$vga" ]; then kopts="${kopts}vga=$vga "; fi export video ; if [ -n "$video" ]; then kopts="${kopts}video=$video "; fi if [ -n "$disable_theme" ]; then export disable_theme; kopts="${kopts}disable_theme "; fi if [ -n "$disable_background" ]; then export disable_background; kopts="${kopts}disable_background "; fi # desktop options export desktop ; if [ -n "$desktop" ]; then kopts="${kopts}$desktop "; fi export desktheme; if [ -n "$desktheme" ]; then kopts="${kopts}$desktheme "; fi export fontsize; if [ -n "$fontsize" ]; then kopts="${kopts}$fontsize "; fi # kernel opts if [ -n "$kernel" -a "$kernel" != "vmlinuz" ]; then if [ -n "$save" ]; then kopts="${kopts}kernel=$kernel " fi fi export bootchart; if [ -n "$bootchart" ]; then kopts="${kopts}bootchart initcall_debug printk.time=y "; fi #xopts="check toram from nousb2 automount acpi invert hwclock" #xopts="$xopts password vcard conwidth norepo store savestate" #xopts="$xopts bootchart live_swap splasht" export export extra; if [ -n "$extra" ]; then kopts="${kopts}$extra "; fi } function options_menu_reload { if [ -n "$1" ]; then default=$1 export default fi configfile /boot/grub/config/options_menu.cfg } function l10n_menu_reload { export default default=4 lang=$blang # check we have translations of KEYMAP_SHORT # using internal KEYMAP_SHORT string "enter: boot, `e': options, `c': cmd-line" # which shall be converted using themes internal gettext translations KEYMAP_SHORT="enter: boot, `e': options, `c': cmd-line" if [ "$KEYMAP_SHORT" = $"enter: boot, `e': options, `c': cmd-line" ]; then lang=en fi configfile /boot/grub/config/l10n_menu.cfg } function l10n_reset { blang= lang= slang= kbd= kbvar= tz= } function toggle { x="$1" y="$2" if [ -z "$x" -o -z "$y" ]; then return; fi if secure_boot; then if [ "$x" != "fdev" -a "$x" != "remaster" -a "$x" != "rollback" ]; then toggle_sb "$x" "$y" return fi fi if [ "$x" == "fdev" ]; then v="$fdev" if [ -z "$v" -o "$v" != "$y" ]; then fdev="$y" if [ "$y" == "fdev=ask" -o "$y" == "fdev=select" ]; then ftry="ftry=0" fi else fdev="" if [ -n "$ftry" -a "$ftry" == "ftry=0" ]; then ftry="" fi fi; export fdev export ftry elif [ "$x" == "rollback" ]; then v="$rollback" if [ -z "$v" -o "$v" != "$y" ]; then rollback="$y" else rollback="" fi; noremaster="" export rollback export noremaster elif [ "$x" == "noremaster" ]; then v="$rollback" if [ -z "$v" -o "$v" != "$y" ]; then noremaster="$y" else noremaster="" fi; rollback="" export rollback export noremaster else eval v='"$'$x'"' if [ -z "$v" -o "$v" != "$y" ]; then eval $x="'$y'" else eval $x= fi fi unset v unset x unset y } function toggle_sb { x="$1" y="$2" if [ "$x" == "persistence" ]; then v="$persistence";if [ -z "$v" -o "$v" != "$y" ]; then persistence="$y" ; else persistence=""; fi; export persistence; elif [ "$x" == "menus" ]; then v="$menus"; if [ -z "$v" -o "$v" != "$y" ]; then menus="$y" ; else menus=""; fi; export menus ; elif [ "$x" == "check" ]; then v="$check"; if [ -z "$v" -o "$v" != "$y" ]; then check="$y" ; else check=""; fi; export check ; elif [ "$x" == "toram" ]; then v="$toram"; if [ -z "$v" -o "$v" != "$y" ]; then toram="$y" ; else toram=""; fi; export toram ; elif [ "$x" == "invert" ]; then v="$invert"; if [ -z "$v" -o "$v" != "$y" ]; then invert="$y" ; else invert=""; fi; export invert ; elif [ "$x" == "from" ]; then v="$from"; if [ -z "$v" -o "$v" != "$y" ]; then from="$y" ; else from=""; fi; export from ; elif [ "$x" == "hwclock" ]; then v="$hwclock"; if [ -z "$v" -o "$v" != "$y" ]; then hwclock="$y" ; else hwclock=""; fi; export hwclock ; elif [ "$x" == "password" ]; then v="$password"; if [ -z "$v" -o "$v" != "$y" ]; then password="$y" ; else password=""; fi; export password ; elif [ "$x" == "norepo" ]; then v="$norepo"; if [ -z "$v" -o "$v" != "$y" ]; then norepo="$y" ; else norepo=""; fi; export norepo ; elif [ "$x" == "splasht" ]; then v="$splasht"; if [ -z "$v" -o "$v" != "$y" ]; then splasht="$y" ; else splasht=""; fi; export splasht ; elif [ "$x" == "store" ]; then v="$store"; if [ -z "$v" -o "$v" != "$y" ]; then store="$y" ; else store=""; fi; export store ; elif [ "$x" == "savestate" ]; then v="$savestate"; if [ -z "$v" -o "$v" != "$y" ]; then savestate="$y" ; else savestate=""; fi; export savestate ; elif [ "$x" == "failsafe" ]; then v="$failsafe"; if [ -z "$v" -o "$v" != "$y" ]; then failsafe="$y" ; else failsafe=""; fi; export failsafe ; elif [ "$x" == "video" ]; then v="$video"; if [ -z "$v" -o "$v" != "$y" ]; then video="$y" ; else video=""; fi; export video ; elif [ "$x" == "vga" ]; then v="$vga"; if [ -z "$v" -o "$v" != "$y" ]; then vga="$y" ; else vga=""; fi; export vga ; elif [ "$x" == "save" ]; then v="$save"; if [ -z "$v" -o "$v" != "$y" ]; then save="$y" ; else save=""; fi; export save ; elif [ "$x" == "nousb2" ]; then v="$nousb2"; if [ -z "$v" -o "$v" != "$y" ]; then nousb2="$y" ; else nousb2=""; fi; export nousb2 ; elif [ "$x" == "automount" ]; then v="$automount"; if [ -z "$v" -o "$v" != "$y" ]; then automount="$y" ; else automount=""; fi; export automount ; elif [ "$x" == "acpi" ]; then v="$acpi"; if [ -z "$v" -o "$v" != "$y" ]; then acpi="$y" ; else acpi=""; fi; export acpi ; elif [ "$x" == "vcard" ]; then v="$vcard"; if [ -z "$v" -o "$v" != "$y" ]; then vcard="$y" ; else vcard=""; fi; export vcard ; elif [ "$x" == "conwidth" ]; then v="$conwidth"; if [ -z "$v" -o "$v" != "$y" ]; then conwidth="$y" ; else conwidth=""; fi; export conwidth ; elif [ "$x" == "bootchart" ]; then v="$bootchart"; if [ -z "$v" -o "$v" != "$y" ]; then bootchart="$y" ; else bootchart=""; fi; export bootchart ; elif [ "$x" == "live_swap" ]; then v="$live_swap"; if [ -z "$v" -o "$v" != "$y" ]; then live_swap="$y" ; else live_swap=""; fi; export live_swap ; elif [ "$x" == "efi" ]; then v="$efi"; if [ -z "$v" -o "$v" != "$y" ]; then efi="$y" ; else efi=""; fi; export efi ; fi unset v unset x unset y } function toggle_kernel { if [ -z "$1" -o "$x" = "vmlinuz1" ]; then set_kernel "vmlinuz" elif [ "$1" = "vmlinuz1" ]; then set_kernel "vmlinuz" fi } function set_kernel { kernel="$1" kernel_label="" kernel_version="" kernel_bdir="/antiX" if [ -z "$kernel" ]; then kernel="vmlinuz"; fi set_initrd="" for n in "" 1 2 3 4 5 6 7 8 9; do if [ "$kernel" = "vmlinuz"${n} ]; then if [ -f "$kernel_bdir/initrd${n}.gz" ]; then set_initrd=initrd${n} fi break fi done if [ -n "$set_initrd" ]; then initrd="$set_initrd" else initrd="initrd" fi if [ "$kernel" = "vmlinuz" ]; then kernel_label="$kernel_label_0" kernel_version="$kernel_version_0" elif [ "$kernel" = "vmlinuz1" ]; then kernel_label="$kernel_label_1" kernel_version="$kernel_version_1" fi if [ -f "$kernel_bdir/${kernel}.ver" ]; then KERNEL_VERSION="" KERNEL_LABEL="" source "$kernel_bdir/${kernel}.ver" if [ -n "$KERNEL_VERSION" ]; then kernel_version="$KERNEL_VERSION" fi if [ -n "$KERNEL_LABEL" ]; then kernel_label="$KERNEL_LABEL" fi unset KERNEL_VERSION unset KERNEL_LABEL fi unset kernel_bdir export kernel export initrd export kernel_label export kernel_version } # functions to check enabled or disabled options function is_disabled { is_disabled_x="$1" if [ -z "$disabled_options" ]; then return 1; fi for is_disabled_y in $disabled_options; do if [ "$is_disabled_y" = "$is_disabled_x" ]; then # is disabled unset is_disabled_x unset is_disabled_y return 0 fi done unset is_disabled_x unset is_disabled_y # is not disabled return 1 } function is_enabled { if is_disabled "$1"; then # is not enabled return 1 else # is enabled return 0 fi }