1 # kboot-mkconfig helper script.
2 # Copyright (C) 2011 Antonio Ospite <ospite@studenti.unina.it>
4 # Inspired by the 10_linux script from kboot
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This progra, is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this software. If not, see <http://www.gnu.org/licenses/>.
21 bindir=${exec_prefix}/bin
22 libdir=${exec_prefix}/lib
24 LINUX_ROOT_DEVICE="$(readlink -f $(mount | grep ' / ' | cut -d ' ' -f 1))"
26 if $(which gettext >/dev/null 2>/dev/null) ; then
32 # One layer of quotation is eaten by "", the second by sed, and the third by
33 # printf; so this turns ' into \'. Note that you must use the output of
34 # this function in a printf format string.
36 $gettext "$@" | sed "s/'/'\\\\\\\\''/g"
39 # Run the first argument through gettext_quoted, and then pass that and all
40 # remaining arguments to printf. This is a useful abbreviation and tends to
45 printf "$(gettext_quoted "$format")" "$@"
48 kboot_file_is_not_garbage ()
50 if test -f "$1" ; then
52 *.dpkg-*) return 1 ;; # debian dpkg
53 README*) return 1 ;; # documentation
63 local sedexp="s/[^-]*-//;s/[._-]\(pre\|rc\|test\|git\|old\|trunk\)/~\1/g"
64 local a=`echo $1 | sed -e "$sedexp"`
65 local b=`echo $2 | sed -e "$sedexp"`
67 if [ "x$b" = "x" ] ; then
72 *.old:*) a=`echo -n $a | sed -e s/\.old$//` ; cmp=gt ;;
73 *:*.old) b=`echo -n $b | sed -e s/\.old$//` ; cmp=ge ;;
75 dpkg --compare-versions "$a" $cmp "$b"
79 version_find_latest ()
83 if version_test_gt "$i" "$a" ; then
97 title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
99 title="$(gettext_quoted "%s, with Linux %s")"
101 label="$(printf "${title}" "${os}" "${version}")"
102 echo -n "'${label}'='${dirname}/${basename} "
103 if test -n "${initrd}" ; then
104 echo -n "initrd=${dirname}/${initrd}"
106 echo " root=${linux_root_device_thisversion} ro ${args}'"
111 list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do
112 if kboot_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
116 while [ "x$list" != "x" ] ; do
117 linux=`version_find_latest $list`
118 echo "Found linux image: $linux" >&2
119 basename=`basename $linux`
120 dirname=`dirname $linux`
122 # XXX: this relies on a binary shipped by GRUB, we just use ${dirname} for
123 # now, check the ${dirname} entries if we need something like that later
124 #rel_dirname=`make_system_path_relative_to_its_root $dirname`
126 version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
127 alt_version=`echo $version | sed -e "s,\.old$,,g"`
128 linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
131 for i in "initrd.img-${version}" "initrd-${version}.img" \
132 "initrd-${version}" "initramfs-${version}.img" \
133 "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
134 "initrd-${alt_version}" "initramfs-${alt_version}.img"; do
135 if test -e "${dirname}/${i}" ; then
142 for i in "config-${version}" "config-${alt_version}"; do
143 if test -e "${dirname}/${i}" ; then
144 initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${dirname}/${i}" | cut -f2 -d= | tr -d \"`
149 if test -n "${initrd}" ; then
150 echo "Found initrd image: ${dirname}/${initrd}" >&2
151 elif test -z "${initramfs}" ; then
152 # "UUID=" magic is parsed by initrd or initramfs. Since there's
153 # no initrd or builtin initramfs, it can't work here.
154 linux_root_device_thisversion=${KBOOT_DEVICE}
157 linux_entry "${OS}" "${version}" false \
158 "${KBOOT_CMDLINE_LINUX} ${KBOOT_CMDLINE_LINUX_DEFAULT}"
159 if [ "x${KBOOT_DISABLE_RECOVERY}" != "xtrue" ]; then
160 linux_entry "${OS}" "${version}" true \
161 "single ${KBOOT_CMDLINE_LINUX}"
164 list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`