OSDN Git Service

2020.05.10 update
[rebornos/cnchi-gnome-osdn.git] / Cnchi / 10_antergos
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 # Disable 10_linux
21
22 if [ -f /etc/grub.d/10_linux ]; then
23     chmod -x /etc/grub.d/10_linux
24 fi
25
26 # Disable 10_archlinux
27 if [ -f /etc/grub.d/10_archlinux ]; then
28     chmod -x /etc/grub.d/10_archlinux
29 fi
30
31 prefix="/usr"
32 exec_prefix="/usr"
33 datarootdir="/usr/share"
34
35 . "${datarootdir}/grub/grub-mkconfig_lib"
36
37 export TEXTDOMAIN=grub
38 export TEXTDOMAINDIR="${datarootdir}/locale"
39
40 CLASS="--class gnu-linux --class gnu --class os"
41
42 if [ "${GRUB_DISTRIBUTOR}" = "Antergos" ]; then
43   CLASS="--class arch ${CLASS}"
44 fi
45
46 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
47   OS=Linux
48 else
49   OS="RebornOS"
50   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
51 fi
52
53 # loop-AES arranges things so that /dev/loop/X can be our root device, but
54 # the initrds that Linux uses don't like that.
55 case ${GRUB_DEVICE} in
56   /dev/loop/*|/dev/loop[0-9])
57     GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
58   ;;
59 esac
60
61 if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
62     || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
63     || uses_abstraction "${GRUB_DEVICE}" lvm; then
64   LINUX_ROOT_DEVICE=${GRUB_DEVICE}
65 else
66   LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
67 fi
68
69 case x"$GRUB_FS" in
70     xbtrfs)
71         rootsubvol="`make_system_path_relative_to_its_root /`"
72         rootsubvol="${rootsubvol#/}"
73         if [ "x${rootsubvol}" != x ]; then
74             GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
75         fi;;
76     xzfs)
77         rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
78         bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
79         LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
80         ;;
81 esac
82
83 intel_ucode=
84 if test -e "/boot/intel-ucode.img" ; then
85     gettext_printf "Found Intel Microcode image\n" >&2
86     intel_ucode="$(make_system_path_relative_to_its_root /boot/intel-ucode.img)"
87 fi
88
89 title_correction_code=
90
91 linux_entry ()
92 {
93   os="$1"
94   version="$2"
95   type="$3"
96   args="$4"
97
98   if [ "$os" == "Antergos Linux" ] || [ "$os" == "Arch Linux" ] || [ "$os" == "Manjaro Linux" ] || [ "$os" == "RebornOS" ]; then
99       is_arch=True
100   fi
101
102   if [ -z "$boot_device_id" ]; then
103       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
104   fi
105   if [ x$type != xsimple ] && [ "$is_arch" != True ]; then
106       case $type in
107           recovery)
108               title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
109           fallback)
110           title="$(gettext_printf "RebornOS, with Linux %s (fallback initramfs)" "${os}" "${version}")" ;;
111           *)
112               title="$(gettext_printf "RebornOS, with %s Kernel" "${os}" "${version}")" ;;
113       esac
114       if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
115           replacement_title="$(echo "Advanced options for RebornOS" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
116           quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
117           title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
118           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")"
119       fi
120       echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
121   else
122         if [ "$is_arch" ]; then
123                 if [ x$type != xfallback ]; then
124                 if [ "$version" == "linux" ]; then
125                 title="$(gettext_printf "%s" "${os}")"
126                 elif [ "$version" == "linux-lts" ]; then
127                 title="$(gettext_printf "RebornOS LTS Kernel" "${os}")"
128                 else
129                 title="$(gettext_printf "RebornOS, with %s Kernel" "${os}" "${version}")"
130                 fi
131         else
132                         if [ "$version" == "linux" ]; then
133                 title="$(gettext_printf "RebornOS - Fallback" "${os}")"
134                 elif [ "$version" == "linux-lts" ]; then
135                 title="$(gettext_printf "RebornOS LTS Kernel - Fallback" "${os}")"
136                 else
137                 title="$(gettext_printf "RebornOS, with %s Kernel - Fallback" "${os}" "${version}")"
138                 fi
139         fi
140
141                 os="$title"
142         fi
143         echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
144   fi
145   if [ x$type != xrecovery ] && [ x$type != xfallback ] ; then
146       save_default_entry | grub_add_tab
147   fi
148
149   # Use ELILO's generic "efifb" when it's known to be available.
150   # FIXME: We need an interface to select vesafb in case efifb can't be used.
151   if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
152       echo "    load_video" | sed "s/^/$submenu_indentation/"
153       if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
154           && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
155           echo "        set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
156       fi
157   else
158       if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
159           echo "        load_video" | sed "s/^/$submenu_indentation/"
160       fi
161       echo "    set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
162   fi
163
164   echo "        insmod gzio" | sed "s/^/$submenu_indentation/"
165
166   if [ x$dirname = x/ ]; then
167     if [ -z "${prepare_root_cache}" ]; then
168       prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
169     fi
170     printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
171   else
172     if [ -z "${prepare_boot_cache}" ]; then
173       prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
174     fi
175     printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
176   fi
177   message="$(gettext_printf "Loading  %s kernel ..." ${version})"
178   sed "s/^/$submenu_indentation/" << EOF
179         echo    '$(echo "$message" | grub_quote)'
180         linux   ${rel_dirname}/${basename} root=${linux_root_device_thisversion} rw ${args}
181 EOF
182         if test -n "${initrd}" ; then
183                 if [ "$is_arch" ] && [ x$type = xfallback ] ; then
184                         initrd="initramfs-${version}-fallback.img"
185                 fi
186     # TRANSLATORS: ramdisk isn't identifier. Should be translated.
187         message="$(gettext_printf "Loading initial ramdisk ...")"
188         sed "s/^/$submenu_indentation/" << EOF
189         echo    '$(echo "$message" | grub_quote)'
190         initrd  ${intel_ucode} ${rel_dirname}/${initrd}
191 EOF
192         fi
193         sed "s/^/$submenu_indentation/" << EOF
194 }
195 EOF
196 }
197
198 machine=`uname -m`
199 case "x$machine" in
200     xi?86 | xx86_64)
201         list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
202                   if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
203               done` ;;
204     *)
205         list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
206                   if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
207              done` ;;
208 esac
209
210 case "$machine" in
211     i?86) GENKERNEL_ARCH="x86" ;;
212     mips|mips64) GENKERNEL_ARCH="mips" ;;
213     mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
214     arm*) GENKERNEL_ARCH="arm" ;;
215     *) GENKERNEL_ARCH="$machine" ;;
216 esac
217
218 prepare_boot_cache=
219 prepare_root_cache=
220 boot_device_id=
221 title_correction_code=
222
223 # Extra indentation to add to menu entries in a submenu. We're not in a submenu
224 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
225 submenu_indentation=""
226
227 is_top_level=true
228 while [ "x$list" != "x" ] ; do
229   if [ $(echo $list | grep -q '[0-9]') ]; then
230     linux=`version_find_latest $list`
231   else
232     artmp=($list)
233     linux=${artmp[0]}
234   fi
235
236   gettext_printf "Found linux image: %s\n" "$linux" >&2
237   basename=`basename $linux`
238   dirname=`dirname $linux`
239   rel_dirname=`make_system_path_relative_to_its_root $dirname`
240   version=`echo $basename | sed -e "s,vmlinuz-,,g"`
241   alt_version=`echo $version | sed -e "s,\.old$,,g"`
242   linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
243
244   initrd=
245   for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
246            "initrd-${version}" "initramfs-${version}.img" \
247            "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
248            "initrd-${alt_version}" "initramfs-${alt_version}.img" \
249            "initrd-linux-${version}" "initramfs-linux-${version}.img" \
250            "initrd-linux-${alt_version}" "initramfs-linux-${alt_version}.img" \
251            "initramfs-genkernel-${version}" \
252            "initramfs-genkernel-${alt_version}" \
253            "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
254            "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
255     if test -e "${dirname}/${i}" ; then
256       initrd="$i"
257       break
258     fi
259   done
260
261   config=
262   for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
263     if test -e "${i}" ; then
264       config="${i}"
265       break
266     fi
267   done
268
269   initramfs=
270   if test -n "${config}" ; then
271       initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
272   fi
273
274   if test -n "${initrd}" ; then
275     gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
276   elif test -z "${initramfs}" ; then
277     # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs.  Since there's
278     # no initrd or builtin initramfs, it can't work here.
279     linux_root_device_thisversion=${GRUB_DEVICE}
280   fi
281
282   # GRUB_DISABLE_SUBMENU=y is the documented value to disable the submenu, testing for true is for backwards compatibility with Antergos
283   # see https://wiki.archlinux.org/index.php/GRUB/Tips_and_tricks#Disable_submenu
284   if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
285     linux_entry "${OS}" "${version}" simple \
286     "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
287
288     submenu_indentation="$grub_tab"
289
290     if [ -z "$boot_device_id" ]; then
291         boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
292     fi
293     # TRANSLATORS: %s is replaced with an OS name
294     echo "submenu '$(gettext_printf "Advanced options for %s" "RebornOS" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
295     is_top_level=false
296   fi
297
298   linux_entry "${OS}" "${version}" advanced \
299               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
300   if test -e "${dirname}/initramfs-${version}-fallback.img" ; then
301       initrd="initramfs-${version}-fallback.img"
302
303       if test -n "${initrd}" ; then
304         gettext_printf "Found fallback initramfs image: %s\n" "${dirname}/${initrd}" >&2
305       fi
306
307       linux_entry "${OS}" "${version}" fallback \
308       "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
309   fi
310   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
311     linux_entry "${OS}" "${version}" recovery \
312                 "single ${GRUB_CMDLINE_LINUX}"
313   fi
314
315   list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
316 done
317
318 # If at least one kernel was found, then we need to
319 # add a closing '}' for the submenu command.
320 if [ x"$is_top_level" != xtrue ]; then
321   echo '}'
322 fi
323
324 echo "$title_correction_code"