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 /usr/lib/distcc/bin/${i}
179 ln -s /usr/bin/distcc /usr/lib/distcc/bin/${i}
181 rm /usr/lib/distcc/bin/*-wrapper
186 for i in cc gcc c++ g++; do
187 rm /usr/${LIBDIR}/icecc/bin/${i}
188 ln -s /usr/bin/icecc /usr/${LIBDIR}/icecc/bin/${i}
190 rm /usr/${LIBDIR}/icecc/bin/*-wrapper
193 update_env_settings(){
196 [ -f /tmp/envscript ] && source /tmp/envscript
218 # Sets up the ROOT= parameter
219 # with no options ROOT=/
220 make_destpath ${clst_root_path}
222 export EMERGE_WARNING_DELAY=0
224 export EBEEP_IGNORE=0
225 export EPAUSE_IGNORE=0
226 export CONFIG_PROTECT="-*"
228 if [ -n "${clst_VERBOSE}" ]
230 echo "ROOT=${ROOT} emerge ${clst_myemergeopts} -pt $@" || exit 1
231 emerge ${clst_myemergeopts} -pt $@ || exit 3
232 echo "Press any key within 15 seconds to pause the build..."
236 echo "Press any key to continue..."
241 echo "emerge ${clst_myemergeopts} $@" || exit 1
243 emerge ${clst_myemergeopts} $@ || exit 1
247 # Copy libs of a executable in the chroot
248 function copy_libs() {
249 # Check if it's a dynamix exec
250 ldd ${1} > /dev/null 2>&1 || return
252 for lib in `ldd ${1} | awk '{ print $3 }'`
257 if [ ! -e ${clst_root_path}/${lib} ]
260 [ -e "${clst_root_path}/${lib}" ] && \
261 strip -R .comment -R .note ${clst_root_path}/${lib} \
262 || echo "WARNING : Cannot strip lib ${clst_root_path}/${lib} !"
265 echo "WARNING : Some library was not found for ${lib} !"
270 function copy_symlink() {
272 [ "${STACK}" = "" ] && STACK=16 || STACK=$((${STACK} - 1 ))
274 if [ ${STACK} -le 0 ]
276 echo "WARNING : ${TARGET} : too many levels of symbolic links !"
280 [ ! -e ${clst_root_path}/`dirname ${1}` ] && \
281 mkdir -p ${clst_root_path}/`dirname ${1}`
282 [ ! -e ${clst_root_path}/${1} ] && \
283 cp -vfdp ${1} ${clst_root_path}/${1}
285 if [[ -n $(type -p realpath) ]]; then
286 TARGET=`realpath ${1}`
288 TARGET=`readlink -f ${1}`
292 copy_symlink ${TARGET} ${STACK}
298 function copy_file() {
303 echo "WARNING : File not found : ${f}"
307 [ ! -e ${clst_root_path}/`dirname ${f}` ] && \
308 mkdir -p ${clst_root_path}/`dirname ${f}`
309 [ ! -e ${clst_root_path}/${f} ] && \
310 cp -vfdp ${f} ${clst_root_path}/${f}
311 if [ -x ${f} -a ! -h ${f} ]
314 strip -R .comment -R .note ${clst_root_path}/${f} > /dev/null 2>&1
321 create_handbook_icon() {
322 # This function creates a local icon to the Gentoo Handbook
323 echo "[Desktop Entry]
327 URL=file:///mnt/cdrom/docs/handbook/html/index.html
329 Name=Gentoo Linux Handbook
330 GenericName=Gentoo Linux Handbook
331 Comment=This is a link to the local copy of the Gentoo Linux Handbook.
332 Icon=text-editor" > /usr/share/applications/gentoo-handbook.desktop