Contents of /trunk/bootstrap/mage-bootstrap.sh.in
Parent Directory | Revision Log
Revision 977 -
(show annotations)
(download)
(as text)
Tue Apr 27 10:09:47 2010 UTC (14 years, 5 months ago) by niro
Original Path: trunk/bootstrap/mage-bootstrap.sh
File MIME type: application/x-sh
File size: 7267 byte(s)
Tue Apr 27 10:09:47 2010 UTC (14 years, 5 months ago) by niro
Original Path: trunk/bootstrap/mage-bootstrap.sh
File MIME type: application/x-sh
File size: 7267 byte(s)
-added --no-update option
1 | #!/bin/bash |
2 | # $Header: /home/cvsd/magellan-cvs/magellan-src/bootstrap/scripts/mage-bootstrap.sh,v 1.8 2008-06-23 19:26:40 niro Exp $ |
3 | |
4 | TOOLCHAIN="" |
5 | BASESYSTEM="" |
6 | PROFILE="" |
7 | MROOT="" |
8 | ABORT_AFTER_STAGE1=false |
9 | MY_MAGEDIR="" |
10 | MY_PKGDIR="" |
11 | MAGEUPDATE=true |
12 | |
13 | die() |
14 | { |
15 | echo "ERROR: $@" |
16 | trap_exit |
17 | exit 1 |
18 | } |
19 | |
20 | read_magerc() |
21 | { |
22 | local var="$1" |
23 | local magerc="$2" |
24 | local value |
25 | |
26 | # local all possible vars of a magerc file |
27 | # to prevent bad issues |
28 | local PKGDIR |
29 | local BUILDDIR |
30 | local INSTALLDB |
31 | local MAGEDIR |
32 | local MLIBDIR |
33 | local VIRTUALDB_DEFAULTS |
34 | local VIRTUALDB_FILE |
35 | local SOURCEDIR |
36 | local BINDIR |
37 | local SMAGESCRIPTSDIR |
38 | local MROOT |
39 | local PKGSUFFIX |
40 | local VERBOSE |
41 | local MAGEDEBUG |
42 | local ARCH |
43 | local MAGE_UNINSTALL_TIMEOUT |
44 | local CHOST |
45 | local CFLAGS |
46 | local CXXFLAGS |
47 | local SMAGE_USE_CCACHE |
48 | local SMAGE_USE_DISTCC |
49 | local MAKEOPTS |
50 | local DISTCC_HOSTS |
51 | local DISTCC_DIR |
52 | local DISTCC_VERBOSE |
53 | local DISTCC_LOG |
54 | local MIRRORS |
55 | local RSYNC |
56 | local SMAGE2RSYNC |
57 | |
58 | # sanity checks |
59 | [ -f /etc/mage.rc.global ] && source /etc/mage.rc.global || \ |
60 | die "get_value_from_magefile: /etc/mage.rc.global not found." |
61 | [ -f ${magerc} ] && source ${magerc} || \ |
62 | die "get_value_from_magefile: ${magerc} not found." |
63 | [ -z "${var}" ] && die "get_value_from_magefile: \$var not given." |
64 | |
65 | source ${magerc} |
66 | eval value=\$$(echo ${var}) |
67 | echo "${value}" |
68 | } |
69 | |
70 | add_initrc() |
71 | { |
72 | local var="$1" |
73 | |
74 | # sanity checks |
75 | [ -z "${MROOT}" ] && die "\$MROOT not given." |
76 | echo "${var}" >> ${MROOT}/.installrc || die "add_initrc() adding \$var" |
77 | } |
78 | |
79 | enter_chroot() |
80 | { |
81 | mount -t proc proc ${MROOT}/proc || die "mount proc" |
82 | mount -o bind /dev ${MROOT}/dev || die "mount dev" |
83 | |
84 | chroot ${MROOT} /bin/bash -i /.installrc || die "chr00ting" |
85 | |
86 | umount ${MROOT}/dev ${MROOT}/proc || die "mount proc/dev" |
87 | |
88 | [ -f ${MROOT}/.installrc ] && rm ${MROOT}/.installrc |
89 | } |
90 | |
91 | is_loc_mounted() |
92 | { |
93 | local filesys |
94 | local i |
95 | filesys=$1 |
96 | |
97 | i="$(cat /proc/mounts | grep " ${filesys} " | cut -d ' ' -f2)" |
98 | [[ ${i} != ${filesys} ]] && return 1 |
99 | |
100 | return 0 |
101 | } |
102 | |
103 | trap_exit() |
104 | { |
105 | is_loc_mounted "${MROOT}/dev" && umount ${MROOT}/dev |
106 | is_loc_mounted "${MROOT}/proc" && umount ${MROOT}/proc |
107 | is_loc_mounted "${MY_MAGEDIR}" && umount ${MY_MAGEDIR} |
108 | is_loc_mounted "${MY_PKGDIR}" && umount ${MY_PKGDIR} |
109 | echo "bootstrap aborted" |
110 | exit 1 |
111 | } |
112 | |
113 | print_usage() |
114 | { |
115 | echo "mage-bootstrap, version @VERSION@" |
116 | echo "Usage: $(basename $0) --opt arg ..." |
117 | echo |
118 | echo "Options:" |
119 | echo " --profile, -p -- select a profile (needed)" |
120 | echo " --root, -r -- location to new root (needed)" |
121 | echo " --magerc, -m -- location of mage.rc (needed)" |
122 | echo |
123 | echo " --toolchain, -t -- select other toolchain than from profile" |
124 | echo " --basesystem, -b -- select other basesystem than from profile" |
125 | echo " --stage1, -s1 -- if set, abort after stage1 (toolchain)" |
126 | echo " --no-update, -u -- do not update the mage tree" |
127 | echo " --help, -h -- prints this help" |
128 | echo |
129 | |
130 | exit 1 |
131 | } |
132 | |
133 | # set some proper traps |
134 | trap "trap_exit" SIGINT SIGQUIT |
135 | |
136 | # show usage if no opts given |
137 | [[ -z $* ]] && print_usage |
138 | |
139 | # very basic getops |
140 | for i in $* |
141 | do |
142 | case $1 in |
143 | --toolchain|-t) shift; TOOLCHAIN="$1" ;; |
144 | --basesystem|-b) shift; BASESYSTEM="$1" ;; |
145 | --profile|-p) shift; PROFILE="$1" ;; |
146 | --root|-r) shift; MROOT="$1" ;; |
147 | --stage1|-s1) ABORT_AFTER_STAGE1=true ;; |
148 | --magerc|-m) shift; MAGERC="$1" ;; |
149 | --no-update|-u) shift; MAGEUPDATE=false ;; |
150 | --help|-h) print_usage ;; |
151 | '') shift;; |
152 | *) echo "Unkown option '$1', use --help or -h to get more info."; exit 1 ;; |
153 | esac |
154 | shift |
155 | done |
156 | |
157 | # sanity checks; abort if not given |
158 | [ -z "${MROOT}" ] && die "\$MROOT not given." |
159 | [ -z "${MAGERC}" ] && die "\$MAGERC not given." |
160 | [ -z "${PROFILE}" ] && die "\$PROFILE not given." |
161 | |
162 | # they may be empty, they are included in the profile |
163 | [ -z "${TOOLCHAIN}" ] && echo "\$TOOLCHAIN not given, using toolchain from profile." |
164 | [[ ${ABORT_AFTER_STAGE1} = false ]] && [ -z "${BASESYSTEM}" ] \ |
165 | && echo "\$BASESYSTEM not given, using basesystem from profile." |
166 | |
167 | # check needed global commands, dirs and files |
168 | [ ! -d /usr/mage ] && die "/usr/mage does not exists" |
169 | [ ! -x /sbin/mage ] && die "'/sbin/mage' not found. Please install '>= app-mage/mage-0.4' first." |
170 | [ ! -x /bin/mount ] && die "'/bin/mount' not found. Please install '>= sys-apps/util-linux' first." |
171 | [ ! -f ${MAGERC} ] && die "Please setup your mage.rc first." |
172 | [ ! -f /etc/resolv.conf ] && die "/etc/resolv.conf missing. Please setup your networking first." |
173 | |
174 | # install fake-root if not exist |
175 | [ ! -d ${MROOT} ] && { install -d ${MROOT} || die "create fakedir"; } |
176 | |
177 | # create a fake dirs and mount them to / of the host system |
178 | MY_MAGEDIR="$(read_magerc MAGEDIR ${MAGERC})" |
179 | MY_PKGDIR="$(read_magerc PKGDIR ${MAGERC})" |
180 | |
181 | install -d ${MROOT}/${MY_MAGEDIR} || die "create magedir" |
182 | install -d ${MROOT}/${MY_PKGDIR} || die "create pkgdir" |
183 | |
184 | mount -o bind ${MROOT}/${MY_MAGEDIR} ${MY_MAGEDIR} || die "mount magedir" |
185 | mount -o bind ${MROOT}/${MY_PKGDIR} ${MY_PKGDIR} || die "mount pkgdir" |
186 | |
187 | # link to the right profile |
188 | ln -snf ${MY_MAGEDIR}/profiles/${PROFILE} /etc/mage-profile || die "link profile" |
189 | |
190 | # update mage tree |
191 | if [[ ${MAGEUPDATE} = true ]] |
192 | then |
193 | MAGERC="${MAGERC}" mage update || die "update mage-tree" |
194 | fi |
195 | |
196 | # now get the toolchain and the basesystem layout file |
197 | # [ -z "${TOOLCHAIN}" ] && TOOLCHAIN="toolchain.defaults" |
198 | # [ -z "${BASESYSTEM}" ] && BASESYSTEM="basesystem.defaults" |
199 | # # read them |
200 | # TOOLCHAIN="$(< /etc/mage-profile/${TOOLCHAIN})" |
201 | # BASESYSTEM="$(< /etc/mage-profile/${BASESYSTEM})" |
202 | |
203 | # this way toolchain and basesystem can be packages; |
204 | # only if nothing set the layout files from the profile will be taken |
205 | [ -z "${TOOLCHAIN}" ] && TOOLCHAIN="$(< ${MY_MAGEDIR}/profiles/${PROFILE}/toolchain.defaults)" |
206 | [ -z "${BASESYSTEM}" ] && BASESYSTEM="$(< ${MY_MAGEDIR}/profiles/${PROFILE}/basesystem.defaults)" |
207 | |
208 | # install toolchain |
209 | CONFIG_PROTECT="-*" MROOT="${MROOT}" MAGERC="${MAGERC}" mage install ${TOOLCHAIN} || die "toolchain install" |
210 | |
211 | # umount dirs, they are not needed anymore |
212 | umount ${MY_MAGEDIR} ${MY_PKGDIR} || die "umount mage/pkgdir" |
213 | |
214 | # copy some needed files to the fake-root |
215 | install -m 0644 ${MAGERC} ${MROOT}/etc/mage.rc || die "install mage.rc" |
216 | install -m 0644 /etc/resolv.conf ${MROOT}/etc/resolv.conf || die "install resolv.conf" |
217 | |
218 | # abort if wanted |
219 | if [[ ${ABORT_AFTER_STAGE1} = true ]] |
220 | then |
221 | echo "Stage1 complete; user requested to abort after this step." |
222 | echo "Exiting ..." |
223 | exit 0 |
224 | fi |
225 | |
226 | # now create an initrc for the installation of the basesystem |
227 | :> ${MROOT}/.installrc |
228 | add_initrc "export MAGE_BOOTSTRAP=true" |
229 | add_initrc "export HOME=/root" |
230 | add_initrc "export PATH=/bin:/usr/bin:/sbin:/usr/sbin" |
231 | add_initrc "export BASESYSTEM=${BASESYSTEM}" |
232 | add_initrc "export PROFILE=${PROFILE}" |
233 | add_initrc "export CONFIG_PROTECT=-*" |
234 | add_initrc "export MY_MAGEDIR=${MY_MAGEDIR}" |
235 | |
236 | # add proxies if defined |
237 | [[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}" |
238 | [[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}" |
239 | [[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}" |
240 | [[ -n ${RSYNC_PROXY} ]] && add_initrc "export RSYNC_PROXY=${RSYNC_PROXY}" |
241 | |
242 | # install comands |
243 | add_initrc "ln -snf ${MY_MAGEDIR}/profiles/${PROFILE} /etc/mage-profile" |
244 | add_initrc "mage install ${BASESYSTEM}" |
245 | add_initrc "mage clean" |
246 | |
247 | # chroot the toolchain |
248 | enter_chroot |
249 | |
250 | echo "System bootstrap to '${MROOT}' finished." |
251 | exit 0 |
Properties
Name | Value |
---|---|
svn:executable | * |