#! /bin/bash

#Parametri di configurazione

PASSWORD="Temp?Passw0rd"
IP_ADDR="192.168.254.250"
BROADCAST="192.168.254.255"
NETMASK="255.255.255.0"
GATEWAY="192.168.254.253"
DNS=${GATEWAY}

#Monta le partizioni nelle rispettive directory
mount /dev/hda1 /mnt/gentoo
mount /dev/hda2 /mnt/gentoo/boot
mount /dev/hda5 /mnt/gentoo/tmp
mount /dev/hda6 /mnt/gentoo/root
mount /dev/hda7 /mnt/gentoo/home
mount /dev/hda8 /mnt/gentoo/etc
mount /dev/hda9 /mnt/gentoo/usr
mount /dev/hda10 /mnt/gentoo/lib
mount /dev/hda11 /mnt/gentoo/var
mount /dev/hda12 /mnt/gentoo/var/log
mount /dev/hda13 /mnt/gentoo/var/spool
mount /dev/hda14 /mnt/gentoo/mnt/data

#Settaggio swap e tmp
swapon /dev/hda3
chmod 1777 /mnt/tmp

cd /mmt/gentoo

#Configura la rete
ifconfig eth0 ${IP_ADDR} broadcast ${BROADCAST} netmask ${NETMASK} up
route add default gw ${GATEWAY}
echo "NAMESERVER ${DNS}">/etc/resolv.conf

#Assegna la password di root
passwd < echo "${PASSWORD}\n${PASSWORD}"

#Inizializza demone ssh
/etc/init.d/sshd start

#Monta proc e dev
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev

#Passaggio al nuovo ambiente
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile
export PS1="(chroot) $PS1"

#Aggiornamento emerge
emerge --sync --quiet
emerge --oneshot portage

#Copia le informazioni del DNS nel sistema finale
cp -L /etc/resolv.conf /mnt/gentoo/etc

#Imposta l'hostname sul sistema finale
echo "HOSTNAME=\"Goliath\"" > /mnt/gentoo/etc/conf.d/hostname

#Imposta la rete sul sistema finale
echo "config_eth0=(\"192.168.254.250 netmask 255.255.255.0 brd 192.168.254.255\")" > /mnt/gentoo/etc/conf.d/net
echo "routes_eth0=(\"default via 192.168.254.253\")" >> /mnt/gentoo/etc/conf.d/net
echo "config_eth1=(\"dhcp\")" >> /mnt/gentoo/etc/conf.d/net

#Compila il kernel
make && make install

emerge grub
grep -v rootfs /proc/mounts > /etc/mtab
grub-install --no-floppy /dev/hda

echo "copiare arch/i386/boot/bzImage /boot/kernel-VERSIONE-gentoo-r5"
echo "editare /etc/modules.autoload.d/kernel-2.6"
echo "editare /etc/rc.conf

