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 /usr/lib/distcc/bin/${i}
182 ln -s /usr/bin/distcc /usr/lib/distcc/bin/${i}
184 rm /usr/lib/distcc/bin/*-wrapper
189 for i in cc gcc c++ g++; do
190 rm /usr/${LIBDIR}/icecc/bin/${i}
191 ln -s /usr/bin/icecc /usr/${LIBDIR}/icecc/bin/${i}
193 rm /usr/${LIBDIR}/icecc/bin/*-wrapper
196 update_env_settings(){
199 [ -f /tmp/envscript ] && source /tmp/envscript
221 # Sets up the ROOT= parameter
222 # with no options ROOT=/
223 make_destpath ${clst_root_path}
225 export EMERGE_WARNING_DELAY=0
227 export EBEEP_IGNORE=0
228 export EPAUSE_IGNORE=0
229 export CONFIG_PROTECT="-*"
231 if [ -n "${clst_VERBOSE}" ]
233 echo "ROOT=${ROOT} emerge ${clst_myemergeopts} -pt $@" || exit 1
234 emerge ${clst_myemergeopts} -pt $@ || exit 3
235 echo "Press any key within 15 seconds to pause the build..."
239 echo "Press any key to continue..."
244 echo "emerge ${clst_myemergeopts} $@" || exit 1
246 emerge ${clst_myemergeopts} $@ || exit 1
250 if [ "${clst_DEBUG}" = "1" ]
253 echo "Profile inheritance:"
254 python -c 'import portage; print portage.settings.profiles'
256 echo "STAGE1_USE: $(portageq envvar STAGE1_USE)"
258 echo "USE (profile): $(portageq envvar USE)"
259 echo "USE (stage1): ${USE}"
260 echo "FEATURES (profile): $(portageq envvar FEATURES)"
261 echo "FEATURES (stage1): ${FEATURES}"
263 echo "ARCH: $(portageq envvar ARCH)"
264 echo "CHOST: $(portageq envvar CHOST)"
265 echo "CFLAGS: $(portageq envvar CFLAGS)"
267 echo "PROFILE_ARCH: $(portageq envvar PROFILE_ARCH)"
269 echo "ABI: $(portageq envvar ABI)"
270 echo "DEFAULT_ABI: $(portageq envvar DEFAULT_ABI)"
271 echo "KERNEL_ABI: $(portageq envvar KERNEL_ABI)"
272 echo "MULTILIB_ABIS: $(portageq envvar MULTILIB_ABIS)"
277 run_default_funcs() {
278 if [ -z "${RUN_DEFAULT_FUNCS}" ]
287 # Copy libs of a executable in the chroot
288 function copy_libs() {
289 # Check if it's a dynamix exec
290 ldd ${1} > /dev/null 2>&1 || return
292 for lib in `ldd ${1} | awk '{ print $3 }'`
297 if [ ! -e ${clst_root_path}/${lib} ]
300 [ -e "${clst_root_path}/${lib}" ] && \
301 strip -R .comment -R .note ${clst_root_path}/${lib} \
302 || echo "WARNING : Cannot strip lib ${clst_root_path}/${lib} !"
305 echo "WARNING : Some library was not found for ${lib} !"
310 function copy_symlink() {
312 [ "${STACK}" = "" ] && STACK=16 || STACK=$((${STACK} - 1 ))
314 if [ ${STACK} -le 0 ]
316 echo "WARNING : ${TARGET} : too many levels of symbolic links !"
320 [ ! -e ${clst_root_path}/`dirname ${1}` ] && \
321 mkdir -p ${clst_root_path}/`dirname ${1}`
322 [ ! -e ${clst_root_path}/${1} ] && \
323 cp -vfdp ${1} ${clst_root_path}/${1}
325 if [[ -n $(type -p realpath) ]]; then
326 TARGET=`realpath ${1}`
328 TARGET=`readlink -f ${1}`
332 copy_symlink ${TARGET} ${STACK}
338 function copy_file() {
343 echo "WARNING : File not found : ${f}"
347 [ ! -e ${clst_root_path}/`dirname ${f}` ] && \
348 mkdir -p ${clst_root_path}/`dirname ${f}`
349 [ ! -e ${clst_root_path}/${f} ] && \
350 cp -vfdp ${f} ${clst_root_path}/${f}
351 if [ -x ${f} -a ! -h ${f} ]
354 strip -R .comment -R .note ${clst_root_path}/${f} > /dev/null 2>&1
361 create_handbook_icon() {
362 # This function creates a local icon to the Gentoo Handbook
363 echo "[Desktop Entry]
367 URL=file:///mnt/cdrom/docs/handbook/html/index.html
369 Name=Gentoo Linux Handbook
370 GenericName=Gentoo Linux Handbook
371 Comment=This is a link to the local copy of the Gentoo Linux Handbook.
372 Icon=text-editor" > /usr/share/applications/gentoo-handbook.desktop