#! /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}

#Formatta le partizioni
mke2fs -j /dev/hda1
mke2fs -j /dev/hda2
mkswap /dev/hda3
mke2fs -j /dev/hda5
mke2fs -j /dev/hda6
mke2fs -j /dev/hda7
mke2fs -j /dev/hda8
mke2fs -j /dev/hda9
mke2fs -j /dev/hda10
mke2fs -j /dev/hda11
mke2fs -j /dev/hda12
mke2fs -j /dev/hda13
mke2fs -j /dev/hda14

#Crea la struttura delle directory
mkdir /mnt/gentoo/boot
mkdir /mnt/gentoo/usr
mkdir /mnt/gentoo/lib
mkdir /mnt/gentoo/var
mkdir /mnt/gentoo/var/log
mkdir /mnt/gentoo/var/spool
mkdir /mnt/gentoo/etc
mkdir /mnt/gentoo/tmp
mkdir /mnt/gentoo/home
mkdir /mnt/gentoo/root
mkdir /mnt/gentoo/mnt
mkdir /mnt/gentoo/mnt/data

#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

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

#Scarica stage3
wget ftp://ftp.unina.it/pub/linux/distributions/gentoo/relases/x86/2008.0/stages/stage3-x86-2008.0.tar.bz2
wget ftp://ftp.unina.it/pub/linux/distributions/gentoo/relases/x86/2008.0/stages/stage3-x86-2008.0.tar.bz2.CONTENTS
wget ftp://ftp.unina.it/pub/linux/distributions/gentoo/relases/x86/2008.0/stages/stage3-x86-2008.0.tar.bz2.DIGESTS

#Controlla il contenuto
md5sum -c stage3-x86-2008.0.tar.bz2.DIGESTS > stage.log

#Scompatta stage3
tar xvjpf stage3-*.tar.bz2


#Scarica portage
wget ftp://ftp.unina.it/pub/linux/distributions/gentoo/snapshots/portage-latest.tar.bz2
wget ftp://ftp.unina.it/pub/linux/distributions/gentoo/snapshots/portage-latest.tar.bz2.gpgsig
wget ftp://ftp.unina.it/pub/linux/distributions/gentoo/snapshots/portage-latest.tar.bz2.md5sum

#Controlla il contenuto
md5sum -c portage-latest.tar.bz2.md5sum > portage.log

#Scompatta portage
tar xvjf /mnt/gentoo/portage-latest.tar.bz2 -C /mnt/gentoo/usr


#Selezione dei mirror
mirrorselect -i -o >> /mnt/gentoo/etc/make.conf

#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

#Download sorgenti kernel
emerge gentoo-sources

#Cose da fare prima di continuare
echo "EDITARE make.conf"
echo "EDITARE make.defaults"
echo "EDITARE /etc/make.profile"

echo "EDITARE menuconfig"



