3 # Trap these signals and kill ourselves if recieved
4 # Force ourselves to die if any of these signals are recieved
5 # most likely our controlling terminal is gone
6 trap "echo SIGTERM signal recieved killing $0 with pid $$;kill -9 $$" SIGTERM
7 trap "echo SIGHUP signal recieved killing $0 with pid $$;kill -9 $$" SIGHUP
8 trap "echo SIGKILL signal recieved killing $0 with pid $$;kill -9 $$" SIGKILL
10 #SIGINT interrupt character (usually Ctrl-C)
11 # * example: high-level sequence of events
12 # * my process (call it "P") is running
14 # * kernel recognizes this and generates SIGINT signal
15 trap "echo SIGINT signal recieved killing $0 with pid $$;kill -9 $$" SIGINT
17 check_genkernel_version(){
18 if [ -x /usr/bin/genkernel ]
20 genkernel_version=$(genkernel --version)
21 genkernel_version_major=${genkernel_version%%.*}
22 genkernel_version_minor_sub=${genkernel_version#${genkernel_version_major}.}
23 genkernel_version_minor=${genkernel_version_minor_sub%%.*}
24 genkernel_version_sub=${genkernel_version##*.}
25 if [ -n "${genkernel_version}" -a "${genkernel_version_major}" -eq '3' -a "${genkernel_version_minor}" -ge '3' ]
27 echo "Genkernel version ${genkernel_version} found ... continuing"
29 echo "ERROR: Your genkernel version is too low in your seed stage. genkernel version 3.3.0"
30 echo "or greater is required."
39 ABI=$(portageq envvar ABI)
40 DEFAULT_ABI=$(portageq envvar DEFAULT_ABI)
41 LIBDIR_default=$(portageq envvar LIBDIR_default)
50 elif [ -n "${DEFAULT_ABI}" ]
57 local var="LIBDIR_${abi}"
58 var=$(portageq envvar ${var})
64 if [ -n "${clst_CCACHE}" ]
66 export clst_myfeatures="${clst_myfeatures} ccache"
67 #if [ "${clst_AUTORESUME}" = "1" -a -e /tmp/.clst_ccache ]
69 # echo "CCACHE Autoresume point found not emerging ccache"
71 clst_root_path=/ run_emerge --oneshot --nodeps ccache || exit 1
72 # touch /tmp/.clst_ccache
76 if [ -n "${clst_DISTCC}" ]
78 export clst_myfeatures="${clst_myfeatures} distcc"
79 export DISTCC_HOSTS="${clst_distcc_hosts}"
80 #if [ "${clst_AUTORESUME}" = "1" -a -e /tmp/.clst_distcc ]
82 # echo "DISTCC Autoresume point found not emerging distcc"
84 USE="-gtk -gnome" clst_root_path=/ run_emerge --oneshot --nodeps distcc || exit 1
85 #touch /tmp/.clst_distcc
88 echo "${clst_distcc_hosts}" > /etc/distcc/hosts
90 # This sets up automatic cross-distcc-fu according to
91 # http://www.gentoo.org/doc/en/cross-compiling-distcc.xml
92 CHOST=$(portageq envvar CHOST)
93 # TODO: change to use get_libdir
94 cd /usr/lib/distcc/bin
95 rm cc gcc g++ c++ 2>/dev/null
96 echo -e '#!/bin/bash\nexec /usr/lib/distcc/bin/'${CHOST}'-g${0:$[-2]} "$@"' > ${CHOST}-wrapper
97 chmod a+x /usr/lib/distcc/bin/${CHOST}-wrapper
98 for i in cc gcc g++ c++; do ln -s ${CHOST}-wrapper ${i}; done
101 if [ -n "${clst_ICECREAM}" ]
103 clst_root_path=/ run_emerge --oneshot --nodeps sys-devel/icecream || exit 1
105 # This sets up automatic cross-icecc-fu according to
106 # http://gentoo-wiki.com/HOWTO_Setup_An_ICECREAM_Compile_Cluster#Icecream_and_cross-compiling
107 CHOST=$(portageq envvar CHOST)
109 cd /usr/${LIBDIR}/icecc/bin
110 rm cc gcc g++ c++ 2>/dev/null
111 echo -e '#!/bin/bash\nexec /usr/'${LIBDIR}'/icecc/bin/'${CHOST}'-g${0:$[-2]} "$@"' > ${CHOST}-wrapper
112 chmod a+x ${CHOST}-wrapper
113 for i in cc gcc g++ c++; do ln -s ${CHOST}-wrapper ${i}; done
114 export PATH="/usr/lib/icecc/bin:${PATH}"
115 export PREROOTPATH="/usr/lib/icecc/bin"
117 export FEATURES="${clst_myfeatures}"
120 setup_myemergeopts(){
121 if [ -n "${clst_VERBOSE}" ]
123 clst_myemergeopts="--verbose"
125 clst_myemergeopts="--quiet"
127 if [ -n "${clst_FETCH}" ]
129 export bootstrap_opts="-f"
130 export clst_myemergeopts="${clst_myemergeopts} -f"
131 elif [ -n "${clst_PKGCACHE}" ]
133 export clst_myemergeopts="${clst_myemergeopts} --usepkg --buildpkg --newuse"
134 export bootstrap_opts="-r"
139 # portage needs to be merged manually with USE="build" set to avoid frying
140 # our make.conf. emerge system could merge it otherwise.
141 # if [ "${clst_AUTORESUME}" = "1" -a -e /tmp/.clst_portage ]
143 # echo "Portage Autoresume point found not emerging portage"
145 USE="build" run_emerge --oneshot --nodeps portage
146 # touch /tmp/.clst_portage || exit 1
151 if [ -x /usr/bin/gcc-config ]
153 mythang=$( cd /etc/env.d/gcc; ls ${clst_CHOST}-* | head -n 1 )
154 if [ -z "${mythang}" ]
158 gcc-config ${mythang}; update_env_settings
163 if [ -x /usr/bin/binutils-config ]
165 mythang=$( cd /etc/env.d/binutils; ls ${clst_CHOST}-* | head -n 1 )
166 if [ -z "${mythang}" ]
170 binutils-config ${mythang}; update_env_settings
175 rm -rf /etc/distcc/hosts
176 for i in cc gcc c++ g++; do
177 # TODO: change to use get_libdir
178 rm -f /usr/lib/distcc/bin/${i}
179 ln -s /usr/bin/distcc /usr/lib/distcc/bin/${i}
181 rm -f /usr/lib/distcc/bin/*-wrapper
186 for i in cc gcc c++ g++; do
187 rm -f /usr/${LIBDIR}/icecc/bin/${i}
188 ln -s /usr/bin/icecc /usr/${LIBDIR}/icecc/bin/${i}
190 rm -f /usr/${LIBDIR}/icecc/bin/*-wrapper
194 if [ -n "${clst_DISTCC}" ]
198 if [ -n "${clst_ICECREAM}" ]
202 case ${clst_target} in
203 stage1|stage2|stage3)
204 rm -f /var/lib/portage/world
205 touch /var/lib/portage/world
208 echo "Skipping removal of world file for ${clst_target}"
212 rm -f /var/log/emerge.log /var/log/portage/elog/*
216 update_env_settings(){
217 which env-update > /dev/null 2>&1
221 ENV_UPDATE=`which env-update`
224 echo "WARNING: env-update not found, skipping!"
227 [ -f /tmp/envscript ] && source /tmp/envscript
249 # Sets up the ROOT= parameter
250 # with no options ROOT=/
251 make_destpath ${clst_root_path}
253 export EMERGE_WARNING_DELAY=0
255 export EBEEP_IGNORE=0
256 export EPAUSE_IGNORE=0
257 export CONFIG_PROTECT="-*"
259 if [ -n "${clst_VERBOSE}" ]
261 echo "ROOT=${ROOT} emerge ${clst_myemergeopts} -pt $@" || exit 1
262 emerge ${clst_myemergeopts} -pt $@ || exit 3
263 echo "Press any key within 15 seconds to pause the build..."
267 echo "Press any key to continue..."
272 echo "emerge ${clst_myemergeopts} $@" || exit 1
274 emerge ${clst_myemergeopts} $@ || exit 1
278 if [ "${clst_DEBUG}" = "1" ]
282 echo "Profile/target info:"
283 echo "Profile inheritance:"
284 python -c 'import portage; print portage.settings.profiles'
285 # TODO: grab our entire env
286 # <zmedico> to get see the ebuild env you can do something like:
287 # `set > /tmp/env_dump.${EBUILD_PHASE}` inside /etc/portage/bashrc
289 echo "STAGE1_USE: $(portageq envvar STAGE1_USE)"
291 echo "USE (profile): $(portageq envvar USE)"
292 echo "USE (stage1): ${USE}"
293 echo "FEATURES (profile): $(portageq envvar FEATURES)"
294 echo "FEATURES (stage1): ${FEATURES}"
296 echo "ARCH: $(portageq envvar ARCH)"
297 echo "CHOST: $(portageq envvar CHOST)"
298 echo "CFLAGS: $(portageq envvar CFLAGS)"
300 echo "PROFILE_ARCH: $(portageq envvar PROFILE_ARCH)"
302 echo "ABI: $(portageq envvar ABI)"
303 echo "DEFAULT_ABI: $(portageq envvar DEFAULT_ABI)"
304 echo "KERNEL_ABI: $(portageq envvar KERNEL_ABI)"
305 echo "MULTILIB_ABIS: $(portageq envvar MULTILIB_ABIS)"
310 run_default_funcs() {
311 if [ "${RUN_DEFAULT_FUNCS}" != "no" ]
320 # Copy libs of a executable in the chroot
321 function copy_libs() {
322 # Check if it's a dynamix exec
323 ldd ${1} > /dev/null 2>&1 || return
325 for lib in `ldd ${1} | awk '{ print $3 }'`
330 if [ ! -e ${clst_root_path}/${lib} ]
333 [ -e "${clst_root_path}/${lib}" ] && \
334 strip -R .comment -R .note ${clst_root_path}/${lib} \
335 || echo "WARNING : Cannot strip lib ${clst_root_path}/${lib} !"
338 echo "WARNING : Some library was not found for ${lib} !"
343 function copy_symlink() {
345 [ "${STACK}" = "" ] && STACK=16 || STACK=$((${STACK} - 1 ))
347 if [ ${STACK} -le 0 ]
349 echo "WARNING : ${TARGET} : too many levels of symbolic links !"
353 [ ! -e ${clst_root_path}/`dirname ${1}` ] && \
354 mkdir -p ${clst_root_path}/`dirname ${1}`
355 [ ! -e ${clst_root_path}/${1} ] && \
356 cp -vfdp ${1} ${clst_root_path}/${1}
358 if [[ -n $(type -p realpath) ]]; then
359 TARGET=`realpath ${1}`
361 TARGET=`readlink -f ${1}`
365 copy_symlink ${TARGET} ${STACK}
371 function copy_file() {
376 echo "WARNING : File not found : ${f}"
380 [ ! -e ${clst_root_path}/`dirname ${f}` ] && \
381 mkdir -p ${clst_root_path}/`dirname ${f}`
382 [ ! -e ${clst_root_path}/${f} ] && \
383 cp -vfdp ${f} ${clst_root_path}/${f}
384 if [ -x ${f} -a ! -h ${f} ]
387 strip -R .comment -R .note ${clst_root_path}/${f} > /dev/null 2>&1
394 create_handbook_icon() {
395 # This function creates a local icon to the Gentoo Handbook
396 echo "[Desktop Entry]
400 URL=file:///mnt/cdrom/docs/handbook/html/index.html
402 Name=Gentoo Linux Handbook
403 GenericName=Gentoo Linux Handbook
404 Comment=This is a link to the local copy of the Gentoo Linux Handbook.
405 Icon=text-editor" > /usr/share/applications/gentoo-handbook.desktop
408 # We do this everywhere, so why not put it in this script