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   ROOT_DEVICE=$(mountpoint -d /)
 
  95   for devnode in $(find /dev);
 
  97     # Get major and minor in decimal
 
  98     CURRENT_DEVICE=$(printf "%d:%d" $(stat --printf="0x%t 0x%T" "$devnode"))
 
  99     if [ $CURRENT_DEVICE = $ROOT_DEVICE ];
 
 115   if ${recovery} ; then
 
 116     title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
 
 118     title="$(gettext_quoted "%s, with Linux %s")"
 
 120   label="$(printf "${title}" "${os}" "${version}")"
 
 121   echo -n "'${label}'='${dirname}/${basename} "
 
 122   if test -n "${initrd}" ; then
 
 123         echo -n "initrd=${dirname}/${initrd}"
 
 125   echo " root=${linux_root_device_thisversion} ro ${args}'"
 
 130   list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do
 
 131           if kboot_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
 
 135   while [ "x$list" != "x" ] ; do
 
 136     linux=`version_find_latest $list`
 
 137     echo "Found linux image: $linux" >&2
 
 138     basename=`basename $linux`
 
 139     dirname=`dirname $linux`
 
 141     # XXX: this relies on a binary shipped by GRUB, we just use ${dirname} for 
 
 142     # now, check the ${dirname} entries if we need something like that later
 
 143     #rel_dirname=`make_system_path_relative_to_its_root $dirname`
 
 145     version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
 
 146     alt_version=`echo $version | sed -e "s,\.old$,,g"`
 
 147     # TODO: remove this too 
 
 148     #linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
 
 149     linux_root_device_thisversion=`linux_find_root_device`
 
 152     for i in "initrd.img-${version}" "initrd-${version}.img" \
 
 153              "initrd-${version}" "initramfs-${version}.img" \
 
 154              "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
 
 155              "initrd-${alt_version}" "initramfs-${alt_version}.img"; do
 
 156       if test -e "${dirname}/${i}" ; then
 
 163     for i in "config-${version}" "config-${alt_version}"; do
 
 164       if test -e "${dirname}/${i}" ; then
 
 165         initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${dirname}/${i}" | cut -f2 -d= | tr -d \"`
 
 170     if test -n "${initrd}" ; then
 
 171       echo "Found initrd image: ${dirname}/${initrd}" >&2
 
 172     elif test -z "${initramfs}" ; then
 
 173       # "UUID=" magic is parsed by initrd or initramfs.  Since there's
 
 174       # no initrd or builtin initramfs, it can't work here.
 
 175       linux_root_device_thisversion=${KBOOT_DEVICE}
 
 178     linux_entry "${OS}" "${version}" false \
 
 179         "${KBOOT_CMDLINE_LINUX} ${KBOOT_CMDLINE_LINUX_DEFAULT}"
 
 180     if [ "x${KBOOT_DISABLE_RECOVERY}" != "xtrue" ]; then
 
 181       linux_entry "${OS}" "${version}" true \
 
 182           "single ${KBOOT_CMDLINE_LINUX}"
 
 185     list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`