#!/bin/sh # vim: et sw=2 sts=2 ts=2 tw=0: # # Copyright 2013 Dimitris Tzemos # Copyright 2014 Cyrille Pontvieux # # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # initialize() { if [ ! -d "$TMP" ]; then mkdir -p "$TMP" chmod 700 "$TMP" fi # T_PX is the root device. Used in the Slackware installer. # The variable name is kept the same here, for consistence. if [ -n "$!" ] && [ -d "$1" ]; then T_PX="$1" elif [ -r $TMP/SeTT_PX ]; then T_PX=$(cat $TMP/SeTT_PX) else T_PX=/ fi cd "$T_PX" # Determine the root partition (such as /dev/hda2) if [ -n "$2" ] && [ -e "$2" ]; then DEV="$2" elif [ -r $TMP/SeTrootdev ]; then DEV=$(cat $TMP/SeTrootdev) else DEV=$(df .|sed -rn '$s/^([^ \t]+)[ \t].*/\1/p') fi [ -n "$DEV" ] || exit 1 # Set OS name # are we on a running system? if [ -r etc/slackware-version ]; then OS="Salix $(sed -e 's/^Slackware //' etc/slackware-version)" else OS="Salix" fi # Title BACKTITLE="$OS - GRUB Installer" } ask_append() { dialog \ --title 'OPTIONAL GRUB_CMDLINE_LINUX_DEFAULT="" LINE' \ --inputbox \ "Some systems might require extra parameters to be passed to the kernel. \ If you needed to pass parameters to the kernel when you booted the Slackware \ bootdisk, you'll probably want to enter the same ones here. Most \ systems won't require any extra parameters. If you don't need any, just \ hit ENTER to continue.\n\ " 12 72 2> $TMP/reply RETVAL=$? return $RETVAL } append_grub_conf() { ask_append; GRUB_CMDLINE_LINUX_DEFAULT="quiet $(cat $TMP/reply)" UTFVT='vt.default_utf8=1' sed -i " s/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT='$GRUB_CMDLINE_LINUX_DEFAULT'/; s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX='$UTFVT'/; " etc/default/grub } install_grub() { # Setup Menu dialog --backtitle "$BACKTITLE" \ --title ' INSTALL GRUB2 ' \ --menu "\nWhere do you want to install the boot loader?" 0 0 0 \ "MBR" "Install in $(echo "$DEV"|sed 's/[0-9]$//') (recommended) " \ "ROOT" "Install in $DEV (Expert)" \ "EXIT" "Quit (Do not install GRUB)" \ 2> $TMP/option_menu.txt OPTION="$(cat $TMP/option_menu.txt)" if [ "$OPTION" = "MBR" ]; then DEVICE="$(echo "$DEV"|sed 's/[0-9]$//')" elif [ "$OPTION" = "ROOT" ]; then DEVICE="$DEV" else clear && exit 1 fi # Confirm Installation dialog --backtitle "$BACKTITLE" \ --title ' CONTINUE? ' \ --yesno "\n This will install the GRUB2 bootloader \n in $DEVICE \n " 0 0 || exit 1 # install grub2 TEXT="Installing bootloader in $DEVICE...\n " chroot "$T_PX" grub-install --target=i386-pc --boot-directory=/boot --recheck --force $DEVICE 2>&1 |\ while read LINE; do TEXT="$TEXT \n$LINE" dialog --backtitle "$BACKTITLE" --title ' INSTALLING GRUB2 ' --infobox "$TEXT" 0 0 done sleep 3 # Update boot menu TEXT="Updating boot/grub/grub.cfg...\n " chroot "$T_PX" update-grub 2>&1 |\ while read LINE; do TEXT="$TEXT \n$LINE" dialog --backtitle "$BACKTITLE" --title ' UPDATING GRUB2 ' --infobox "$TEXT" 0 0 done sleep 1 } # Check for root [ $(id -u) -eq 0 ] || exit 1 # Create temporary directory TMP=/var/log/setup/tmp T_PX='' # passed as first argument by the installer DEV='' # passed as second argument by the installer BACKTITLE='' initialize "$@" cd "$T_PX" append_grub_conf install_grub rm -f $TMP/reply $TMP/option_menu.txt 2>/dev/null || true