1 # kboot-mkconfig helper script.
2 # Copyright (C) 2011 Antonio Ospite <ospite@studenti.unina.it>
4 # Inspired by the 10_linux script from grub
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 # TODO: remove this if the following find_linux_root_device()
25 # is found to be reliable enough
26 #LINUX_ROOT_DEVICE="$(readlink -f $(mount | grep ' / ' | cut -d ' ' -f 1))"
28 if $(which gettext >/dev/null 2>/dev/null) ; then
34 # One layer of quotation is eaten by "", the second by sed, and the third by
35 # printf; so this turns ' into \'. Note that you must use the output of
36 # this function in a printf format string.
38 $gettext "$@" | sed "s/'/'\\\\\\\\''/g"
41 # Run the first argument through gettext_quoted, and then pass that and all
42 # remaining arguments to printf. This is a useful abbreviation and tends to
47 printf "$(gettext_quoted "$format")" "$@"
50 kboot_file_is_not_garbage ()
52 if test -f "$1" ; then
54 *.dpkg-*) return 1 ;; # debian dpkg
55 README*) return 1 ;; # documentation
65 local sedexp="s/[^-]*-//;s/[._-]\(pre\|rc\|test\|git\|old\|trunk\)/~\1/g"
66 local a=`echo $1 | sed -e "$sedexp"`
67 local b=`echo $2 | sed -e "$sedexp"`
69 if [ "x$b" = "x" ] ; then
74 *.old:*) a=`echo -n $a | sed -e s/\.old$//` ; cmp=gt ;;
75 *:*.old) b=`echo -n $b | sed -e s/\.old$//` ; cmp=ge ;;
77 dpkg --compare-versions "$a" $cmp "$b"
81 version_find_latest ()
85 if version_test_gt "$i" "$a" ; then
92 linux_find_root_device() {
93 RDEV=$(mountpoint -d /)
95 for devnode in $(find /dev);
97 if [ $(stat --printf="%t:%T" "$devnode") = $RDEV ];
113 if ${recovery} ; then
114 title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
116 title="$(gettext_quoted "%s, with Linux %s")"
118 label="$(printf "${title}" "${os}" "${version}")"
119 echo -n "'${label}'='${dirname}/${basename} "
120 if test -n "${initrd}" ; then
121 echo -n "initrd=${dirname}/${initrd}"
123 echo " root=${linux_root_device_thisversion} ro ${args}'"
128 list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do
129 if kboot_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
133 while [ "x$list" != "x" ] ; do
134 linux=`version_find_latest $list`
135 echo "Found linux image: $linux" >&2
136 basename=`basename $linux`
137 dirname=`dirname $linux`
139 # XXX: this relies on a binary shipped by GRUB, we just use ${dirname} for
140 # now, check the ${dirname} entries if we need something like that later
141 #rel_dirname=`make_system_path_relative_to_its_root $dirname`
143 version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
144 alt_version=`echo $version | sed -e "s,\.old$,,g"`
145 # TODO: remove this too
146 #linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
147 linux_root_device_thisversion=linux_find_root_device
150 for i in "initrd.img-${version}" "initrd-${version}.img" \
151 "initrd-${version}" "initramfs-${version}.img" \
152 "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
153 "initrd-${alt_version}" "initramfs-${alt_version}.img"; do
154 if test -e "${dirname}/${i}" ; then
161 for i in "config-${version}" "config-${alt_version}"; do
162 if test -e "${dirname}/${i}" ; then
163 initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${dirname}/${i}" | cut -f2 -d= | tr -d \"`
168 if test -n "${initrd}" ; then
169 echo "Found initrd image: ${dirname}/${initrd}" >&2
170 elif test -z "${initramfs}" ; then
171 # "UUID=" magic is parsed by initrd or initramfs. Since there's
172 # no initrd or builtin initramfs, it can't work here.
173 linux_root_device_thisversion=${KBOOT_DEVICE}
176 linux_entry "${OS}" "${version}" false \
177 "${KBOOT_CMDLINE_LINUX} ${KBOOT_CMDLINE_LINUX_DEFAULT}"
178 if [ "x${KBOOT_DISABLE_RECOVERY}" != "xtrue" ]; then
179 linux_entry "${OS}" "${version}" true \
180 "single ${KBOOT_CMDLINE_LINUX}"
183 list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`