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

Contents of /scripts/bootstrap.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.97 - (show annotations) (download) (as text)
Thu Jun 27 21:04:49 2013 UTC (16 months, 3 weeks ago) by zmedico
Branch: MAIN
Changes since 1.96: +2 -7 lines
File MIME type: text/x-sh
Remove call to emerge --clean.

Since AUTOCLEAN=yes is the default, there's no need to call emerge
--clean. Also, remove redundant AUTOCLEAN=yes export, since that's
the default and if the user has disabled AUTOCLEAN then that's their
problem.

1 #!/bin/bash
2 # Copyright 1999-2012 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.96 2012/10/23 02:25:23 zmedico 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
16 # sanity check
17 [[ -e /etc/profile ]] && . /etc/profile
18
19 if [[ -e /etc/init.d/functions.sh ]] ; then
20 source /etc/init.d/functions.sh
21
22 # Use our own custom script, else logger cause things to
23 # 'freeze' if we do not have a system logger running
24 esyslog() {
25 :
26 }
27 else
28 eerror() { echo "!!! $*"; }
29 einfo() { echo "* $*"; }
30 fi
31
32 show_status() {
33 local num=$1
34 shift
35 echo " [[ ($num/3) $* ]]"
36 }
37
38 # Track progress of the bootstrap process to allow for
39 # semi-transparent resuming
40 progressfile=/var/run/bootstrap-progress
41 [[ -e ${progressfile} ]] && source ${progressfile}
42 export BOOTSTRAP_STAGE=${BOOTSTRAP_STAGE:-1}
43
44 set_bootstrap_stage() {
45 [[ -z ${STRAP_RUN} ]] && return 0
46 export BOOTSTRAP_STAGE=$1
47 echo "BOOTSTRAP_STAGE=$1" > ${progressfile}
48 }
49
50 v_echo() {
51 einfo "Executing: $*"
52 env "$@"
53 }
54
55 cvsver="$Header: /var/cvsroot/gentoo-x86/scripts/bootstrap.sh,v 1.96 2012/10/23 02:25:23 zmedico Exp $"
56 cvsver=${cvsver##*,v }
57 cvsver=${cvsver%%Exp*}
58 cvsyear=${cvsver#* }
59 cvsyear=${cvsyear%%/*}
60
61 usage() {
62 echo -e "Usage: ${HILITE}${0##*/}${NORMAL} ${GOOD}[options]${NORMAL}"
63 echo -e " ${GOOD}--debug (-d)${NORMAL} Run with debug information turned on"
64 echo -e " ${GOOD}--fetchonly (-f)${NORMAL} Just download all the source files"
65 echo -e " ${GOOD}--info (-i)${NORMAL} Show system related information"
66 echo -e " ${GOOD}--pretend (-p)${NORMAL} Display the packages that will be merged"
67 echo -e " ${GOOD}--quiet (-q)${NORMAL} Reduced or condensed output from portage's displays."
68 echo -e " ${GOOD}--tree (-t)${NORMAL} Display the dependency tree, forces -p"
69 echo -e " ${GOOD}--resume (-r)${NORMAL} Build/use binary packages"
70 }
71
72 STRAP_EMERGE_OPTS="--oneshot"
73 STRAP_RUN=1
74 V_ECHO=env
75 DEBUG=0
76
77 for opt in "$@" ; do
78 case ${opt} in
79 --fetchonly|-f)
80 echo "Running in fetch-only mode ..."
81 STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -f"
82 unset STRAP_RUN;;
83 --help|-h)
84 usage
85 exit 0;;
86 --debug|-d) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --debug"; DEBUG=1;;
87 --info|-i) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --info" ; unset STRAP_RUN ;;
88 --pretend|-p) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -p" ; unset STRAP_RUN ;;
89 --quiet|-q) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -q" ; unset STRAP_RUN ;;
90 --tree|-t) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -p -t" ; unset STRAP_RUN ;;
91 --resume|-r) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --usepkg --buildpkg";;
92 --verbose|-v) STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -v"; V_ECHO=v_echo;;
93 --version|-V)
94 einfo "Gentoo Linux bootstrap ${cvsver}"
95 exit 0
96 ;;
97 *)
98 eerror "Unknown option '${opt}'"
99 usage
100 exit 1;;
101 esac
102 done
103
104 RESUME=0
105 if [[ -n ${STRAP_RUN} ]] ; then
106 if [ ${BOOTSTRAP_STAGE} -ge 3 ] ; then
107 echo
108 einfo "System has been bootstrapped already!"
109 einfo "If you re-bootstrap the system, you must complete the entire bootstrap process"
110 einfo "otherwise you will have a broken system."
111 einfo "Press enter to continue or CTRL+C to abort ..."
112 read
113 set_bootstrap_stage 1
114 elif [ ${BOOTSTRAP_STAGE} -gt 1 ] ; then
115 einfo "Resuming bootstrap at internal stage #${BOOTSTRAP_STAGE} ..."
116 RESUME=1
117 fi
118 else
119 export BOOTSTRAP_STAGE=0
120 fi
121
122 for p in /etc/portage /etc ; do
123 p+="/make.profile"
124 [[ -e ${p} ]] || continue
125 if type -P realpath >/dev/null ; then
126 MYPROFILEDIR=$(realpath ${p})
127 else
128 MYPROFILEDIR=$(readlink -f ${p})
129 fi
130 done
131 if [[ ! -d ${MYPROFILEDIR} ]] ; then
132 eerror "Error: '${MYPROFILEDIR}' does not exist. Exiting."
133 exit 1
134 fi
135
136 echo -e "\n${GOOD}Gentoo Linux; ${BRACKET}http://www.gentoo.org/${NORMAL}"
137 echo -e "Copyright 1999-${cvsyear} Gentoo Foundation; Distributed under the GPLv2"
138 if [[ " ${STRAP_EMERGE_OPTS} " == *" -f "* ]] ; then
139 echo "Fetching all bootstrap-related archives ..."
140 elif [[ -n ${STRAP_RUN} ]] ; then
141 if [ ${BOOTSTRAP_STAGE} -gt 2 ] ; then
142 echo "Resuming Bootstrap of base system ..."
143 else
144 echo "Starting Bootstrap of base system ..."
145 fi
146 fi
147 echo -------------------------------------------------------------------------------
148 show_status 0 Locating packages
149
150 # This should not be set to get glibc to build properly. See bug #7652.
151 unset LD_LIBRARY_PATH
152
153 # We do not want stray $TMP, $TMPDIR or $TEMP settings
154 unset TMP TMPDIR TEMP
155
156 cleanup() {
157 if [[ -n ${STRAP_RUN} ]] ; then
158 if [ ${BOOTSTRAP_STAGE} -le 2 ] ; then
159 cp -f /var/cache/edb/mtimedb /var/run/bootstrap-mtimedb
160 else
161 rm -f /var/run/bootstrap-mtimedb
162 fi
163 fi
164 exit $1
165 }
166
167 pycmd() {
168 [[ ${DEBUG} = "1" ]] && echo /usr/bin/python -c "$@" > /dev/stderr
169 /usr/bin/python -c "$@"
170 }
171
172 # TSTP messes ^Z of bootstrap up, so we don't trap it anymore.
173 trap "cleanup" TERM KILL INT QUIT ABRT
174
175 # Bug #50158 (don't use `which` in a bootstrap).
176 if ! type -path portageq &>/dev/null ; then
177 echo -------------------------------------------------------------------------------
178 eerror "Your portage version is too old. Please use a newer stage1 image."
179 echo
180 cleanup 1
181 fi
182
183 # USE may be set from the environment so we back it up for later.
184 export ORIGUSE=$(portageq envvar USE)
185
186 # Check for 'build' or 'bootstrap' in USE ...
187 INVALID_USE=$(gawk -v ORIGUSE="${ORIGUSE}" '
188 BEGIN {
189 if (ORIGUSE ~ /[[:space:]](build|bootstrap)[[:space:]]/)
190 print "yes"
191 }')
192
193 # Do not do the check for stage build scripts ...
194 if [[ ${INVALID_USE} = "yes" ]] ; then
195 echo
196 eerror "You have 'build' or 'bootstrap' in your USE flags. Please"
197 eerror "remove it before trying to continue, since these USE flags"
198 eerror "are used for internal purposes and shouldn't be specified"
199 eerror "by you."
200 echo
201 cleanup 1
202 fi
203
204 # since our logic here ignores stuff found in package.use, let's warn the
205 # user so they can avert disaster early
206 if [[ -n $(sed -n '/^[ ]*#/d;/^[ ]*$/d;p' /etc/portage/package.use 2>/dev/null) ]] ; then
207 echo
208 ewarn "You appear to have custom USE flags set in /etc/portage/package.use."
209 ewarn "Be aware that these settings may be ignored while running this script"
210 ewarn "(due to limitations in the bootstrap process). If you have some USE"
211 ewarn "flags you wish to apply to say gcc or glibc, you should hit CTRL+C"
212 ewarn "now, export them in your environment (see below), and then restart."
213 ewarn " # export USE='some flags i want'"
214 fi
215
216 # gettext should only be needed when used with nls
217 for opt in ${ORIGUSE} ; do
218 case "${opt}" in
219 bindist)
220 ALLOWED_USE="${ALLOWED_USE} bindist"
221 ;;
222 nls)
223 USE_NLS=1
224 ALLOWED_USE="${ALLOWED_USE} nls"
225 ;;
226 nptl)
227 export MYARCH=$(portageq envvar ARCH)
228 if [[ -z $(portageq best_visible / '>=sys-kernel/linux-headers-2.6.0') ]] ; then
229 eerror "You need to have >=sys-kernel/linux-headers-2.6.0 unmasked!"
230 eerror "Please edit the latest >=sys-kernel/linux-headers-2.6.0 package,"
231 eerror "and add your ARCH to KEYWORDS or change your make.profile link"
232 eerror "to a profile which does not have 2.6 headers masked."
233 echo
234 cleanup 1
235 fi
236 USE_NPTL=1
237 ;;
238 nptlonly)
239 USE_NPTLONLY=1
240 ;;
241 multilib)
242 ALLOWED_USE="${ALLOWED_USE} multilib"
243 ;;
244 userlocales)
245 ALLOWED_USE="${ALLOWED_USE} userlocales"
246 ;;
247 esac
248 done
249
250 # With cascading profiles, the packages profile at the leaf is not a
251 # complete system, just the restrictions to it for the specific profile.
252 # The complete profile consists of an aggregate of the leaf and all its
253 # parents. So we now call portage to read the aggregate profile and store
254 # that into a variable.
255
256 eval $(pycmd '
257 import portage
258 import sys
259 for atom in portage.settings.packages:
260 if not isinstance(atom, portage.dep.Atom):
261 atom = portage.dep.Atom(atom.lstrip("*"))
262 varname = "my" + portage.catsplit(atom.cp)[1].upper().replace("-", "_")
263 sys.stdout.write("%s=\"%s\"; " % (varname, atom))
264 ')
265
266 # This stuff should never fail but will if not enough is installed.
267 [[ -z ${myBASELAYOUT} ]] && myBASELAYOUT=">=$(portageq best_version / sys-apps/baselayout)"
268 [[ -z ${myPORTAGE} ]] && myPORTAGE="portage"
269 [[ -z ${myBINUTILS} ]] && myBINUTILS="binutils"
270 [[ -z ${myGCC} ]] && myGCC="gcc"
271 [[ -z ${myGETTEXT} ]] && myGETTEXT="gettext"
272 [[ -z ${myLIBC} ]] && myLIBC="virtual/libc"
273 [[ -z ${myTEXINFO} ]] && myTEXINFO="sys-apps/texinfo"
274 [[ -z ${myZLIB} ]] && myZLIB="zlib"
275 [[ -z ${myNCURSES} ]] && myNCURSES="ncurses"
276
277 # Do we really want gettext/nls?
278 [[ ${USE_NLS} != 1 ]] && myGETTEXT=
279
280 # Do we really have no 2.4.x nptl kernels in portage?
281 if [[ ${USE_NPTL} = "1" ]] ; then
282 myOS_HEADERS="$(portageq best_visible / '>=sys-kernel/linux-headers-2.6.0')"
283 [[ -n ${myOS_HEADERS} ]] && myOS_HEADERS=">=${myOS_HEADERS}"
284 ALLOWED_USE="${ALLOWED_USE} nptl"
285 # Should we build with nptl only?
286 [[ ${USE_NPTLONLY} = "1" ]] && ALLOWED_USE="${ALLOWED_USE} nptlonly"
287 fi
288 [[ -z ${myOS_HEADERS} ]] && myOS_HEADERS="virtual/os-headers"
289
290 einfo "Using baselayout : ${myBASELAYOUT}"
291 einfo "Using portage : ${myPORTAGE}"
292 einfo "Using os-headers : ${myOS_HEADERS}"
293 einfo "Using binutils : ${myBINUTILS}"
294 einfo "Using gcc : ${myGCC}"
295 [[ ${USE_NLS} = "1" ]] && einfo "Using gettext : ${myGETTEXT}"
296 einfo "Using libc : ${myLIBC}"
297 einfo "Using texinfo : ${myTEXINFO}"
298 einfo "Using zlib : ${myZLIB}"
299 einfo "Using ncurses : ${myNCURSES}"
300 echo -------------------------------------------------------------------------------
301 show_status 1 Configuring environment
302 echo -------------------------------------------------------------------------------
303
304 [[ -x /usr/sbin/gcc-config ]] && GCC_CONFIG="/usr/sbin/gcc-config"
305 [[ -x /usr/bin/gcc-config ]] && GCC_CONFIG="/usr/bin/gcc-config"
306
307 # Allow portage to overwrite stuff
308 export CONFIG_PROTECT="-*"
309
310 # disable collision-protection
311 export FEATURES="${FEATURES} -collision-protect"
312
313 # query BOOTSTRAP_USE from the profile
314 BOOTSTRAP_USE=$(portageq envvar BOOTSTRAP_USE)
315
316 if [ ${BOOTSTRAP_STAGE} -le 1 ] ; then
317 show_status 2 Updating portage
318 ${V_ECHO} USE="-* build bootstrap ${ALLOWED_USE} ${BOOTSTRAP_USE}" emerge ${STRAP_EMERGE_OPTS} ${myPORTAGE} || cleanup 1
319 echo -------------------------------------------------------------------------------
320 set_bootstrap_stage 2
321 fi
322 export USE="-* bootstrap ${ALLOWED_USE} ${BOOTSTRAP_USE}"
323
324 # We can't unmerge headers which may or may not exist yet. If your
325 # trying to use nptl, it may be needed to flush out any old headers
326 # before fully bootstrapping.
327 if [ ${BOOTSTRAP_STAGE} -le 2 ] ; then
328 show_status 3 Emerging packages
329 if [[ ${RESUME} -eq 1 ]] ; then
330 STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} --resume"
331 cp /var/run/bootstrap-mtimedb /var/cache/edb
332 else
333 # Why do we need this? It will pull in python that needs g++
334 # among others, and add a few IMHO unneeded deps ...
335 #STRAP_EMERGE_OPTS="${STRAP_EMERGE_OPTS} -e"
336 :
337 fi
338 ${V_ECHO} emerge ${STRAP_EMERGE_OPTS} ${myOS_HEADERS} ${myTEXINFO} ${myGETTEXT} ${myBINUTILS} \
339 ${myGCC} ${myLIBC} ${myBASELAYOUT} ${myZLIB} || cleanup 1
340 echo -------------------------------------------------------------------------------
341 set_bootstrap_stage 3
342 fi
343
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
347 then
348 # Make sure we get the old gcc unmerged ...
349 emerge --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
352 fi
353 fi
354
355 if [[ -n ${STRAP_RUN} ]] ; then
356 echo -------------------------------------------------------------------------------
357 einfo "Please note that you should now add the '-e' option for emerge system:"
358 echo
359 einfo " # emerge -e system"
360 echo
361 fi
362
363 cleanup 0

  ViewVC Help
Powered by ViewVC 1.1.20