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

Contents of /scripts/bootstrap-new.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download) (as text)
Fri Feb 4 18:28:47 2005 UTC (14 years, 8 months ago) by wolf31o2
Branch: MAIN
Changes since 1.3: +4 -3 lines
File MIME type: text/x-sh
Added extra [ ] around RESUME variable check.

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

  ViewVC Help
Powered by ViewVC 1.1.20