2 # Copyright 1999-2020 Gentoo Authors
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"
71 echo -e " ${GOOD}--tree (-t)${NORMAL} Display the dependency tree, forces -p"
72 echo -e " ${GOOD}--resume (-r)${NORMAL} Build/use binary packages"
73 echo -e " ${GOOD}--verbose (-v)${NORMAL} Verbose output from portage"
76 STRAP_EMERGE_OPTS="--oneshot"
84 echo "Running in fetch-only mode ..."
85 STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -f"
90 --debug|-d) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --debug"; DEBUG=1;;
91 --info|-i) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --info" ; unset STRAP_RUN ;;
92 --pretend|-p) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -p" ; unset STRAP_RUN ;;
93 --quiet|-q) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -q" ; unset STRAP_RUN ;;
94 --tree|-t) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -p -t" ; unset STRAP_RUN ;;
95 --resume|-r) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --usepkg --buildpkg";;
96 --verbose|-v) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -v" ; V_ECHO=v_echo;;
98 einfo "Gentoo Linux bootstrap ${cvsver}"
102 eerror "Unknown option '${opt}'"
109 if [[ -n ${STRAP_RUN} ]] ; then
110 if [ ${BOOTSTRAP_STAGE} -ge 3 ] ; then
112 einfo "System has been bootstrapped already!"
113 einfo "If you re-bootstrap the system, you must complete the entire bootstrap process"
114 einfo "otherwise you will have a broken system."
115 einfo "Press enter to continue or CTRL+C to abort ..."
117 set_bootstrap_stage 1
118 elif [ ${BOOTSTRAP_STAGE} -gt 1 ] ; then
119 einfo "Resuming bootstrap at internal stage #${BOOTSTRAP_STAGE} ..."
123 export BOOTSTRAP_STAGE=0
126 for p in /etc/portage /etc ; do
128 [[ -e ${p} ]] || continue
129 if type -P realpath >/dev/null ; then
130 MYPROFILEDIR=$(realpath ${p})
132 MYPROFILEDIR=$(readlink -f ${p})
135 if [[ ! -d ${MYPROFILEDIR} ]] ; then
136 eerror "Error: '${MYPROFILEDIR}' does not exist. Exiting."
140 echo -e "\n${GOOD}Gentoo Linux; ${BRACKET}http://www.gentoo.org/${NORMAL}"
141 echo -e "Copyright 1999-${cvsyear} Gentoo Foundation; Distributed under the GPLv2"
142 if [[ " ${STRAP_EMERGE_OPTS} " == *" -f "* ]] ; then
143 echo "Fetching all bootstrap-related archives ..."
144 elif [[ -n ${STRAP_RUN} ]] ; then
145 if [ ${BOOTSTRAP_STAGE} -gt 2 ] ; then
146 echo "Resuming Bootstrap of base system ..."
148 echo "Starting Bootstrap of base system ..."
151 echo -------------------------------------------------------------------------------
152 show_status 0 Locating packages
154 # This should not be set to get glibc to build properly. See bug #7652.
155 unset LD_LIBRARY_PATH
157 # We do not want stray $TMP, $TMPDIR or $TEMP settings
158 unset TMP TMPDIR TEMP
161 if [[ -n ${STRAP_RUN} ]] ; then
162 if [ ${BOOTSTRAP_STAGE} -le 2 ] ; then
163 cp -f /var/cache/edb/mtimedb /var/run/bootstrap-mtimedb
165 rm -f /var/run/bootstrap-mtimedb
172 [[ ${DEBUG} = "1" ]] && echo /usr/bin/python -c "$@" > /dev/stderr
173 /usr/bin/python -c "$@"
176 # TSTP messes ^Z of bootstrap up, so we don't trap it anymore.
177 trap "cleanup" TERM KILL INT QUIT ABRT
179 # Bug #50158 (don't use `which` in a bootstrap).
180 if ! type -path portageq &>/dev/null ; then
181 echo -------------------------------------------------------------------------------
182 eerror "Your portage version is too old. Please use a newer stage1 image."
187 # USE may be set from the environment so we back it up for later.
188 export ORIGUSE=$(portageq envvar USE)
190 # Check for 'build' or 'bootstrap' in USE ...
191 INVALID_USE=$(gawk -v ORIGUSE="${ORIGUSE}" '
193 if (ORIGUSE ~ /[[:space:]](build|bootstrap)[[:space:]]/)
197 # Do not do the check for stage build scripts ...
198 if [[ ${INVALID_USE} = "yes" ]] ; then
200 eerror "You have 'build' or 'bootstrap' in your USE flags. Please"
201 eerror "remove it before trying to continue, since these USE flags"
202 eerror "are used for internal purposes and shouldn't be specified"
208 # since our logic here ignores stuff found in package.use, let's warn the
209 # user so they can avert disaster early
210 if [[ -n $(sed -n '/^[ ]*#/d;/^[ ]*$/d;p' /etc/portage/package.use 2>/dev/null) ]] ; then
212 ewarn "You appear to have custom USE flags set in /etc/portage/package.use."
213 ewarn "Be aware that these settings may be ignored while running this script"
214 ewarn "(due to limitations in the bootstrap process). If you have some USE"
215 ewarn "flags you wish to apply to say gcc or glibc, you should hit CTRL+C"
216 ewarn "now, export them in your environment (see below), and then restart."
217 ewarn " # export USE='some flags i want'"
220 # gettext should only be needed when used with nls
221 for opt in ${ORIGUSE} ; do
224 ALLOWED_USE="${ALLOWED_USE} bindist"
228 ALLOWED_USE="${ALLOWED_USE} nls"
231 export MYARCH=$(portageq envvar ARCH)
232 if [[ -z $(portageq best_visible / '>=sys-kernel/linux-headers-2.6.0') ]] ; then
233 eerror "You need to have >=sys-kernel/linux-headers-2.6.0 unmasked!"
234 eerror "Please edit the latest >=sys-kernel/linux-headers-2.6.0 package,"
235 eerror "and add your ARCH to KEYWORDS or change your make.profile link"
236 eerror "to a profile which does not have 2.6 headers masked."
243 ALLOWED_USE="${ALLOWED_USE} multilib"
246 ALLOWED_USE="${ALLOWED_USE} userlocales"
251 # With cascading profiles, the packages profile at the leaf is not a
252 # complete system, just the restrictions to it for the specific profile.
253 # The complete profile consists of an aggregate of the leaf and all its
254 # parents. So we now call portage to read the aggregate profile and store
255 # that into a variable.
259 from portage.dbapi._expand_new_virt import expand_new_virt
261 root = portage.settings["EROOT"]
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 atom = list(expand_new_virt(portage.db[root]["vartree"].dbapi, atom))[0]
267 sys.stdout.write("%s=\"%s\"; " % (varname, atom))
270 # This stuff should never fail but will if not enough is installed.
271 [[ -z ${myBASELAYOUT} ]] && myBASELAYOUT=">=$(portageq best_version / sys-apps/baselayout)"
272 [[ -z ${myPORTAGE} ]] && myPORTAGE="sys-apps/portage"
273 [[ -z ${myBINUTILS} ]] && myBINUTILS="sys-devel/binutils"
274 [[ -z ${myGCC} ]] && myGCC="sys-devel/gcc"
275 [[ -z ${myGETTEXT} ]] && myGETTEXT="sys-devel/gettext"
276 [[ -z ${myLIBC} ]] && myLIBC="$(portageq expand_virtual / virtual/libc)"
277 [[ -z ${myTEXINFO} ]] && myTEXINFO="sys-apps/texinfo"
278 [[ -z ${myZLIB} ]] && myZLIB="sys-libs/zlib"
279 [[ -z ${myNCURSES} ]] && myNCURSES="sys-libs/ncurses"
281 # Do we really want gettext/nls?
282 [[ ${USE_NLS} != 1 ]] && myGETTEXT=
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"
289 [[ -z ${myOS_HEADERS} ]] && myOS_HEADERS="$(portageq expand_virtual / virtual/os-headers)"
291 einfo "Using baselayout : ${myBASELAYOUT}"
292 einfo "Using portage : ${myPORTAGE}"
293 einfo "Using os-headers : ${myOS_HEADERS}"
294 einfo "Using binutils : ${myBINUTILS}"
295 einfo "Using gcc : ${myGCC}"
296 [[ ${USE_NLS} = "1" ]] && einfo "Using gettext : ${myGETTEXT}"
297 einfo "Using libc : ${myLIBC}"
298 einfo "Using texinfo : ${myTEXINFO}"
299 einfo "Using zlib : ${myZLIB}"
300 einfo "Using ncurses : ${myNCURSES}"
301 echo -------------------------------------------------------------------------------
302 show_status 1 Configuring environment
303 echo -------------------------------------------------------------------------------
305 [[ -x /usr/sbin/gcc-config ]] && GCC_CONFIG="/usr/sbin/gcc-config"
306 [[ -x /usr/bin/gcc-config ]] && GCC_CONFIG="/usr/bin/gcc-config"
308 # Allow portage to overwrite stuff
309 [[ $CONFIG_PROTECT != "-*"* ]] && export CONFIG_PROTECT="-*"
311 # disable collision-protection
312 export FEATURES="${FEATURES} -collision-protect"
314 # query BOOTSTRAP_USE from the profile
315 BOOTSTRAP_USE=$(portageq envvar BOOTSTRAP_USE)
317 if [ ${BOOTSTRAP_STAGE} -le 1 ] ; then
318 show_status 2 Updating portage
319 ${V_ECHO} USE="-* build bootstrap ${ALLOWED_USE} ${BOOTSTRAP_USE}" emerge ${STRAP_EMERGE_OPTS} ${myPORTAGE} || cleanup 1
320 echo -------------------------------------------------------------------------------
321 set_bootstrap_stage 2
323 export USE="-* bootstrap ${ALLOWED_USE} ${BOOTSTRAP_USE}"
325 # We can't unmerge headers which may or may not exist yet. If your
326 # trying to use nptl, it may be needed to flush out any old headers
327 # before fully bootstrapping.
328 if [ ${BOOTSTRAP_STAGE} -le 2 ] ; then
329 show_status 3 Emerging packages
330 if [[ ${RESUME} -eq 1 ]] ; then
331 STRAP_EMERGE_POSARGS=""
332 STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --resume"
333 cp /var/run/bootstrap-mtimedb /var/cache/edb
335 STRAP_EMERGE_POSARGS="\
336 ${myOS_HEADERS} ${myTEXINFO} ${myGETTEXT} ${myBINUTILS} \
337 ${myGCC} ${myLIBC} ${myBASELAYOUT} ${myZLIB}"
339 ${V_ECHO} emerge ${STRAP_EMERGE_OPTS} ${STRAP_EMERGE_POSARGS} || cleanup 1
340 echo -------------------------------------------------------------------------------
341 set_bootstrap_stage 3
344 # Basic support for gcc multi version/arch scheme ...
345 if [[ -n ${STRAP_RUN} ]] ; then
346 if [[ -x ${GCC_CONFIG} ]] && ${GCC_CONFIG} --get-current-profile &>/dev/null
348 # Make sure we get the old gcc unmerged ...
349 ${V_ECHO} emerge ${STRAP_EMERGE_OPTS} --prune sys-devel/gcc || cleanup 1
350 # Make sure the profile and /lib/cpp and /usr/bin/cc are valid ...
351 ${GCC_CONFIG} "$(${GCC_CONFIG} --get-current-profile)" &>/dev/null
355 if [[ -n ${STRAP_RUN} ]] ; then
356 echo -------------------------------------------------------------------------------
357 einfo "Please note that you should now add the '-e' option for emerge system:"
359 einfo " # emerge <other_opts> -e @system"