Set FEATURES=-news before emerging ccache/distcc/icecream
[catalyst.git] / targets / support / chroot-functions.sh
old mode 100755 (executable)
new mode 100644 (file)
index 6f80b9e..1a44c92
@@ -13,7 +13,7 @@ trap "echo SIGKILL signal recieved killing $0 with pid $$;kill -9 $$" SIGKILL
 #      * user types ctrl-c
 #      * kernel recognizes this and generates SIGINT signal
 trap "echo SIGINT signal recieved killing $0 with pid $$;kill -9 $$" SIGINT
+
 check_genkernel_version(){
        if [ -x /usr/bin/genkernel ]
        then
@@ -36,11 +36,9 @@ check_genkernel_version(){
 }
 
 get_libdir() {
+       ABI=$(portageq envvar ABI)
        DEFAULT_ABI=$(portageq envvar DEFAULT_ABI)
        LIBDIR_default=$(portageq envvar LIBDIR_default)
-       MULTILIB_ABIS=${MULTILIB_ABIS:-"default"}
-       export DEFAULT_ABI=${DEFAULT_ABI:-"default"}
-       export LIBDIR_default=${CONF_LIBDIR:-"lib"}
 
        local abi
        if [ $# -gt 0 ]
@@ -63,46 +61,47 @@ get_libdir() {
 
 setup_myfeatures(){
        setup_myemergeopts
+       export FEATURES="-news"
        if [ -n "${clst_CCACHE}" ]
        then
                export clst_myfeatures="${clst_myfeatures} ccache"
-               #if [ "${clst_AUTORESUME}" = "1" -a -e /tmp/.clst_ccache ]
-               #then
-               #       echo "CCACHE Autoresume point found not emerging ccache"
-               #else
-                       clst_root_path=/ run_emerge --oneshot --nodeps ccache || exit 1
-               #       touch /tmp/.clst_ccache
-               #fi
+               clst_root_path=/ run_merge --oneshot --nodeps --noreplace dev-util/ccache || exit 1
        fi
 
        if [ -n "${clst_DISTCC}" ]
        then
                export clst_myfeatures="${clst_myfeatures} distcc"
                export DISTCC_HOSTS="${clst_distcc_hosts}"
-               #if [ "${clst_AUTORESUME}" = "1" -a -e /tmp/.clst_distcc ]
-               #then
-               #       echo "DISTCC Autoresume point found not emerging distcc"
-               #else
-                       USE="-gtk -gnome" clst_root_path=/ run_emerge --oneshot --nodeps distcc || exit 1
-                       #touch /tmp/.clst_distcc
-               #fi
+               [ -e /etc/make.conf ] && \
+                       echo 'USE="${USE} -avahi -gtk -gnome"' >> /etc/make.conf
+               # We install distcc to / on stage1, then use --noreplace, so we need to
+               # have some way to check if we need to reinstall distcc without being
+               # able to rely on USE, so we check for the distcc user and force a
+               # reinstall if it isn't found.
+               if [ "$(getent passwd distcc | cut -d: -f1)" != "distcc" ]
+               then
+                       clst_root_path=/ run_merge --oneshot --nodeps sys-devel/distcc || exit 1
+               else
+                       clst_root_path=/ run_merge --oneshot --nodeps --noreplace sys-devel/distcc || exit 1
+               fi
+               sed -i '/USE="${USE} -avahi -gtk -gnome"/d' /etc/make.conf
                mkdir -p /etc/distcc
                echo "${clst_distcc_hosts}" > /etc/distcc/hosts
 
                # This sets up automatic cross-distcc-fu according to
                # http://www.gentoo.org/doc/en/cross-compiling-distcc.xml
                CHOST=$(portageq envvar CHOST)
-               # TODO: change to use get_libdir
-               cd /usr/lib/distcc/bin
+               LIBDIR=$(get_libdir)
+               cd /usr/${LIBDIR}/distcc/bin
                rm cc gcc g++ c++ 2>/dev/null
-               echo -e '#!/bin/bash\nexec /usr/lib/distcc/bin/'${CHOST}'-g${0:$[-2]} "$@"' > ${CHOST}-wrapper
-               chmod a+x /usr/lib/distcc/bin/${CHOST}-wrapper
+               echo -e '#!/bin/bash\nexec /usr/'${LIBDIR}'/distcc/bin/'${CHOST}'-g${0:$[-2]} "$@"' > ${CHOST}-wrapper
+               chmod a+x /usr/${LIBDIR}/distcc/bin/${CHOST}-wrapper
                for i in cc gcc g++ c++; do ln -s ${CHOST}-wrapper ${i}; done
        fi
 
        if [ -n "${clst_ICECREAM}" ]
        then
-               clst_root_path=/ run_emerge --oneshot --nodeps sys-devel/icecream || exit 1
+               clst_root_path=/ run_merge --oneshot --nodeps --noreplace sys-devel/icecream || exit 1
 
                # This sets up automatic cross-icecc-fu according to
                # http://gentoo-wiki.com/HOWTO_Setup_An_ICECREAM_Compile_Cluster#Icecream_and_cross-compiling
@@ -116,6 +115,7 @@ setup_myfeatures(){
                export PATH="/usr/lib/icecc/bin:${PATH}"
                export PREROOTPATH="/usr/lib/icecc/bin"
        fi
+       export FEATURES="${clst_myfeatures} -news"
 }
 
 setup_myemergeopts(){
@@ -124,76 +124,104 @@ setup_myemergeopts(){
                clst_myemergeopts="--verbose"
        else
                clst_myemergeopts="--quiet"
+               bootstrap_opts="${bootstrap_opts} -q"
        fi
        if [ -n "${clst_FETCH}" ]
        then
-               export bootstrap_opts="-f"
+               export bootstrap_opts="${bootstrap_opts} -f"
                export clst_myemergeopts="${clst_myemergeopts} -f"
        elif [ -n "${clst_PKGCACHE}" ]
        then
                export clst_myemergeopts="${clst_myemergeopts} --usepkg --buildpkg --newuse"
-               export bootstrap_opts="-r"
+               export bootstrap_opts="${bootstrap_opts} -r"
        fi
 }
 
-
-setup_portage(){
-       # portage needs to be merged manually with USE="build" set to avoid frying
-       # our make.conf. emerge system could merge it otherwise.
-#      if [ "${clst_AUTORESUME}" = "1" -a -e /tmp/.clst_portage ]
-#      then
-#              echo "Portage Autoresume point found not emerging portage"
-#      else
-               USE="build" run_emerge --oneshot --nodeps portage
-#              touch /tmp/.clst_portage || exit 1
-#      fi
-}
-
-setup_gcc(){
-       if [ -x /usr/bin/gcc-config ]
+setup_binutils(){
+       if [ -x /usr/bin/binutils-config ]
        then
-               mythang=$( cd /etc/env.d/gcc; ls ${clst_CHOST}-* | head -n 1 )
+               mythang=$( cd /etc/env.d/binutils; ls ${clst_CHOST}-* | head -n 1 )
                if [ -z "${mythang}" ]
                then
                        mythang=1
                fi
-               gcc-config ${mythang}; update_env_settings
+               binutils-config ${mythang}; update_env_settings
        fi
 }
 
-setup_binutils(){
-       if [ -x /usr/bin/binutils-config ]
+setup_gcc(){
+       if [ -x /usr/bin/gcc-config ]
        then
-               mythang=$( cd /etc/env.d/binutils; ls ${clst_CHOST}-* | head -n 1 )
+               mythang=$( cd /etc/env.d/gcc; ls ${clst_CHOST}-* | head -n 1 )
                if [ -z "${mythang}" ]
                then
                        mythang=1
                fi
-               binutils-config ${mythang}; update_env_settings
+               gcc-config ${mythang}; update_env_settings
        fi
 }
 
+setup_pkgmgr(){
+       # We need to merge our package manager with USE="build" set in case it is
+       # portage to avoid frying our /etc/make.conf file.  Otherwise, we could
+       # just let emerge system could merge it.
+       [ -e /etc/make.conf ] && echo 'USE="${USE} build"' >> /etc/make.conf
+       run_merge --oneshot --nodeps sys-apps/portage
+       sed -i '/USE="${USE} build"/d' /etc/make.conf
+}
+
 cleanup_distcc() {
+       LIBDIR=$(get_libdir)
        rm -rf /etc/distcc/hosts
        for i in cc gcc c++ g++; do
-               # TODO: change to use get_libdir
-               rm /usr/lib/distcc/bin/${i}
-               ln -s /usr/bin/distcc /usr/lib/distcc/bin/${i}
+               rm -f /usr/${LIBDIR}/distcc/bin/${i}
+               ln -s /usr/bin/distcc /usr/${LIBDIR}/distcc/bin/${i}
        done
-       rm /usr/lib/distcc/bin/*-wrapper
+       rm -f /usr/${LIBDIR}/distcc/bin/*-wrapper
 }
 
 cleanup_icecream() {
        LIBDIR=$(get_libdir)
        for i in cc gcc c++ g++; do
-               rm /usr/${LIBDIR}/icecc/bin/${i}
+               rm -f /usr/${LIBDIR}/icecc/bin/${i}
                ln -s /usr/bin/icecc /usr/${LIBDIR}/icecc/bin/${i}
        done
-       rm /usr/${LIBDIR}/icecc/bin/*-wrapper
+       rm -f /usr/${LIBDIR}/icecc/bin/*-wrapper
+}
+
+cleanup_stages() {
+       make_destpath
+       if [ -n "${clst_DISTCC}" ]
+       then
+               cleanup_distcc
+       fi
+       if [ -n "${clst_ICECREAM}" ]
+       then
+               cleanup_icecream
+       fi
+       case ${clst_target} in
+               stage3|system)
+                       run_merge --depclean --with-bdeps=n
+                       ;;
+               *)
+                       echo "Skipping depclean operation for ${clst_target}"
+                       ;;
+       esac
+       case ${clst_target} in
+               stage1|stage2|stage3|system)
+                       rm -f /var/lib/portage/world
+                       touch /var/lib/portage/world
+                       ;;
+               *)
+                       echo "Skipping removal of world file for ${clst_target}"
+                       ;;
+       esac
+
+       rm -f /var/log/emerge.log /var/log/portage/elog/*
 }
 
 update_env_settings(){
-       /usr/sbin/env-update
+       [ -x /usr/sbin/env-update ] && /usr/sbin/env-update
        source /etc/profile
        [ -f /tmp/envscript ] && source /tmp/envscript
 }
@@ -204,19 +232,21 @@ die() {
 }
 
 make_destpath() {
-       if  [ "${1}" = "" ]
+       # ROOT is / by default, so remove any ROOT= settings from make.conf
+       sed -i '/ROOT=/d' /etc/make.conf
+       export ROOT=/
+       if [ "${1}" != "/" -a -n "${1}" ] 
        then
-               export ROOT=/
-       else
+               echo "ROOT=\"${1}\"" >> /etc/make.conf
                export ROOT=${1}
-               if [ ! -d ${ROOT} ]
-               then
-                       install -d ${ROOT}
-               fi
+       fi
+       if [ ! -d ${ROOT} ]
+       then
+               install -d ${ROOT}
        fi
 }
 
-run_emerge() {
+run_merge() {
        # Sets up the ROOT= parameter
        # with no options ROOT=/
        make_destpath ${clst_root_path}
@@ -245,6 +275,51 @@ run_emerge() {
        emerge ${clst_myemergeopts} $@ || exit 1
 }
 
+show_debug() {
+       if [ "${clst_DEBUG}" = "1" ]
+       then
+               unset PACKAGES
+               echo "DEBUG:"
+               echo "Profile/target info:"
+               echo "Profile inheritance:"
+               python -c 'import portage; print portage.settings.profiles'
+               echo
+               # TODO: make this work on non-portage
+               emerge --info
+               # TODO: grab our entire env
+               # <zmedico> to get see the ebuild env you can do something like:
+               # `set > /tmp/env_dump.${EBUILD_PHASE}` inside /etc/portage/bashrc
+               # XXX: Also, portageq does *not* source profile.bashrc at any time.
+               echo
+               echo "STAGE1_USE:            $(portageq envvar STAGE1_USE)"
+               echo
+               echo "USE (profile):         $(portageq envvar USE)"
+               echo "FEATURES (profile):    $(portageq envvar FEATURES)"
+               echo
+               echo "ARCH:                  $(portageq envvar ARCH)"
+               echo "CHOST:                 $(portageq envvar CHOST)"
+               echo "CFLAGS:                $(portageq envvar CFLAGS)"
+               echo
+               echo "These should be blank on non-multilib profiles."
+               echo "ABI:                   $(portageq envvar ABI)"
+               echo "DEFAULT_ABI:           $(portageq envvar DEFAULT_ABI)"
+               echo "KERNEL_ABI:            $(portageq envvar KERNEL_ABI)"
+               echo "LIBDIR:                $(get_libdir)"
+               echo "MULTILIB_ABIS:         $(portageq envvar MULTILIB_ABIS)"
+               echo "PROFILE_ARCH:          $(portageq envvar PROFILE_ARCH)"
+               echo
+       fi
+}
+
+run_default_funcs() {
+       if [ "${RUN_DEFAULT_FUNCS}" != "no" ]
+       then
+               update_env_settings
+               setup_myfeatures
+               show_debug
+       fi
+}
+
 # Functions
 # Copy libs of a executable in the chroot
 function copy_libs() {
@@ -285,9 +360,9 @@ function copy_symlink() {
                cp -vfdp ${1} ${clst_root_path}/${1}
        
        if [[ -n $(type -p realpath) ]]; then
-           TARGET=`realpath ${1}`
+               TARGET=`realpath ${1}`
        else
-           TARGET=`readlink -f ${1}`
+               TARGET=`readlink -f ${1}`
        fi
        if [ -h ${TARGET} ]
        then
@@ -333,3 +408,7 @@ GenericName=Gentoo Linux Handbook
 Comment=This is a link to the local copy of the Gentoo Linux Handbook.
 Icon=text-editor" > /usr/share/applications/gentoo-handbook.desktop
 }
+
+# We do this everywhere, so why not put it in this script
+run_default_funcs
+