Advertisement
kachunkachunk

Manjaro 17/04's Grub2 auto-loading of razer_acpi_fix.img

Apr 30th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 33.83 KB | None | 0 0
  1. #! /bin/sh
  2. set -e
  3.  
  4. # grub-mkconfig helper script.
  5. # Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
  6. #
  7. # GRUB is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # GRUB is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. prefix="/usr"
  21. exec_prefix="/usr"
  22. datarootdir="/usr/share"
  23.                                                                                                                                                                                                                                                                                                                                                                        
  24. . "$pkgdatadir/grub-mkconfig_lib"                                                                                                                                                                                                                                                                                                                                      
  25.                                                                                                                                                                                                                                                                                                                                                                        
  26. export TEXTDOMAIN=grub                                                                                                                                                                                                                                                                                                                                                
  27. export TEXTDOMAINDIR="${datarootdir}/locale"                                                                                                                                                                                                                                                                                                                          
  28.                                                                                                                                                                                                                                                                                                                                                                        
  29. CLASS="--class gnu-linux --class gnu --class os"                                                                                                                                                                                                                                                                                                                      
  30.                                                                                                                                                                                                                                                                                                                                                                        
  31. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then                                                                                                                                                                                                                                                                                                                            
  32.   OS=Linux                                                                                                                                                                                                                                                                                                                                                            
  33. else                                                                                                                                                                                                                                                                                                                                                                  
  34.   OS="${GRUB_DISTRIBUTOR} Linux"                                                                                                                                                                                                                                                                                                                                      
  35.   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"                                                                                                                                                                                                                                            
  36. fi                                                                                                                                                                                                                                                                                                                                                                    
  37.                                                                                                                                                                                                                                                                                                                                                                        
  38. # loop-AES arranges things so that /dev/loop/X can be our root device, but                                                                                                                                                                                                                                                                                            
  39. # the initrds that Linux uses don't like that.                                                                                                                                                                                                                                                                                                                        
  40. case ${GRUB_DEVICE} in                                                                                                                                                                                                                                                                                                                                                
  41.   /dev/loop/*|/dev/loop[0-9])                                                                                                                                                                                                                                                                                                                                          
  42.     GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`                                                                                                                                                                                                                                                                                        
  43.   ;;                                                                                                                                                                                                                                                                                                                                                                  
  44. esac                                                                                                                                                                                                                                                                                                                                                                  
  45.                                                                                                                                                                                                                                                                                                                                                                        
  46. # btrfs may reside on multiple devices. We cannot pass them as value of root= parameter                                                                                                                                                                                                                                                                                
  47. # and mounting btrfs requires user space scanning, so force UUID in this case.                                                                                                                                                                                                                                                                                        
  48. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \                                                                                                                                                                                                                                                                                  
  49.     || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \                                                                                                                                                                                                                                                                                                            
  50.     || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then                                                                                                                                                                                                                                                                                    
  51.   LINUX_ROOT_DEVICE=${GRUB_DEVICE}                                                                                                                                                                                                                                                                                                                                    
  52. else                                                                                                                                                                                                                                                                                                                                                                  
  53.   LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}                                                                                                                                                                                                                                                                                                                          
  54. fi                                                                                                                                                                                                                                                                                                                                                                    
  55.                                                                                                                                                                                                                                                                                                                                                                        
  56. case x"$GRUB_FS" in                                                                                                                                                                                                                                                                                                                                                    
  57.     xbtrfs)                                                                                                                                                                                                                                                                                                                                                            
  58.         rootsubvol="`make_system_path_relative_to_its_root /`"                                                                                                                                                                                                                                                                                                        
  59.         rootsubvol="${rootsubvol#/}"                                                                                                                                                                                                                                                                                                                                  
  60.         if [ "x${rootsubvol}" != x ]; then                                                                                                                                                                                                                                                                                                                            
  61.             GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"                                                                                                                                                                                                                                                                                  
  62.         fi;;                                                                                                                                                                                                                                                                                                                                                          
  63.     xzfs)                                                                                                                                                                                                                                                                                                                                                              
  64.         rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`                                                                                                                                                                                                                                                                            
  65.         bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"                                                                                                                                                                                                                                                                                          
  66.         LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"                                                                                                                                                                                                                                                                                                                      
  67.         ;;                                                                                                                                                                                                                                                                                                                                                            
  68. esac                                                                                                                                                                                                                                                                                                                                                                  
  69.                                                                                                                                                                                                                                                                                                                                                                        
  70. intel_ucode=                                                                                                                                                                                                                                                                                                                                                          
  71. if test -e "/boot/intel-ucode.img" ; then                                                                                                                                                                                                                                                                                                                              
  72.     gettext_printf "Found Intel Microcode image\n" >&2                                                                                                                                                                                                                                                                                                                
  73.     intel_ucode="$(make_system_path_relative_to_its_root /boot/intel-ucode.img)"                                                                                                                                                                                                                                                                                      
  74. fi                                                                                                                                                                                                                                                                                                                                                                    
  75.                                                                                                                                                                                                                                                                                                                                                                        
  76. title_correction_code=                                                                                                                                                                                                                                                                                                                                                
  77.                                                                                                                                                                                                                                                                                                                                                                        
  78. linux_entry ()                                                                                                                                                                                                                                                                                                                                                        
  79. {                                                                                                                                                                                                                                                                                                                                                                      
  80.   os="$1"                                                                                                                                                                                                                                                                                                                                                              
  81.   version="$2"                                                                                                                                                                                                                                                                                                                                                        
  82.   type="$3"                                                                                                                                                                                                                                                                                                                                                            
  83.   args="$4"                                                                                                                                                                                                                                                                                                                                                            
  84.                                                                                                                                                                                                                                                                                                                                                                        
  85.   if [ -z "$boot_device_id" ]; then                                                                                                                                                                                                                                                                                                                                    
  86.       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"                                                                                                                                                                                                                                                                                                          
  87.   fi                                                                                                                                                                                                                                                                                                                                                                  
  88.   if [ x$type != xsimple ] ; then                                                                                                                                                                                                                                                                                                                                      
  89.       case $type in                                                                                                                                                                                                                                                                                                                                                    
  90.           recovery)                                                                                                                                                                                                                                                                                                                                                    
  91.               title="$(gettext_printf "%s (Kernel: %s - recovery mode)" "${os}" "${version}")" ;;                                                                                                                                                                                                                                                                      
  92.          fallback)                                                                                                                                                                                                                                                                                                                                                    
  93.              title="$(gettext_printf "%s (Kernel: %s - fallback initramfs)" "${os}" "${version}")" ;;
  94.          *)
  95.              title="$(gettext_printf "%s (Kernel: %s)" "${os}" "${version}")" ;;
  96.      esac
  97.      if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  98.          replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  99.          quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  100.          title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  101.          grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
  102.      fi
  103.      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  104.  else
  105.      echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  106.  fi      
  107.  if [ x$type != xrecovery ] && [ x$type != xfallback ] ; then
  108.      save_default_entry | grub_add_tab
  109.  fi
  110.  
  111.  # Use ELILO's generic "efifb" when it's known to be available.
  112.  # FIXME: We need an interface to select vesafb in case efifb can't be used.
  113.  if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
  114.      echo "    load_video" | sed "s/^/$submenu_indentation/"
  115.      if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
  116.          && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
  117.          echo "        set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
  118.      fi
  119.  else
  120.      if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
  121.          echo "        load_video" | sed "s/^/$submenu_indentation/"
  122.      fi
  123.      echo "    set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
  124.  fi
  125.  
  126.  echo "        insmod gzio" | sed "s/^/$submenu_indentation/"
  127.  
  128.  if [ x$dirname = x/ ]; then
  129.    if [ -z "${prepare_root_cache}" ]; then
  130.      prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
  131.    fi
  132.    printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
  133.  else
  134.    if [ -z "${prepare_boot_cache}" ]; then
  135.      prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
  136.    fi
  137.    printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  138.  fi
  139.  
  140.  message="$(gettext_printf "Loading Linux %s ..." "${version}")"
  141.  sed "s/^/$submenu_indentation/" << EOF
  142.        echo    '$(echo "$message" | grub_quote)'
  143.        linux   ${rel_dirname}/${basename} root=${linux_root_device_thisversion} rw ${args}
  144. EOF
  145.  if test -n "${initrd}" ; then
  146.    # TRANSLATORS: ramdisk isn't identifier. Should be translated.
  147.    message="$(gettext_printf "Loading initial ramdisk ...")"
  148.    sed "s/^/$submenu_indentation/" << EOF
  149.        echo    '$(echo "$message" | grub_quote)'
  150.        initrd  ${rel_dirname}/razer_acpi_fix.img ${intel_ucode} ${rel_dirname}/${initrd}
  151. EOF
  152.  fi
  153.  sed "s/^/$submenu_indentation/" << EOF
  154. }
  155. EOF
  156. }
  157.  
  158. machine=`uname -m`
  159. case "x$machine" in
  160.    xi?86 | xx86_64)
  161.        list=
  162.        for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
  163.            if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  164.        done ;;
  165.    *)
  166.        list=
  167.        for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
  168.                  if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  169.        done ;;
  170. esac
  171.  
  172. case "$machine" in
  173.    i?86) GENKERNEL_ARCH="x86" ;;
  174.    mips|mips64) GENKERNEL_ARCH="mips" ;;
  175.    mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
  176.    arm*) GENKERNEL_ARCH="arm" ;;
  177.    *) GENKERNEL_ARCH="$machine" ;;
  178. esac
  179.  
  180. prepare_boot_cache=
  181. prepare_root_cache=
  182. boot_device_id=
  183. title_correction_code=
  184.  
  185. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  186. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  187. submenu_indentation=""
  188.  
  189. is_top_level=true
  190. while [ "x$list" != "x" ] ; do
  191.  linux=`version_find_latest $list`
  192.  gettext_printf "Found linux image: %s\n" "$linux" >&2
  193.  basename=`basename $linux`
  194.  dirname=`dirname $linux`
  195.  rel_dirname=`make_system_path_relative_to_its_root $dirname`
  196.  version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  197.  alt_version=`echo $version | sed -e "s,\.old$,,g"`
  198.  linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  199.  
  200.  if test -e "/etc/manjaro-release" ; then
  201.    kbasename="`echo "${basename}" | sed -e 's,vmlinuz-,linux,g'`"
  202.    if test -e "${dirname}/${kbasename}.kver" ; then
  203.        version="$(cat ${dirname}/${kbasename}.kver)"
  204.    fi
  205.    kbasename2="`echo "${basename}" | sed -e 's,vmlinuz-,linux-,g'`"
  206.    if test -e "${dirname}/${kbasename2}.kver" ; then
  207.        version="$(cat ${dirname}/${kbasename2}.kver)"
  208.    fi
  209.    kbasename3="`echo "${basename}" | sed -e 's,vmlinuz-,linux,g' | sed -e 's,\.,,g'`"
  210.    if test -e "${dirname}/${kbasename3}.kver" ; then
  211.        version="$(cat ${dirname}/${kbasename3}.kver)"
  212.    fi
  213.    kbasename4="`echo "${basename}" | sed -e 's,vmlinuz-,linux-,g' | sed -e 's,\.,,g'`"
  214.    if test -e "${dirname}/${kbasename4}.kver" ; then
  215.        version="$(cat ${dirname}/${kbasename4}.kver)"
  216.    fi
  217.  fi
  218.  
  219.  initrd=
  220.  initramfs_manjaro="`echo "${basename}" | sed -e 's,vmlinuz,initramfs,g'`"
  221.  for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
  222.           "initrd-${version}" "initramfs-${version}.img" \
  223.           "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  224.           "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  225.           "initramfs-genkernel-${version}" \
  226.           "initramfs-genkernel-${alt_version}" \
  227.           "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
  228.           "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}" \
  229.           "${initramfs_manjaro}.img" ; do
  230.    if test -e "${dirname}/${i}" ; then
  231.      initrd="$i"
  232.      break
  233.    fi
  234.  done
  235.  
  236.  config=
  237.  for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  238.    if test -e "${i}" ; then
  239.      config="${i}"
  240.      break
  241.    fi
  242.  done
  243.  
  244.  initramfs=
  245.  if test -n "${config}" ; then
  246.      initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
  247.  fi
  248.  
  249.  if test -n "${initrd}" ; then
  250.    gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
  251.  elif test -z "${initramfs}" ; then
  252.    # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs.  Since there's
  253.    # no initrd or builtin initramfs, it can't work here.
  254.    linux_root_device_thisversion=${GRUB_DEVICE}
  255.  fi
  256.  
  257.  if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
  258.    linux_entry "${OS}" "${version}" simple \
  259.    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  260.  
  261.    submenu_indentation="$grub_tab"
  262.    
  263.    if [ -z "$boot_device_id" ]; then
  264.        boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  265.    fi
  266.    # TRANSLATORS: %s is replaced with an OS name
  267.    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
  268.    is_top_level=false
  269.  fi
  270.  
  271.  linux_entry "${OS}" "${version}" advanced \
  272.              "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  273.  
  274.  for i in "${initramfs_manjaro}-fallback.img" "initramfs-${version}-fallback.img" ; do
  275.    if test -e "${dirname}/${i}" ; then
  276.      initrd="${i}"
  277.      gettext_printf "Found initrd fallback image: %s\n" "${dirname}/${initrd}" >&2
  278.      linux_entry "${OS}" "${version}" fallback \
  279.                  "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  280.      break
  281.    fi
  282.  done
  283.  
  284.  if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  285.    linux_entry "${OS}" "${version}" recovery \
  286.                "single ${GRUB_CMDLINE_LINUX}"
  287.  fi
  288.  
  289.  list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
  290. done
  291.  
  292. # If at least one kernel was found, then we need to
  293. # add a closing '}' for the submenu command.
  294. if [ x"$is_top_level" != xtrue ]; then
  295.  echo '}'
  296. fi
  297.  
  298. echo "$title_correction_code"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement