#!/bin/bash

########################################################################
# MuGLIn - MuGLIn GNU/Linux Installation		                       #
#                                                                      #
# Copyright (C) 2010 Jakob Gurnhofer <jakob.gurnhofer@gmail.com>       #
# Copyricht (C) 2010 Srdjan Markovic <smark2ki@htl.moedling.at>        #
#                                                                      #
# This file is part of MuGLIn source code.                             #
#                                                                      #
# MuGLIn is free software: you can redistribute it and/or modify       #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or    #
# (at your option) any later version.                                  #
#                                                                      #
# MuGLIn is distributed in the hope that it will be useful,            #
# but WITHOUT ANY WARRANTY; without even the implied warranty of       #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        #
# GNU General Public License for more details.                         #
#                                                                      #
# You should have received a copy of the GNU General Public License    #
# along with MuGLIn. If not, see <http://www.gnu.org/licenses/>.       #
########################################################################

# installs grub
if [ ! -d /target/dev ]; then
	mkdir /target/dev
fi
if [ ! -d /target/proc ]; then
	mkdir /target/proc
fi
if [ ! -d /target/sys]; then
	mkdir /target/sys
fi
mount -t proc none /proc
mount -t sysfs none /sys
mount -o bind /dev /dev

DISC="$(grep /target/ /muglin_ram/tmp/mount | cut -d" " -f3 | sed -e 's/[[:digit:]]$//g')"
if [[ "$DISC" == "" ]]; then die "Could not identify primary disk from /tmp/mount."; fi
if [[ !  -x /sbin/grub-install ]]; then die "Could not find grub-install"; fi
chroot /target /mulin_bash -c /sbin/grub-install $DISC

umount /target/proc
umount /target/sys
umount /target/dev
