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