aports/main/compat-pvgrub/update-pvgrub
JailBox d07bbedd08 main/compat-pvgrub: prevent output to wrong conf-file
if "$myconf" defines/redefines "$conf"
        the generated output would go to the wrong file
I.e.
  >echo "conf=/boot/mybootdir/extlinux.conf" >> /etc/update-extliunx.conf
 /sbin/update-extlinux will honor this,
 while update-pvgrub would write to the wrong config file.

So postpone presetting "$conf" until "$myconf" has been source'd
2019-10-28 19:15:13 +00:00

118 lines
2.2 KiB
Bash
Executable file

#!/bin/sh
version=
default=0
timeout=5
verbose=0
myconf=/etc/update-extlinux.conf
# read in extlinux settings
if [ -f "$myconf" ]; then
. $myconf
fi
conf=/boot/grub/menu.lst
everbose() {
if [ "$verbose" = "0" ]; then
return
fi
echo $*
}
ewarn() {
echo "WARNING:" $@ >&2
}
eerror() {
echo "ERROR:" $@ >&2
return 1
}
everbose "Updating extlinux configuration."
if [ "x$root" = "x" ]; then
ewarn "Root device is not specified in $myconf."
blkid_export=$(blkid -o export /dev/root)
if [ -n "$blkid_export" ]; then
export $blkid_export
fi
if [ -z "$UUID" ]; then
# try parse /proc/mount for mounted /
dev=$(awk '$2 == "/" {dev=$1} END {print dev}' /proc/mounts)
if [ -n "$dev" ]; then
blkid_export=$(blkid -o export $dev)
if [ -n "$blkid_export" ]; then
export "$blkid_export"
fi
fi
fi
if [ -z "$UUID" ]; then
if [ -z "$dev" ]; then
eerror "Failed to detect root device"
exit 1
else
root=$dev
fi
else
root=UUID=$UUID
fi
everbose "Root device is: $root"
fi
menu_hidden=
umask 0022
rm -f $conf.new
echo "# Generated by update-pvgrub $version" > $conf.new
echo "default 0" >> $conf.new
if [ "$hidden" = "1" ]; then
echo "hiddenmenu" >> $conf.new
fi
echo "timeout $timeout" >> $conf.new
lst=0
for kernel in $(find /boot -name "vmlinuz-*" -type f); do
tag=$(basename $kernel | cut -b9-)
everbose "Found kernel: $kernel"
label=$(grep -w -l $tag /usr/share/kernel/*/kernel.release | cut -d/ -f5)
if [ -z "$label" ]; then
label=$lst
fi
echo "title Linux $tag" >> $conf.new
echo "root (hd0)" >> $conf.new
echo "kernel /boot/$(basename $kernel) root=$root modules=${modules}${TYPE:+,$TYPE} $default_kernel_opts" >> $conf.new
if [ -f "/boot/initramfs-$tag" ]; then
everbose "Found initramfs: /boot/initramfs-$tag"
echo "initrd /boot/initramfs-$tag" >> $conf.new
fi
echo "" >> $conf.new
lst=$(($lst + 1))
done
if [ -n "$password" ]; then
echo "password --md5 $password" >> $conf.new
echo "" >> $conf.new
chmod o-r $conf.new
fi
everbose "$lst entries found."
if cmp -s $conf.new $conf; then
everbose "Configuration unchanged."
rm $conf.new
fi
if [ "$overwrite" != "1" ]; then
exit 0
elif [ -f "$conf.new" ]; then
# keep a backup just in case
if [ -f "$conf" ]; then
mv $conf $conf.old
fi
mv $conf.new $conf
fi