#!/bin/sh # # Copyright 2013 Dimitris Tzemos # Copyright 2013 SalixOS Linux, # Copyright 2013 Slackel Linux # 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. # # Set OS name (Slackel, Salix) #OS="Slackel $(sed -e 's/^Slackware //' /etc/slackware-version)" # 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 GRUB2 Installer v0.1 - By Dimitris Tzemos " BACKTITLE="$OS - GRUB2 Installer" initialize(){ # Create temporary directory TMP=/var/log/setup/tmp if [ ! -d "$TMP" ]; then mkdir -p "$TMP" fi #T_PX="`cat $TMP/SeTT_PX`" # Set the OS root directory (called T_PX for some unknown reason). # If an argument is given to this script and it is a directory, it # is taken to be the root directory. First though, we check for a # directory named $T_PX, and that gets the first priority. if [ ! -d "$T_PX" ]; then if [ ! "$1" = "" ]; then if [ -d "$1" ]; then T_PX="$1" fi else # Are we on the installer image? if [ -r /usr/lib/setup/SeTpartitions ]; then T_PX=/mnt # Or, are we on a running system? elif [ -r /etc/slackware-version ]; then T_PX=/ # One more installer-likely thing: elif [ -r /usr/lib/setup/setup ]; then T_PX=/mnt else # We will have to assume we've on an installed and running system. T_PX=/ fi fi fi # Determine the root partition (such as /dev/hda2) ROOT_DEVICE=$2 if [ "$ROOT_DEVICE" = "" ]; then if [ -r $TMP/SeTrootdev ]; then ROOT_DEVICE="`cat $TMP/SeTrootdev`" else ROOT_DEVICE="`mount | cut -f 1 -d " " | sed -n "1 p"`" fi fi #Find Root Device echo $ROOT_DEVICE > "$TMP/device.txt" # Define selected device and mount point DEV="$(cat "$TMP/device.txt"|tr -d ' ')" if [ ! "$(mount|grep "^$DEV")" ]; then mount $DEV >/dev/null 2>&1 fi if [ "$DEV" = "" -o "$T_PX" = "" ]; then exit 1; fi } 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; if [ $? = 1 -o $? = 255 ]; then GRUB_CMDLINE_LINUX_DEFAULT="quiet " fi GRUB_CMDLINE_LINUX_DEFAULT="quiet `cat $TMP/reply`" UTFVT="vt.default_utf8=1" if [ ! "$GRUB_CMDLINE_LINUX_DEFAULT" = "" -o ! "$UTFVT" = "" ]; then sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT='$GRUB_CMDLINE_LINUX_DEFAULT'/" $T_PX/etc/default/grub sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX='$UTFVT'/" $T_PX/etc/default/grub fi } install_grub(){ # Setup Menu dialog --backtitle "$BACKTITLE" --title " INSTALL GRUB2 " \ --menu "\nWhere do you want to install the boot loader?" 0 0 0 \ "MBR" "Be installed in $(echo "$DEV"|sed 's/[0-9]$//') (recommended) " \ "ROOT" "Be installed in $DEV (Expert)" \ "EXIT" "Quit (Do not install the grub2)" \ 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 if [ $? -ne 0 ]; then exit 1; fi # 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 } initialize append_grub_conf install_grub