#!/bin/sh

######PROBABLY NEED TO CHANGE/ADJUST THESE...

export PREFIX=/data1/portage/dec21/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.20051221/i686-pc-linux-gnu

###########################
function bootstrap {
    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
mkdir -p buildroot/distfiles
cp ${HAUBI}/distfiles/* buildroot/distfiles

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



#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/
cp -r ${MATT}/portage-2.0.54 buildroot/portage/
#use my portage tree (has changes)
touch buildroot/portage/portage.fetched.done
touch buildroot/portage/portage.extracted.done

gmake portage

#add ebuild-tree
mkdir -p ${ROOT1}/usr/local/portage
cp -r ${KITO}/prefix-overlay/* ${ROOT1}/usr/local/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

#copy eclass files
cp  -r ${HAUBI}/secondary-portage-snapshot-20050927/eclass ${ROOT1}/portage/

#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/
sed -e "s|#PREFIX#|${ROOT1}|g" -i ${ROOT1}/etc/make.conf

#copy modified/new ebuilds
cp -r ${MATT}/treeadditions/*  ${ROOT1}/usr/local/portage

#create package.keywords
#changed package.mask to remove it...
#echo "sys-libs/db" > ${ROOT1}/etc/portage/package.keywords
}


function symlink {
    echo "symlinking $1"
    #make parent directories
    mkdir -p ${ROOT1}/`which $1`
    #delete directory that is really cmd
    rm -rf  ${ROOT1}/`which $1`
    
    ln -s `which $1` ${ROOT1}/`which $1`
}

#bootstrap

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






cd ${ROOT1}
#create symlinks
mkdir -p ${ROOT1}/usr/bin
mkdir -p ${ROOT1}/bin

#ln -s `which rm` ${ROOT1}/`which rm`
#ln -s `which rmdir` ${ROOT1}/`which rmdir`
ln -s `which find` ${ROOT1}/`which find`
#ln -s `which wget` ${ROOT1}/`which wget`
ln -s `which id` ${ROOT1}/`which id`
ln -s `which install` ${ROOT1}/`which install`
ln -s `which tar` ${ROOT1}/`which tar`
ln -s `which gzip` ${ROOT1}/`which gzip`
ln -s `which cat` ${ROOT1}/`which cat`
ln -s `which touch` ${ROOT1}/`which touch`
symlink chmod
symlink sed
symlink mkdir
symlink cp
symlink rm
symlink rmdir
symlink ln
symlink sh
symlink strace
symlink diff
symlink expr
symlink uniq
symlink grep
symlink mv
symlink sort
symlink make
symlink sed

type emerge
emerge -av system
