#!/bin/sh

export PREFIX=/data1/portage/dec15/prefix
HAUBI=/data1/portage/haubi
KITO=/data1/portage/kito
MATT=/data1/portage/matt
STAGE1=/data1/portage/stage/stageUnzipped

#ROOT1 is where toolsbox root will be..
ROOT1=${PREFIX}/toolsbox-4-patchespre.20051215/i686-pc-linux-gnu

mkdir -p $PREFIX

cd ${PREFIX}/..

#unzip toolbox
tar -xvf ${HAUBI}/toolsbox-4-20050927.tar 
cd toolsbox-4-20050927

#change portage version
#using updated file in ${MATT}
chmod 777 portage/*
cp ${MATT}/portage.build portage/


#cp files I've already downloaded needed toolsbox tarballs
cp ${HAUBI}/distfiles/* buildroot/distfiles

gmake config PREFIX=${PREFIX} DISTURL=http://www.ibiblio.org/pub/Linux/distributions/gentoo/distfiles portage_BUILD


mkdir -p buildroot/distfiles
#I changed the name from portage-prefix and re gzip'd it (it was bzip2'd)
cp ${KITO}/portage-2.0.54.tar.gz buildroot/distfiles/

touch buildroot/portage/portage.fetched.done

gmake portage

#add ebuild-tree
mkdir -p ${ROOT1}/portage
cp -r ${KITO}/prefix-overlay/* ${ROOT1}/portage/

#add profile
mkdir -p ${ROOT1}/portage/profiles
#copy contents of dir/ignore directories
cp  ${HAUBI}/secondary-portage-snapshot-20050927/profiles/* ${ROOT1}/portage/profiles 
#recursively copy default-secondary
cp  -r ${HAUBI}/secondary-portage-snapshot-20050927/profiles/default-secondary ${ROOT1}/portage/profiles

#cp /etc from stage1
mkdir -p ${ROOT1}/etc
cp -r ${STAGE1}/etc/* ${ROOT1}/etc/
#rm make.profile
rm -f ${ROOT1}/etc/make.profile

#link make.profile
#x86 DEP!!!
ln -s ${ROOT1}/portage/profiles/default-secondary/linux/x86 ${ROOT1}/etc/make.profile

#use modified make.conf
#modified make.conf has x86!!!
cp ${MATT}/make.conf ${ROOT1}/etc/

cd ${ROOT1}
for f in ./bin/toolsbox-*-env.sh; do . $f;done

type emerge
emerge -av system






