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 clst_root_path=/ run_merge --oneshot --nodeps --noreplace dev-util/ccache || exit 1
70 if [ -n "${clst_DISTCC}" ]
72 export clst_myfeatures="${clst_myfeatures} distcc"
73 export DISTCC_HOSTS="${clst_distcc_hosts}"
74 [ -e /etc/make.conf ] && \
75 echo 'USE="${USE} -avahi -gtk -gnome"' >> /etc/make.conf
76 # We install distcc to / on stage1, then use --noreplace, so we need to
77 # have some way to check if we need to reinstall distcc without being
78 # able to rely on USE, so we check for the distcc user and force a
79 # reinstall if it isn't found.
80 if [ "$(getent passwd distcc | cut -d: -f1)" != "distcc" ]
82 clst_root_path=/ run_merge --oneshot --nodeps sys-devel/distcc || exit 1
84 clst_root_path=/ run_merge --oneshot --nodeps --noreplace sys-devel/distcc || exit 1
86 sed -i '/USE="${USE} -avahi -gtk -gnome"/d' /etc/make.conf
88 echo "${clst_distcc_hosts}" > /etc/distcc/hosts
89 # We need to run distcc-config, since it might not have gotten run
90 [ -x /usr/bin/distcc-config ] && /usr/bin/distcc-config --install
92 # This sets up automatic cross-distcc-fu according to
93 # http://www.gentoo.org/doc/en/cross-compiling-distcc.xml
94 CHOST=$(portageq envvar CHOST)
96 cd /usr/${LIBDIR}/distcc/bin
97 rm cc gcc g++ c++ 2>/dev/null
98 echo -e '#!/bin/bash\nexec /usr/'${LIBDIR}'/distcc/bin/'${CHOST}'-g${0:$[-2]} "$@"' > ${CHOST}-wrapper
99 chmod a+x /usr/${LIBDIR}/distcc/bin/${CHOST}-wrapper
100 for i in cc gcc g++ c++; do ln -s ${CHOST}-wrapper ${i}; done
103 if [ -n "${clst_ICECREAM}" ]
105 clst_root_path=/ run_merge --oneshot --nodeps --noreplace sys-devel/icecream || exit 1
107 # This sets up automatic cross-icecc-fu according to
108 # http://gentoo-wiki.com/HOWTO_Setup_An_ICECREAM_Compile_Cluster#Icecream_and_cross-compiling
109 CHOST=$(portageq envvar CHOST)
111 cd /usr/${LIBDIR}/icecc/bin
112 rm cc gcc g++ c++ 2>/dev/null
113 echo -e '#!/bin/bash\nexec /usr/'${LIBDIR}'/icecc/bin/'${CHOST}'-g${0:$[-2]} "$@"' > ${CHOST}-wrapper
114 chmod a+x ${CHOST}-wrapper
115 for i in cc gcc g++ c++; do ln -s ${CHOST}-wrapper ${i}; done
116 export PATH="/usr/lib/icecc/bin:${PATH}"
117 export PREROOTPATH="/usr/lib/icecc/bin"
119 export FEATURES="${clst_myfeatures} -news"
122 setup_myemergeopts(){
123 if [ -n "${clst_VERBOSE}" ]
125 clst_myemergeopts="--verbose"
127 clst_myemergeopts="--quiet"
128 bootstrap_opts="${bootstrap_opts} -q"
130 if [ -n "${clst_FETCH}" ]
132 export bootstrap_opts="${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="${bootstrap_opts} -r"
142 if [ -x /usr/bin/binutils-config ]
144 mythang=$( cd /etc/env.d/binutils; ls ${clst_CHOST}-* | head -n 1 )
145 if [ -z "${mythang}" ]
149 binutils-config ${mythang}; update_env_settings
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 # We need to merge our package manager with USE="build" set in case it is
167 # portage to avoid frying our /etc/make.conf file. Otherwise, we could
168 # just let emerge system could merge it.
169 [ -e /etc/make.conf ] && echo 'USE="${USE} build"' >> /etc/make.conf
170 run_merge --oneshot --nodeps sys-apps/portage
171 sed -i '/USE="${USE} build"/d' /etc/make.conf
176 rm -rf /etc/distcc/hosts
177 for i in cc gcc c++ g++; do
178 rm -f /usr/${LIBDIR}/distcc/bin/${i}
179 ln -s /usr/bin/distcc /usr/${LIBDIR}/distcc/bin/${i}
181 rm -f /usr/${LIBDIR}/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
195 if [ -n "${clst_DISTCC}" ]
199 if [ -n "${clst_ICECREAM}" ]
203 case ${clst_target} in
205 run_merge --depclean --with-bdeps=n
208 echo "Skipping depclean operation for ${clst_target}"
211 case ${clst_target} in
212 stage1|stage2|stage3)
213 rm -f /var/lib/portage/world
214 touch /var/lib/portage/world
217 echo "Skipping removal of world file for ${clst_target}"
221 rm -f /var/log/emerge.log /var/log/portage/elog/*
224 update_env_settings(){
225 [ -x /usr/sbin/env-update ] && /usr/sbin/env-update
227 [ -f /tmp/envscript ] && source /tmp/envscript
236 # ROOT is / by default, so remove any ROOT= settings from make.conf
237 sed -i '/ROOT=/d' /etc/make.conf
239 if [ "${1}" != "/" -a -n "${1}" ]
241 echo "ROOT=\"${1}\"" >> /etc/make.conf
251 # Sets up the ROOT= parameter
252 # with no options ROOT=/
253 make_destpath ${clst_root_path}
255 export EMERGE_WARNING_DELAY=0
257 export EBEEP_IGNORE=0
258 export EPAUSE_IGNORE=0
259 export CONFIG_PROTECT="-*"
261 if [ -n "${clst_VERBOSE}" ]
263 echo "ROOT=${ROOT} emerge ${clst_myemergeopts} -pt $@" || exit 1
264 emerge ${clst_myemergeopts} -pt $@ || exit 3
265 echo "Press any key within 15 seconds to pause the build..."
269 echo "Press any key to continue..."
274 echo "emerge ${clst_myemergeopts} $@" || exit 1
276 emerge ${clst_myemergeopts} $@ || exit 1
280 if [ "${clst_DEBUG}" = "1" ]
284 echo "Profile/target info:"
285 echo "Profile inheritance:"
286 python -c 'import portage; print portage.settings.profiles'
288 # TODO: make this work on non-portage
290 # TODO: grab our entire env
291 # <zmedico> to get see the ebuild env you can do something like:
292 # `set > /tmp/env_dump.${EBUILD_PHASE}` inside /etc/portage/bashrc
293 # XXX: Also, portageq does *not* source profile.bashrc at any time.
295 echo "STAGE1_USE: $(portageq envvar STAGE1_USE)"
297 echo "USE (profile): $(portageq envvar USE)"
298 echo "FEATURES (profile): $(portageq envvar FEATURES)"
300 echo "ARCH: $(portageq envvar ARCH)"
301 echo "CHOST: $(portageq envvar CHOST)"
302 echo "CFLAGS: $(portageq envvar CFLAGS)"
304 echo "These should be blank on non-multilib profiles."
305 echo "ABI: $(portageq envvar ABI)"
306 echo "DEFAULT_ABI: $(portageq envvar DEFAULT_ABI)"
307 echo "KERNEL_ABI: $(portageq envvar KERNEL_ABI)"
308 echo "LIBDIR: $(get_libdir)"
309 echo "MULTILIB_ABIS: $(portageq envvar MULTILIB_ABIS)"
310 echo "PROFILE_ARCH: $(portageq envvar PROFILE_ARCH)"
315 run_default_funcs() {
316 if [ "${RUN_DEFAULT_FUNCS}" != "no" ]
325 # Copy libs of a executable in the chroot
326 function copy_libs() {
327 # Check if it's a dynamix exec
328 ldd ${1} > /dev/null 2>&1 || return
330 for lib in `ldd ${1} | awk '{ print $3 }'`
335 if [ ! -e ${clst_root_path}/${lib} ]
338 [ -e "${clst_root_path}/${lib}" ] && \
339 strip -R .comment -R .note ${clst_root_path}/${lib} \
340 || echo "WARNING : Cannot strip lib ${clst_root_path}/${lib} !"
343 echo "WARNING : Some library was not found for ${lib} !"
348 function copy_symlink() {
350 [ "${STACK}" = "" ] && STACK=16 || STACK=$((${STACK} - 1 ))
352 if [ ${STACK} -le 0 ]
354 echo "WARNING : ${TARGET} : too many levels of symbolic links !"
358 [ ! -e ${clst_root_path}/`dirname ${1}` ] && \
359 mkdir -p ${clst_root_path}/`dirname ${1}`
360 [ ! -e ${clst_root_path}/${1} ] && \
361 cp -vfdp ${1} ${clst_root_path}/${1}
363 if [[ -n $(type -p realpath) ]]; then
364 TARGET=`realpath ${1}`
366 TARGET=`readlink -f ${1}`
370 copy_symlink ${TARGET} ${STACK}
376 function copy_file() {
381 echo "WARNING : File not found : ${f}"
385 [ ! -e ${clst_root_path}/`dirname ${f}` ] && \
386 mkdir -p ${clst_root_path}/`dirname ${f}`
387 [ ! -e ${clst_root_path}/${f} ] && \
388 cp -vfdp ${f} ${clst_root_path}/${f}
389 if [ -x ${f} -a ! -h ${f} ]
392 strip -R .comment -R .note ${clst_root_path}/${f} > /dev/null 2>&1
399 create_handbook_icon() {
400 # This function creates a local icon to the Gentoo Handbook
401 echo "[Desktop Entry]
405 URL=file:///mnt/cdrom/docs/handbook/html/index.html
407 Name=Gentoo Linux Handbook
408 GenericName=Gentoo Linux Handbook
409 Comment=This is a link to the local copy of the Gentoo Linux Handbook.
410 Icon=text-editor" > /usr/share/applications/gentoo-handbook.desktop
413 # We do this everywhere, so why not put it in this script