2 # Copyright 1999-2014 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
5 # people who were here:
6 # (drobbins, 06 Jun 2003)
10 # (wolf31o2, Jan 2005)
12 # (uberlord, May 2007)
14 # (williamh, Mar 2014)
18 [[ -e /etc/profile ]] && . /etc/profile
20 if [[ -e /lib/gentoo/functions.sh ]] ; then
21 source /lib/gentoo/functions.sh
22 elif [[ -e /etc/init.d/functions.sh ]] ; then
23 source /etc/init.d/functions.sh
25 eerror() { echo "!!! $*"; }
26 einfo() { echo "* $*"; }
29 # Use our own custom script, else logger cause things to
30 # 'freeze' if we do not have a system logger running
38 echo " [[ ($num/3) $* ]]"
41 # Track progress of the bootstrap process to allow for
42 # semi-transparent resuming
43 progressfile=/var/run/bootstrap-progress
44 [[ -e ${progressfile} ]] && source ${progressfile}
45 export BOOTSTRAP_STAGE=${BOOTSTRAP_STAGE:-1}
47 set_bootstrap_stage() {
48 [[ -z ${STRAP_RUN} ]] && return 0
49 export BOOTSTRAP_STAGE=$1
50 echo "BOOTSTRAP_STAGE=$1" > ${progressfile}
58 cvsver="$Id$" # TODO: FIXME for Git era
59 cvsver=${cvsver##*,v }
60 cvsver=${cvsver%%Exp*}
62 cvsyear=${cvsyear%%/*}
65 echo -e "Usage: ${HILITE}${0##*/}${NORMAL} ${GOOD}[options]${NORMAL}"
66 echo -e " ${GOOD}--debug (-d)${NORMAL} Run with debug information turned on"
67 echo -e " ${GOOD}--fetchonly (-f)${NORMAL} Just download all the source files"
68 echo -e " ${GOOD}--info (-i)${NORMAL} Show system related information"
69 echo -e " ${GOOD}--pretend (-p)${NORMAL} Display the packages that will be merged"
70 echo -e " ${GOOD}--quiet (-q)${NORMAL} Reduced or condensed output from portage's displays."
71 echo -e " ${GOOD}--tree (-t)${NORMAL} Display the dependency tree, forces -p"
72 echo -e " ${GOOD}--resume (-r)${NORMAL} Build/use binary packages"
75 STRAP_EMERGE_OPTS="--oneshot"
83 echo "Running in fetch-only mode ..."
84 STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -f"
89 --debug|-d) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --debug"; DEBUG=1;;
90 --info|-i) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --info" ; unset STRAP_RUN ;;
91 --pretend|-p) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -p" ; unset STRAP_RUN ;;
92 --quiet|-q) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -q" ; unset STRAP_RUN ;;
93 --tree|-t) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -p -t" ; unset STRAP_RUN ;;
94 --resume|-r) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --usepkg --buildpkg";;
95 --verbose|-v) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -v"; V_ECHO=v_echo;;
97 einfo "Gentoo Linux bootstrap ${cvsver}"
101 eerror "Unknown option '${opt}'"
108 if [[ -n ${STRAP_RUN} ]] ; then
109 if [ ${BOOTSTRAP_STAGE} -ge 3 ] ; then
111 einfo "System has been bootstrapped already!"
112 einfo "If you re-bootstrap the system, you must complete the entire bootstrap process"
113 einfo "otherwise you will have a broken system."
114 einfo "Press enter to continue or CTRL+C to abort ..."
116 set_bootstrap_stage 1
117 elif [ ${BOOTSTRAP_STAGE} -gt 1 ] ; then
118 einfo "Resuming bootstrap at internal stage #${BOOTSTRAP_STAGE} ..."
122 export BOOTSTRAP_STAGE=0
125 for p in /etc/portage /etc ; do
127 [[ -e ${p} ]] || continue
128 if type -P realpath >/dev/null ; then
129 MYPROFILEDIR=$(realpath ${p})
131 MYPROFILEDIR=$(readlink -f ${p})
134 if [[ ! -d ${MYPROFILEDIR} ]] ; then
135 eerror "Error: '${MYPROFILEDIR}' does not exist. Exiting."
139 echo -e "\n${GOOD}Gentoo Linux; ${BRACKET}http://www.gentoo.org/${NORMAL}"
140 echo -e "Copyright 1999-${cvsyear} Gentoo Foundation; Distributed under the GPLv2"
141 if [[ " ${STRAP_EMERGE_OPTS} " == *" -f "* ]] ; then
142 echo "Fetching all bootstrap-related archives ..."
143 elif [[ -n ${STRAP_RUN} ]] ; then
144 if [ ${BOOTSTRAP_STAGE} -gt 2 ] ; then
145 echo "Resuming Bootstrap of base system ..."
147 echo "Starting Bootstrap of base system ..."
150 echo -------------------------------------------------------------------------------
151 show_status 0 Locating packages
153 # This should not be set to get glibc to build properly. See bug #7652.
154 unset LD_LIBRARY_PATH
156 # We do not want stray $TMP, $TMPDIR or $TEMP settings
157 unset TMP TMPDIR TEMP
160 if [[ -n ${STRAP_RUN} ]] ; then
161 if [ ${BOOTSTRAP_STAGE} -le 2 ] ; then
162 cp -f /var/cache/edb/mtimedb /var/run/bootstrap-mtimedb
164 rm -f /var/run/bootstrap-mtimedb
171 [[ ${DEBUG} = "1" ]] && echo /usr/bin/python -c "$@" > /dev/stderr
172 /usr/bin/python -c "$@"
175 # TSTP messes ^Z of bootstrap up, so we don't trap it anymore.
176 trap "cleanup" TERM KILL INT QUIT ABRT
178 # Bug #50158 (don't use `which` in a bootstrap).
179 if ! type -path portageq &>/dev/null ; then
180 echo -------------------------------------------------------------------------------
181 eerror "Your portage version is too old. Please use a newer stage1 image."
186 # USE may be set from the environment so we back it up for later.
187 export ORIGUSE=$(portageq envvar USE)
189 # Check for 'build' or 'bootstrap' in USE ...
190 INVALID_USE=$(gawk -v ORIGUSE="${ORIGUSE}" '
192 if (ORIGUSE ~ /[[:space:]](build|bootstrap)[[:space:]]/)
196 # Do not do the check for stage build scripts ...
197 if [[ ${INVALID_USE} = "yes" ]] ; then
199 eerror "You have 'build' or 'bootstrap' in your USE flags. Please"
200 eerror "remove it before trying to continue, since these USE flags"
201 eerror "are used for internal purposes and shouldn't be specified"
207 # since our logic here ignores stuff found in package.use, let's warn the
208 # user so they can avert disaster early
209 if [[ -n $(sed -n '/^[ ]*#/d;/^[ ]*$/d;p' /etc/portage/package.use 2>/dev/null) ]] ; then
211 ewarn "You appear to have custom USE flags set in /etc/portage/package.use."
212 ewarn "Be aware that these settings may be ignored while running this script"
213 ewarn "(due to limitations in the bootstrap process). If you have some USE"
214 ewarn "flags you wish to apply to say gcc or glibc, you should hit CTRL+C"
215 ewarn "now, export them in your environment (see below), and then restart."
216 ewarn " # export USE='some flags i want'"
219 # gettext should only be needed when used with nls
220 for opt in ${ORIGUSE} ; do
223 ALLOWED_USE="${ALLOWED_USE} bindist"
227 ALLOWED_USE="${ALLOWED_USE} nls"
230 export MYARCH=$(portageq envvar ARCH)
231 if [[ -z $(portageq best_visible / '>=sys-kernel/linux-headers-2.6.0') ]] ; then
232 eerror "You need to have >=sys-kernel/linux-headers-2.6.0 unmasked!"
233 eerror "Please edit the latest >=sys-kernel/linux-headers-2.6.0 package,"
234 eerror "and add your ARCH to KEYWORDS or change your make.profile link"
235 eerror "to a profile which does not have 2.6 headers masked."
245 ALLOWED_USE="${ALLOWED_USE} multilib"
248 ALLOWED_USE="${ALLOWED_USE} userlocales"
253 # With cascading profiles, the packages profile at the leaf is not a
254 # complete system, just the restrictions to it for the specific profile.
255 # The complete profile consists of an aggregate of the leaf and all its
256 # parents. So we now call portage to read the aggregate profile and store
257 # that into a variable.
262 for atom in portage.settings.packages:
263 if not isinstance(atom, portage.dep.Atom):
264 atom = portage.dep.Atom(atom.lstrip("*"))
265 varname = "my" + portage.catsplit(atom.cp)[1].upper().replace("-", "_")
266 sys.stdout.write("%s=\"%s\"; " % (varname, atom))
269 # This stuff should never fail but will if not enough is installed.
270 [[ -z ${myBASELAYOUT} ]] && myBASELAYOUT=">=$(portageq best_version / sys-apps/baselayout)"
271 [[ -z ${myPORTAGE} ]] && myPORTAGE="portage"
272 [[ -z ${myBINUTILS} ]] && myBINUTILS="binutils"
273 [[ -z ${myGCC} ]] && myGCC="gcc"
274 [[ -z ${myGETTEXT} ]] && myGETTEXT="gettext"
275 [[ -z ${myLIBC} ]] && myLIBC="$(portageq expand_virtual / virtual/libc)"
276 [[ -z ${myTEXINFO} ]] && myTEXINFO="sys-apps/texinfo"
277 [[ -z ${myZLIB} ]] && myZLIB="zlib"
278 [[ -z ${myNCURSES} ]] && myNCURSES="ncurses"
280 # Do we really want gettext/nls?
281 [[ ${USE_NLS} != 1 ]] && myGETTEXT=
283 # Do we really have no 2.4.x nptl kernels in portage?
284 if [[ ${USE_NPTL} = "1" ]] ; then
285 myOS_HEADERS="$(portageq best_visible / '>=sys-kernel/linux-headers-2.6.0')"
286 [[ -n ${myOS_HEADERS} ]] && myOS_HEADERS=">=${myOS_HEADERS}"
287 ALLOWED_USE="${ALLOWED_USE} nptl"
288 # Should we build with nptl only?
289 [[ ${USE_NPTLONLY} = "1" ]] && ALLOWED_USE="${ALLOWED_USE} nptlonly"
291 [[ -z ${myOS_HEADERS} ]] && myOS_HEADERS="virtual/os-headers"
293 einfo "Using baselayout : ${myBASELAYOUT}"
294 einfo "Using portage : ${myPORTAGE}"
295 einfo "Using os-headers : ${myOS_HEADERS}"
296 einfo "Using binutils : ${myBINUTILS}"
297 einfo "Using gcc : ${myGCC}"
298 [[ ${USE_NLS} = "1" ]] && einfo "Using gettext : ${myGETTEXT}"
299 einfo "Using libc : ${myLIBC}"
300 einfo "Using texinfo : ${myTEXINFO}"
301 einfo "Using zlib : ${myZLIB}"
302 einfo "Using ncurses : ${myNCURSES}"
303 echo -------------------------------------------------------------------------------
304 show_status 1 Configuring environment
305 echo -------------------------------------------------------------------------------
307 [[ -x /usr/sbin/gcc-config ]] && GCC_CONFIG="/usr/sbin/gcc-config"
308 [[ -x /usr/bin/gcc-config ]] && GCC_CONFIG="/usr/bin/gcc-config"
310 # Allow portage to overwrite stuff
311 export CONFIG_PROTECT="-*"
313 # disable collision-protection
314 export FEATURES="${FEATURES} -collision-protect"
316 # query BOOTSTRAP_USE from the profile
317 BOOTSTRAP_USE=$(portageq envvar BOOTSTRAP_USE)
319 if [ ${BOOTSTRAP_STAGE} -le 1 ] ; then
320 show_status 2 Updating portage
321 ${V_ECHO} USE="-* build bootstrap ${ALLOWED_USE} ${BOOTSTRAP_USE}" emerge ${STRAP_EMERGE_OPTS} ${myPORTAGE} || cleanup 1
322 echo -------------------------------------------------------------------------------
323 set_bootstrap_stage 2
325 export USE="-* bootstrap ${ALLOWED_USE} ${BOOTSTRAP_USE}"
327 # We can't unmerge headers which may or may not exist yet. If your
328 # trying to use nptl, it may be needed to flush out any old headers
329 # before fully bootstrapping.
330 if [ ${BOOTSTRAP_STAGE} -le 2 ] ; then
331 show_status 3 Emerging packages
332 if [[ ${RESUME} -eq 1 ]] ; then
333 STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --resume"
334 cp /var/run/bootstrap-mtimedb /var/cache/edb
336 STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} \
337 ${myOS_HEADERS} ${myTEXINFO} ${myGETTEXT} ${myBINUTILS} \
338 ${myGCC} ${myLIBC} ${myBASELAYOUT} ${myZLIB}"
340 ${V_ECHO} emerge ${STRAP_EMERGE_OPTS} || cleanup 1
341 echo -------------------------------------------------------------------------------
342 set_bootstrap_stage 3
345 # Basic support for gcc multi version/arch scheme ...
346 if [[ -n ${STRAP_RUN} ]] ; then
347 if [[ -x ${GCC_CONFIG} ]] && ${GCC_CONFIG} --get-current-profile &>/dev/null
349 # Make sure we get the old gcc unmerged ...
350 emerge --prune sys-devel/gcc || cleanup 1
351 # Make sure the profile and /lib/cpp and /usr/bin/cc are valid ...
352 ${GCC_CONFIG} "$(${GCC_CONFIG} --get-current-profile)" &>/dev/null
356 if [[ -n ${STRAP_RUN} ]] ; then
357 echo -------------------------------------------------------------------------------
358 einfo "Please note that you should now add the '-e' option for emerge system:"
360 einfo " # emerge -e system"