# alx specific functions add_conf_prot() { local i for i in $@ do export CONFIG_PROTECT="${CONFIG_PROTECT} ${i}" done } add_conf_prot_mask() { local i for i in $@ do export CONFIG_PROTECT_MASK="${CONFIG_PROTECT_MASK} ${i}" done } add_conf_prot_ignore() { local i for i in $@ do export CONFIG_PROTECT_IGNORE="${CONFIG_PROTECT_IGNORE} ${i}" done } # updates /boot/grub/grub.conf with given params # example: alx_grub_update kernel-image-name description alx_grub_update() { local KERNEL_IMAGE local KERNEL_DESCRIPTION local i local rootfs local grubroot local grubopts local OLD_IFS local grubconf="/boot/grub/grub.conf" local grub2conf="/boot/grub/grub.cfg" local pass KERNEL_IMAGE="$1" KERNEL_DESCRIPTION="$2" # some checks if [ -z "${KERNEL_IMAGE}" ] then echo "At least a kernel-image must be given" return 1 fi [ -z "${KERNEL_DESCRIPTION}" ] && KERNEL_DESCRIPTION="${KERNEL_IMAGE}" # grub2 if [[ -x /sbin/grub-mkconfig ]] then # create a device.map if [[ ! -f /boot/grub/device.map ]] then grub-mkdevicemap fi # needed by grub-mkconfig on the first run if [[ ! -f /boot/grub/video.lst ]] then install -m0644 /$(mlibdir)/grub/*/video.lst /boot/grub/video.lst fi # update grub.cfg LC_ALL=C grub-mkconfig -o ${grub2conf} # install bootloader to disk #local bootpartition="$(df -h /boot |(read; awk '{print $1; exit}'))" local bootdisk bootdisk="$(grub-probe --target=drive /boot | sed 's:(\(.*\),.*):(\1):')" # Generate core.img, but don't let it be installed in boot sector grub-install --no-floppy "${bootdisk}" # grub legacy else if [ ! -f ${grubconf} ] then echo "${grubconf} not found" return 1 fi # first of all get the first rootfs instance for i in $(< ${grubconf}) do rootfs="$(echo ${i} | grep root=)" [[ -n ${rootfs} ]] && break done # then get the grub-root OLD_IFS="$IFS" IFS=$'\n' for i in $(< ${grubconf}) do grubroot="$(echo ${i} | grep 'root (' | cut -d' ' -f2)" [[ -n ${grubroot} ]] && break done IFS="${OLD_IFS}" # check for special hardware if [[ -x $(which hwinfo) ]] then # zotac devices if [[ ! -z $(hwinfo --bios --storage | grep -i zotac) ]] then grubopts="rootdelay=8" echo "Special device 'ZOTAC' detected!" fi fi # fix description : > ${grubconf} echo "default 0" >> ${grubconf} echo "timeout 3" >> ${grubconf} # using roots current password if one was set pass="$(grep '^root:' /etc/shadow | cut -d: -f2)" # or fallback to a default password [[ -z ${pass} ]] && pass="$1$oc/rCMuc$ZodLQSj6N5zYIJtOBg.RT/" echo "password --md5 ${pass}" >> ${grubconf} echo >> ${grubconf} echo "# normal boot" >> ${grubconf} echo "title ${KERNEL_DESCRIPTION}" >> ${grubconf} echo "root ${grubroot}" >> ${grubconf} echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts}" >> ${grubconf} echo >> ${grubconf} echo "# admin boots" >> ${grubconf} echo "title ${KERNEL_DESCRIPTION} - Re-run hardware-detection" >> ${grubconf} echo "lock" >> ${grubconf} echo "root ${grubroot}" >> ${grubconf} echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} hardware-auto-detection" >> ${grubconf} echo >> ${grubconf} echo "title ${KERNEL_DESCRIPTION} - Reset *all* local settings" >> ${grubconf} echo "lock" >> ${grubconf} echo "root ${grubroot}" >> ${grubconf} echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} alx-reset-settings" >> ${grubconf} fi } ## compat alx_grub_update_new() { echo -e "${COLYELLOW}alx_grub_update_new() is deprecated - please only use alx_grub_update() from now on${COLDEFAULT}" alx_grub_update echo -e "${COLYELLOW}alx_grub_update_new() is deprecated - please only use alx_grub_update() from now on${COLDEFAULT}" }