#!/bin/bash # $Header: /home/cvsd/magellan-cvs/magellan-src/mage-buildroot/mage-buildroot.sh,v 1.1 2006-01-01 17:20:46 niro Exp $ # # mage buildroot # create buildroot to compile programms # may get later into mage # # default die function die() { echo -e ${COLRED}"$@"${COLDEFAULT} exit 1 } [[ $(id -u ) != 0 ]] && die "you must be root" # i need some settings and functions from mage [ -f /etc/rc.d/init.d/functions ] && \ source /etc/rc.d/init.d/functions || \ die "Your /etc/mage.rc is missing. Aborting." [ -f /etc/mage.rc.global ] && \ source /etc/mage.rc.global || \ die "/etc/mage.rc.global missing" [ -f /etc/mage.rc ] && source /etc/mage.rc || \ die "Your /etc/mage.rc is missing. Aborting." [ -f ${MLIBDIR}/mage4.functions.sh ] && \ source ${MLIBDIR}/mage4.functions.sh || \ die "mage functions missing" installrc() { local var="$1" # sanity checks [ -z "${MROOT}" ] && die "\$MROOT not given." echo "${var}" >> ${MROOT}/.installrc || die "add_initrc() adding \$var" } enter_chroot() { [ ! -d ${MROOT}/proc ] && install -d ${MROOT}/proc [ ! -d ${MROOT}/dev ] && install -d ${MROOT}/dev [ ! -d ${MROOT}/sys ] && install -d ${MROOT}/sys mount -t proc proc ${MROOT}/proc mount -t sysfs sysfs ${MROOT}/sys mount -o bind /dev ${MROOT}/dev # chroot ${MROOT} /bin/bash -i /.installrc chroot ${MROOT} /usr/bin/env -i \ HOME=/root \ TERM="${TERM}" \ PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ /bin/bash -i /.installrc #|| die "chr00ting" umount ${MROOT}/dev umount ${MROOT}/proc umount ${MROOT}/sys #[ -f ${MROOT}/.installrc ] && rm ${MROOT}/.installrc } # some sane defaults MROOT="$1" TARGET_PKG="$2" #MAGERC="/etc/mage.rc" MAGERC="/home/tjoke/mage.rc-buildroot" MAGE_PROFILE="$(basename $(readlink /etc/mage-profile))" TOOLCHAIN=toolchain BASESYSTEM=common-devutils # first install a toolchain and some common dev-utils using bootstrap2 # only if not already builded if [ ! -f ${MROOT}/.buildroot_build_ok-${TOOLCHAIN}-${BASESYSTEM} ] then #mage-bootstrap \ /home/tjoke/alx-cvs/magellan-src/bootstrap/scripts/mage-bootstrap.sh \ --root "${MROOT}" \ --magerc "${MAGERC}" \ --profile "${MAGE_PROFILE}" \ --toolchain "${TOOLCHAIN}" \ --basesystem "${BASESYSTEM}" \ || die "bootstrapping toolchain" # mark this as builded touch ${MROOT}/.buildroot_build_ok-${TOOLCHAIN}-${BASESYSTEM} || die "touch ok" fi ##################################################### # setup a chroot environment # ##################################################### echo > ${MROOT}/.installrc || die # some needed env-vars and functions installrc 'unset MROOT' installrc 'env-rebuild' installrc 'source /etc/profile' installrc 'die() { echo -e ${COLRED}"$@"${COLDEFAULT}; exit 1; }' installrc '[ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions' # || die "Your /etc/mage.rc is missing. Aborting."' installrc '[ -f /etc/mage.rc.global ] && . /etc/mage.rc.global' # || die "/etc/mage.rc.global missing"' installrc '[ -f /etc/mage.rc ] && . /etc/mage.rc' # || die "Your /etc/mage.rc is missing. Aborting."' installrc '[ -f ${MLIBDIR}/mage4.functions.sh ] && . ${MLIBDIR}/mage4.functions.sh' # || die "mage functions missing"' installrc "export FAKE_MROOT=\"${MROOT}\"" installrc "export TARGET_PKG=\"${TARGET_PKG}\"" # update mage only if buildroot already exists [ -f ${MROOT}/.buildroot_build_ok-${TOOLCHAIN}-${BASESYSTEM} ] && installrc 'mage update' installrc 'smage2 update' # run part cat >> ${MROOT}/.installrc << "EOF" ##################################################### # now calculate the src-dependencies for TARGET_PKG # ##################################################### # before anything run mage_setup mage_setup || die "error in mage_setup()" # first of all get the right pkg which going to be installed PCAT="$(pname2pcat ${TARGET_PKG})" # package does not exists [ -z "${PCAT}" ] && die "Package '${TARGET_PKG}' does not exist." # source the highest magefile of this pkg PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${TARGET_PKG})) # convert PKGNAME to PNAME/PVER/PBUILD # we're working *only* with these three vars from here on PNAME="$(pkgname2pname ${PKGNAME})" PVER="$(pkgname2pver ${PKGNAME})" PBUILD="$(pkgname2pbuild ${PKGNAME})" if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} then echo -en "Package " echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" echo -e " already installed." exit 3 fi # get all dependencies of this package ALLDEPS="$(${MLIBDIR}/depwalker.sh \ --method srcinstall \ --pcat ${PCAT} \ --pname ${PNAME} \ --pver ${PVER} \ --pbuild ${PBUILD})" # remove TARGET_PKG from list SRC_INSTALL_DEPS="$(get_highest_magefile ${PCAT} ${TARGET_PKG})" INSTALL_DEPS="${ALLDEPS/${SRC_INSTALL_DEPS}/}" echo echo "---- environment -----" echo "MROOT: ${FAKE_MROOT}" echo "PKGDIR: ${PKGDIR}" echo "BUILDDIR: ${BUILDDIR}" echo "BINDIR: ${BINDIR}" echo "----------------------" echo echo "---- dependencies ----" echo "SRC_INSTALL_DEPS: ${SRC_INSTALL_DEPS}" echo "INSTALL_DEPS: ${INSTALL_DEPS}" echo "----------------------" #read # now install the packages (no srcinstall, when the user not explcitly want this) fetch_packages ${INSTALL_DEPS} || die "fetching packages" md5sum_packages ${INSTALL_DEPS} || die "md5 sum packages" unpack_packages ${INSTALL_DEPS} || die "unpacking packages" install_packages ${INSTALL_DEPS} || die "installing packages" # whipe out all packages mage clean # now src-install TARGET_PKG install_packages --src-install ${SRC_INSTALL_DEPS} || die "src-installing packages" # done echo -e "Package ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT} successfully builded." echo "You will find this in ${FAKE_MROOT}/${PKGDIR}." EOF # run this stuff enter_chroot