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

Contents of /scripts/bootstrap-new.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download) (as text)
Fri Feb 4 16:26:45 2005 UTC (14 years, 8 months ago) by wolf31o2
Branch: MAIN
Changes since 1.2: +4 -4 lines
File MIME type: text/x-sh
Fixed status messages.

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

  ViewVC Help
Powered by ViewVC 1.1.20