/[gentoo-x86]/scripts/bootstrap.sh
Gentoo

Contents of /scripts/bootstrap.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.99 - (show annotations) (download) (as text)
Wed Feb 4 10:07:32 2015 UTC (4 years, 7 months ago) by kumba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.98: +7 -8 lines
File MIME type: text/x-sh
Fix to call emerge --resume properly, especially for catalyst stage2 resumes.  #538618.

1 #!/bin/bash
2 # Copyright 1999-2014 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-x86/scripts/bootstrap.sh,v 1.98 2014/03/13 16:11:27 williamh Exp $
5
6 # people who were here:
7 # (drobbins, 06 Jun 2003)
8 # (solar, Jul 2004)
9 # (vapier, Aug 2004)
10 # (compnerd, Nov 2004)
11 # (wolf31o2, Jan 2005)
12 # (azarah, Mar 2005)
13 # (uberlord, May 2007)
14 # (kumba, May 2007)
15 # (williamh, Mar 2014)
16 # (kumba, Feb 2015)
17
18 # sanity check
19 [[ -e /etc/profile ]] && . /etc/profile
20
21 if [[ -e /lib/gentoo/functions.sh ]] ; then
22 source /lib/gentoo/functions.sh
23 elif [[ -e /etc/init.d/functions.sh ]] ; then
24 source /etc/init.d/functions.sh
25 else
26 eerror() { echo "!!! $*"; }
27 einfo() { echo "* $*"; }
28 fi
29
30 # Use our own custom script, else logger cause things to
31 # 'freeze' if we do not have a system logger running
32 esyslog() {
33 :
34 }
35
36 show_status() {
37 local num=$1
38 shift
39 echo " [[ ($num/3) $* ]]"
40 }
41
42 # Track progress of the bootstrap process to allow for
43 # semi-transparent resuming
44 progressfile=/var/run/bootstrap-progress
45 [[ -e ${progressfile} ]] && source ${progressfile}
46 export BOOTSTRAP_STAGE=${BOOTSTRAP_STAGE:-1}
47
48 set_bootstrap_stage() {
49 [[ -z ${STRAP_RUN} ]] && return 0
50 export BOOTSTRAP_STAGE=$1
51 echo "BOOTSTRAP_STAGE=$1" > ${progressfile}
52 }
53
54 v_echo() {
55 einfo "Executing: $*"
56 env "$@"
57 }
58
59 cvsver="$Header: /var/cvsroot/gentoo-x86/scripts/bootstrap.sh,v 1.98 2014/03/13 16:11:27 williamh Exp $"
60 cvsver=${cvsver##*,v }
61 cvsver=${cvsver%%Exp*}
62 cvsyear=${cvsver#* }
63 cvsyear=${cvsyear%%/*}
64
65 usage() {
66 echo -e "Usage: ${HILITE}${0##*/}${NORMAL} ${GOOD}[options]${NORMAL}"
67 echo -e " ${GOOD}--debug (-d)${NORMAL} Run with debug information turned on"
68 echo -e " ${GOOD}--fetchonly (-f)${NORMAL} Just download all the source files"
69 echo -e " ${GOOD}--info (-i)${NORMAL} Show system related information"
70 echo -e " ${GOOD}--pretend (-p)${NORMAL} Display the packages that will be merged"
71 echo -e " ${GOOD}--quiet (-q)${NORMAL} Reduced or condensed output from portage's displays."
72 echo -e " ${GOOD}--tree (-t)${NORMAL} Display the dependency tree, forces -p"
73 echo -e " ${GOOD}--resume (-r)${NORMAL} Build/use binary packages"
74 }
75
76 STRAP_EMERGE_OPTS="--oneshot"
77 STRAP_RUN=1
78 V_ECHO=env
79 DEBUG=0
80
81 for opt in "$@" ; do
82 case ${opt} in
83 --fetchonly|-f)
84 echo "Running in fetch-only mode ..."
85 STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -f"
86 unset STRAP_RUN;;
87 --help|-h)
88 usage
89 exit 0;;
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;;
97 --version|-V)
98 einfo "Gentoo Linux bootstrap ${cvsver}"
99 exit 0
100 ;;
101 *)
102 eerror "Unknown option '${opt}'"
103 usage
104 exit 1;;
105 esac
106 done
107
108 RESUME=0
109 if [[ -n ${STRAP_RUN} ]] ; then
110 if [ ${BOOTSTRAP_STAGE} -ge 3 ] ; then
111 echo
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 ..."
116 read
117 set_bootstrap_stage 1
118 elif [ ${BOOTSTRAP_STAGE} -gt 1 ] ; then
119 einfo "Resuming bootstrap at internal stage #${BOOTSTRAP_STAGE} ..."
120 RESUME=1
121 fi
122 else
123 export BOOTSTRAP_STAGE=0
124 fi
125
126 for p in /etc/portage /etc ; do
127 p+="/make.profile"
128 [[ -e ${p} ]] || continue
129 if type -P realpath >/dev/null ; then
130 MYPROFILEDIR=$(realpath ${p})
131 else
132 MYPROFILEDIR=$(readlink -f ${p})
133 fi
134 done
135 if [[ ! -d ${MYPROFILEDIR} ]] ; then
136 eerror "Error: '${MYPROFILEDIR}' does not exist. Exiting."
137 exit 1
138 fi
139
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 ..."
147 else
148 echo "Starting Bootstrap of base system ..."
149 fi
150 fi
151 echo -------------------------------------------------------------------------------
152 show_status 0 Locating packages
153
154 # This should not be set to get glibc to build properly. See bug #7652.
155 unset LD_LIBRARY_PATH
156
157 # We do not want stray $TMP, $TMPDIR or $TEMP settings
158 unset TMP TMPDIR TEMP
159
160 cleanup() {
161 if [[ -n ${STRAP_RUN} ]] ; then
162 if [ ${BOOTSTRAP_STAGE} -le 2 ] ; then
163 cp -f /var/cache/edb/mtimedb /var/run/bootstrap-mtimedb
164 else
165 rm -f /var/run/bootstrap-mtimedb
166 fi
167 fi
168 exit $1
169 }
170
171 pycmd() {
172 [[ ${DEBUG} = "1" ]] && echo /usr/bin/python -c "$@" > /dev/stderr
173 /usr/bin/python -c "$@"
174 }
175
176 # TSTP messes ^Z of bootstrap up, so we don't trap it anymore.
177 trap "cleanup" TERM KILL INT QUIT ABRT
178
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."
183 echo
184 cleanup 1
185 fi
186
187 # USE may be set from the environment so we back it up for later.
188 export ORIGUSE=$(portageq envvar USE)
189
190 # Check for 'build' or 'bootstrap' in USE ...
191 INVALID_USE=$(gawk -v ORIGUSE="${ORIGUSE}" '
192 BEGIN {
193 if (ORIGUSE ~ /[[:space:]](build|bootstrap)[[:space:]]/)
194 print "yes"
195 }')
196
197 # Do not do the check for stage build scripts ...
198 if [[ ${INVALID_USE} = "yes" ]] ; then
199 echo
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"
203 eerror "by you."
204 echo
205 cleanup 1
206 fi
207
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
211 echo
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'"
218 fi
219
220 # gettext should only be needed when used with nls
221 for opt in ${ORIGUSE} ; do
222 case "${opt}" in
223 bindist)
224 ALLOWED_USE="${ALLOWED_USE} bindist"
225 ;;
226 nls)
227 USE_NLS=1
228 ALLOWED_USE="${ALLOWED_USE} nls"
229 ;;
230 nptl)
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."
237 echo
238 cleanup 1
239 fi
240 USE_NPTL=1
241 ;;
242 nptlonly)
243 USE_NPTLONLY=1
244 ;;
245 multilib)
246 ALLOWED_USE="${ALLOWED_USE} multilib"
247 ;;
248 userlocales)
249 ALLOWED_USE="${ALLOWED_USE} userlocales"
250 ;;
251 esac
252 done
253
254 # With cascading profiles, the packages profile at the leaf is not a
255 # complete system, just the restrictions to it for the specific profile.
256 # The complete profile consists of an aggregate of the leaf and all its
257 # parents. So we now call portage to read the aggregate profile and store
258 # that into a variable.
259
260 eval $(pycmd '
261 import portage
262 import sys
263 for atom in portage.settings.packages:
264 if not isinstance(atom, portage.dep.Atom):
265 atom = portage.dep.Atom(atom.lstrip("*"))
266 varname = "my" + portage.catsplit(atom.cp)[1].upper().replace("-", "_")
267 sys.stdout.write("%s=\"%s\"; " % (varname, atom))
268 ')
269
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="portage"
273 [[ -z ${myBINUTILS} ]] && myBINUTILS="binutils"
274 [[ -z ${myGCC} ]] && myGCC="gcc"
275 [[ -z ${myGETTEXT} ]] && myGETTEXT="gettext"
276 [[ -z ${myLIBC} ]] && myLIBC="virtual/libc"
277 [[ -z ${myTEXINFO} ]] && myTEXINFO="sys-apps/texinfo"
278 [[ -z ${myZLIB} ]] && myZLIB="zlib"
279 [[ -z ${myNCURSES} ]] && myNCURSES="ncurses"
280
281 # Do we really want gettext/nls?
282 [[ ${USE_NLS} != 1 ]] && myGETTEXT=
283
284 # Do we really have no 2.4.x nptl kernels in portage?
285 if [[ ${USE_NPTL} = "1" ]] ; then
286 myOS_HEADERS="$(portageq best_visible / '>=sys-kernel/linux-headers-2.6.0')"
287 [[ -n ${myOS_HEADERS} ]] && myOS_HEADERS=">=${myOS_HEADERS}"
288 ALLOWED_USE="${ALLOWED_USE} nptl"
289 # Should we build with nptl only?
290 [[ ${USE_NPTLONLY} = "1" ]] && ALLOWED_USE="${ALLOWED_USE} nptlonly"
291 fi
292 [[ -z ${myOS_HEADERS} ]] && myOS_HEADERS="virtual/os-headers"
293
294 einfo "Using baselayout : ${myBASELAYOUT}"
295 einfo "Using portage : ${myPORTAGE}"
296 einfo "Using os-headers : ${myOS_HEADERS}"
297 einfo "Using binutils : ${myBINUTILS}"
298 einfo "Using gcc : ${myGCC}"
299 [[ ${USE_NLS} = "1" ]] && einfo "Using gettext : ${myGETTEXT}"
300 einfo "Using libc : ${myLIBC}"
301 einfo "Using texinfo : ${myTEXINFO}"
302 einfo "Using zlib : ${myZLIB}"
303 einfo "Using ncurses : ${myNCURSES}"
304 echo -------------------------------------------------------------------------------
305 show_status 1 Configuring environment
306 echo -------------------------------------------------------------------------------
307
308 [[ -x /usr/sbin/gcc-config ]] && GCC_CONFIG="/usr/sbin/gcc-config"
309 [[ -x /usr/bin/gcc-config ]] && GCC_CONFIG="/usr/bin/gcc-config"
310
311 # Allow portage to overwrite stuff
312 export CONFIG_PROTECT="-*"
313
314 # disable collision-protection
315 export FEATURES="${FEATURES} -collision-protect"
316
317 # query BOOTSTRAP_USE from the profile
318 BOOTSTRAP_USE=$(portageq envvar BOOTSTRAP_USE)
319
320 if [ ${BOOTSTRAP_STAGE} -le 1 ] ; then
321 show_status 2 Updating portage
322 ${V_ECHO} USE="-* build bootstrap ${ALLOWED_USE} ${BOOTSTRAP_USE}" emerge ${STRAP_EMERGE_OPTS} ${myPORTAGE} || cleanup 1
323 echo -------------------------------------------------------------------------------
324 set_bootstrap_stage 2
325 fi
326 export USE="-* bootstrap ${ALLOWED_USE} ${BOOTSTRAP_USE}"
327
328 # We can't unmerge headers which may or may not exist yet. If your
329 # trying to use nptl, it may be needed to flush out any old headers
330 # before fully bootstrapping.
331 if [ ${BOOTSTRAP_STAGE} -le 2 ] ; then
332 show_status 3 Emerging packages
333 if [[ ${RESUME} -eq 1 ]] ; then
334 STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --resume"
335 cp /var/run/bootstrap-mtimedb /var/cache/edb
336 else
337 STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} \
338 ${myOS_HEADERS} ${myTEXINFO} ${myGETTEXT} ${myBINUTILS} \
339 ${myGCC} ${myLIBC} ${myBASELAYOUT} ${myZLIB}"
340 fi
341 ${V_ECHO} emerge ${STRAP_EMERGE_OPTS} || cleanup 1
342 echo -------------------------------------------------------------------------------
343 set_bootstrap_stage 3
344 fi
345
346 # Basic support for gcc multi version/arch scheme ...
347 if [[ -n ${STRAP_RUN} ]] ; then
348 if [[ -x ${GCC_CONFIG} ]] && ${GCC_CONFIG} --get-current-profile &>/dev/null
349 then
350 # Make sure we get the old gcc unmerged ...
351 emerge --prune sys-devel/gcc || cleanup 1
352 # Make sure the profile and /lib/cpp and /usr/bin/cc are valid ...
353 ${GCC_CONFIG} "$(${GCC_CONFIG} --get-current-profile)" &>/dev/null
354 fi
355 fi
356
357 if [[ -n ${STRAP_RUN} ]] ; then
358 echo -------------------------------------------------------------------------------
359 einfo "Please note that you should now add the '-e' option for emerge system:"
360 echo
361 einfo " # emerge -e system"
362 echo
363 fi
364
365 cleanup 0

  ViewVC Help
Powered by ViewVC 1.1.20