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 # We do this everywhere, so why not put it in this script
20 check_genkernel_version(){
21 if [ -x /usr/bin/genkernel ]
23 genkernel_version=$(genkernel --version)
24 genkernel_version_major=${genkernel_version%%.*}
25 genkernel_version_minor_sub=${genkernel_version#${genkernel_version_major}.}
26 genkernel_version_minor=${genkernel_version_minor_sub%%.*}
27 genkernel_version_sub=${genkernel_version##*.}
28 if [ -n "${genkernel_version}" -a "${genkernel_version_major}" -eq '3' -a "${genkernel_version_minor}" -ge '3' ]
30 echo "Genkernel version ${genkernel_version} found ... continuing"
32 echo "ERROR: Your genkernel version is too low in your seed stage. genkernel version 3.3.0"
33 echo "or greater is required."
42 ABI=$(portageq envvar ABI)
43 DEFAULT_ABI=$(portageq envvar DEFAULT_ABI)
44 LIBDIR_default=$(portageq envvar LIBDIR_default)
53 elif [ -n "${DEFAULT_ABI}" ]
60 local var="LIBDIR_${abi}"
61 var=$(portageq envvar ${var})
67 if [ -n "${clst_CCACHE}" ]
69 export clst_myfeatures="${clst_myfeatures} ccache"
70 #if [ "${clst_AUTORESUME}" = "1" -a -e /tmp/.clst_ccache ]
72 # echo "CCACHE Autoresume point found not emerging ccache"
74 clst_root_path=/ run_emerge --oneshot --nodeps ccache || exit 1
75 # touch /tmp/.clst_ccache
79 if [ -n "${clst_DISTCC}" ]
81 export clst_myfeatures="${clst_myfeatures} distcc"
82 export DISTCC_HOSTS="${clst_distcc_hosts}"
83 #if [ "${clst_AUTORESUME}" = "1" -a -e /tmp/.clst_distcc ]
85 # echo "DISTCC Autoresume point found not emerging distcc"
87 USE="-gtk -gnome" clst_root_path=/ run_emerge --oneshot --nodeps distcc || exit 1
88 #touch /tmp/.clst_distcc
91 echo "${clst_distcc_hosts}" > /etc/distcc/hosts
93 # This sets up automatic cross-distcc-fu according to
94 # http://www.gentoo.org/doc/en/cross-compiling-distcc.xml
95 CHOST=$(portageq envvar CHOST)
96 # TODO: change to use get_libdir
97 cd /usr/lib/distcc/bin
98 rm cc gcc g++ c++ 2>/dev/null
99 echo -e '#!/bin/bash\nexec /usr/lib/distcc/bin/'${CHOST}'-g${0:$[-2]} "$@"' > ${CHOST}-wrapper
100 chmod a+x /usr/lib/distcc/bin/${CHOST}-wrapper
101 for i in cc gcc g++ c++; do ln -s ${CHOST}-wrapper ${i}; done
104 if [ -n "${clst_ICECREAM}" ]
106 clst_root_path=/ run_emerge --oneshot --nodeps sys-devel/icecream || exit 1
108 # This sets up automatic cross-icecc-fu according to
109 # http://gentoo-wiki.com/HOWTO_Setup_An_ICECREAM_Compile_Cluster#Icecream_and_cross-compiling
110 CHOST=$(portageq envvar CHOST)
112 cd /usr/${LIBDIR}/icecc/bin
113 rm cc gcc g++ c++ 2>/dev/null
114 echo -e '#!/bin/bash\nexec /usr/'${LIBDIR}'/icecc/bin/'${CHOST}'-g${0:$[-2]} "$@"' > ${CHOST}-wrapper
115 chmod a+x ${CHOST}-wrapper
116 for i in cc gcc g++ c++; do ln -s ${CHOST}-wrapper ${i}; done
117 export PATH="/usr/lib/icecc/bin:${PATH}"
118 export PREROOTPATH="/usr/lib/icecc/bin"
120 export FEATURES="${clst_myfeatures}"
123 setup_myemergeopts(){
124 if [ -n "${clst_VERBOSE}" ]
126 clst_myemergeopts="--verbose"
128 clst_myemergeopts="--quiet"
130 if [ -n "${clst_FETCH}" ]
132 export bootstrap_opts="-f"
133 export clst_myemergeopts="${clst_myemergeopts} -f"
134 elif [ -n "${clst_PKGCACHE}" ]
136 export clst_myemergeopts="${clst_myemergeopts} --usepkg --buildpkg --newuse"
137 export bootstrap_opts="-r"
142 # portage needs to be merged manually with USE="build" set to avoid frying
143 # our make.conf. emerge system could merge it otherwise.
144 # if [ "${clst_AUTORESUME}" = "1" -a -e /tmp/.clst_portage ]
146 # echo "Portage Autoresume point found not emerging portage"
148 USE="build" run_emerge --oneshot --nodeps portage
149 # touch /tmp/.clst_portage || exit 1
154 if [ -x /usr/bin/gcc-config ]
156 mythang=$( cd /etc/env.d/gcc; ls ${clst_CHOST}-* | head -n 1 )
157 if [ -z "${mythang}" ]
161 gcc-config ${mythang}; update_env_settings
166 if [ -x /usr/bin/binutils-config ]
168 mythang=$( cd /etc/env.d/binutils; ls ${clst_CHOST}-* | head -n 1 )
169 if [ -z "${mythang}" ]
173 binutils-config ${mythang}; update_env_settings
178 rm -rf /etc/distcc/hosts
179 for i in cc gcc c++ g++; do
180 # TODO: change to use get_libdir
181 rm -f /usr/lib/distcc/bin/${i}
182 ln -s /usr/bin/distcc /usr/lib/distcc/bin/${i}
184 rm -f /usr/lib/distcc/bin/*-wrapper
189 for i in cc gcc c++ g++; do
190 rm -f /usr/${LIBDIR}/icecc/bin/${i}
191 ln -s /usr/bin/icecc /usr/${LIBDIR}/icecc/bin/${i}
193 rm -f /usr/${LIBDIR}/icecc/bin/*-wrapper
197 if [ -n "${clst_DISTCC}" ]
201 if [ -n "${clst_ICECREAM}" ]
205 case ${clst_target} in
206 stage1|stage2|stage3)
207 rm -f /var/lib/portage/world
208 touch /var/lib/portage/world
211 echo "Skipping removal of world file for ${clst_target}"
215 rm -f /var/log/emerge.log /var/log/portage/elog/*
219 update_env_settings(){
220 which env-update > /dev/null 2>&1
224 ENV_UPDATE=`which env-update`
227 echo "WARNING: env-update not found, skipping!"
230 [ -f /tmp/envscript ] && source /tmp/envscript
252 # Sets up the ROOT= parameter
253 # with no options ROOT=/
254 make_destpath ${clst_root_path}
256 export EMERGE_WARNING_DELAY=0
258 export EBEEP_IGNORE=0
259 export EPAUSE_IGNORE=0
260 export CONFIG_PROTECT="-*"
262 if [ -n "${clst_VERBOSE}" ]
264 echo "ROOT=${ROOT} emerge ${clst_myemergeopts} -pt $@" || exit 1
265 emerge ${clst_myemergeopts} -pt $@ || exit 3
266 echo "Press any key within 15 seconds to pause the build..."
270 echo "Press any key to continue..."
275 echo "emerge ${clst_myemergeopts} $@" || exit 1
277 emerge ${clst_myemergeopts} $@ || exit 1
281 if [ "${clst_DEBUG}" = "1" ]
285 echo "Profile/target info:"
286 echo "Profile inheritance:"
287 python -c 'import portage; print portage.settings.profiles'
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)"
307 ### XXX: This is temporary until we make --debug force-enable --verbose
308 if [ -n "${clst_buildpkgs}" ]
310 PACKAGES=${clst_buildpkgs}
311 elif [ -n "${clst_packages}" ]
313 PACKAGES=${clst_packages}
315 if [ -n "${PACKAGES}" ]
321 ### XXX: end of section to remove
325 run_default_funcs() {
326 if [ -z "${RUN_DEFAULT_FUNCS}" ]
335 # Copy libs of a executable in the chroot
336 function copy_libs() {
337 # Check if it's a dynamix exec
338 ldd ${1} > /dev/null 2>&1 || return
340 for lib in `ldd ${1} | awk '{ print $3 }'`
345 if [ ! -e ${clst_root_path}/${lib} ]
348 [ -e "${clst_root_path}/${lib}" ] && \
349 strip -R .comment -R .note ${clst_root_path}/${lib} \
350 || echo "WARNING : Cannot strip lib ${clst_root_path}/${lib} !"
353 echo "WARNING : Some library was not found for ${lib} !"
358 function copy_symlink() {
360 [ "${STACK}" = "" ] && STACK=16 || STACK=$((${STACK} - 1 ))
362 if [ ${STACK} -le 0 ]
364 echo "WARNING : ${TARGET} : too many levels of symbolic links !"
368 [ ! -e ${clst_root_path}/`dirname ${1}` ] && \
369 mkdir -p ${clst_root_path}/`dirname ${1}`
370 [ ! -e ${clst_root_path}/${1} ] && \
371 cp -vfdp ${1} ${clst_root_path}/${1}
373 if [[ -n $(type -p realpath) ]]; then
374 TARGET=`realpath ${1}`
376 TARGET=`readlink -f ${1}`
380 copy_symlink ${TARGET} ${STACK}
386 function copy_file() {
391 echo "WARNING : File not found : ${f}"
395 [ ! -e ${clst_root_path}/`dirname ${f}` ] && \
396 mkdir -p ${clst_root_path}/`dirname ${f}`
397 [ ! -e ${clst_root_path}/${f} ] && \
398 cp -vfdp ${f} ${clst_root_path}/${f}
399 if [ -x ${f} -a ! -h ${f} ]
402 strip -R .comment -R .note ${clst_root_path}/${f} > /dev/null 2>&1
409 create_handbook_icon() {
410 # This function creates a local icon to the Gentoo Handbook
411 echo "[Desktop Entry]
415 URL=file:///mnt/cdrom/docs/handbook/html/index.html
417 Name=Gentoo Linux Handbook
418 GenericName=Gentoo Linux Handbook
419 Comment=This is a link to the local copy of the Gentoo Linux Handbook.
420 Icon=text-editor" > /usr/share/applications/gentoo-handbook.desktop