Annotation of /trunk/bootstrap/mage-bootstrap.sh.in
Parent Directory | Revision Log
Revision 2587 -
(hide annotations)
(download)
Thu Feb 6 13:05:57 2014 UTC (10 years, 3 months ago) by niro
File size: 7769 byte(s)
Thu Feb 6 13:05:57 2014 UTC (10 years, 3 months ago) by niro
File size: 7769 byte(s)
-use is_loc_mounted() in enter_chroot()
1 | niro | 324 | #!/bin/bash |
2 | niro | 2191 | # $Id$ |
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 | niro | 2587 | is_loc_mounted "${MROOT}/proc" || mount -t proc proc ${MROOT}/proc |
83 | is_loc_mounted "${MROOT}/sys" || mount -t sysfs sysfs ${MROOT}/sys | ||
84 | is_loc_mounted "${MROOT}/dev" || mount -o bind /dev ${MROOT}/dev | ||
85 | niro | 324 | |
86 | chroot ${MROOT} /bin/bash -i /.installrc || die "chr00ting" | ||
87 | |||
88 | niro | 2587 | is_loc_mounted "${MROOT}/dev" && umount ${MROOT}/dev |
89 | is_loc_mounted "${MROOT}/sys" && umount ${MROOT}/sys | ||
90 | is_loc_mounted "${MROOT}/proc" && umount ${MROOT}/proc | ||
91 | niro | 324 | |
92 | [ -f ${MROOT}/.installrc ] && rm ${MROOT}/.installrc | ||
93 | } | ||
94 | |||
95 | is_loc_mounted() | ||
96 | { | ||
97 | local filesys | ||
98 | local i | ||
99 | filesys=$1 | ||
100 | |||
101 | i="$(cat /proc/mounts | grep " ${filesys} " | cut -d ' ' -f2)" | ||
102 | [[ ${i} != ${filesys} ]] && return 1 | ||
103 | |||
104 | return 0 | ||
105 | } | ||
106 | |||
107 | trap_exit() | ||
108 | { | ||
109 | is_loc_mounted "${MROOT}/dev" && umount ${MROOT}/dev | ||
110 | is_loc_mounted "${MROOT}/proc" && umount ${MROOT}/proc | ||
111 | niro | 2180 | is_loc_mounted "${MROOT}/sys" && umount ${MROOT}/sys |
112 | niro | 324 | is_loc_mounted "${MY_MAGEDIR}" && umount ${MY_MAGEDIR} |
113 | is_loc_mounted "${MY_PKGDIR}" && umount ${MY_PKGDIR} | ||
114 | echo "bootstrap aborted" | ||
115 | exit 1 | ||
116 | } | ||
117 | |||
118 | print_usage() | ||
119 | { | ||
120 | niro | 340 | echo "mage-bootstrap, version @VERSION@" |
121 | niro | 324 | echo "Usage: $(basename $0) --opt arg ..." |
122 | echo | ||
123 | echo "Options:" | ||
124 | niro | 1075 | echo " --profile, -p -- select a profile (needed)" |
125 | echo " --root, -r -- location to new root (needed)" | ||
126 | echo " --magerc, -m -- location of mage.rc (needed)" | ||
127 | niro | 324 | echo |
128 | niro | 1075 | echo " --toolchain, -t -- select other toolchain than from profile" |
129 | echo " --basesystem, -b -- select other basesystem than from profile" | ||
130 | echo " --stage1, -s1 -- if set, abort after stage1 (toolchain)" | ||
131 | niro | 1485 | echo " --update-tarball, -ut -- update via tarball not rsync" |
132 | niro | 1075 | echo " --no-update, -u -- do not update the mage tree" |
133 | echo " --help, -h -- prints this help" | ||
134 | niro | 324 | echo |
135 | |||
136 | exit 1 | ||
137 | } | ||
138 | |||
139 | # set some proper traps | ||
140 | trap "trap_exit" SIGINT SIGQUIT | ||
141 | |||
142 | # show usage if no opts given | ||
143 | [[ -z $* ]] && print_usage | ||
144 | |||
145 | # very basic getops | ||
146 | for i in $* | ||
147 | do | ||
148 | case $1 in | ||
149 | --toolchain|-t) shift; TOOLCHAIN="$1" ;; | ||
150 | --basesystem|-b) shift; BASESYSTEM="$1" ;; | ||
151 | --profile|-p) shift; PROFILE="$1" ;; | ||
152 | --root|-r) shift; MROOT="$1" ;; | ||
153 | --stage1|-s1) ABORT_AFTER_STAGE1=true ;; | ||
154 | --magerc|-m) shift; MAGERC="$1" ;; | ||
155 | niro | 1486 | --update-tarball|-ut) MAGEUPDATETARBALL=true ;; |
156 | --no-update|-u) MAGEUPDATE=false ;; | ||
157 | niro | 324 | --help|-h) print_usage ;; |
158 | '') shift;; | ||
159 | *) echo "Unkown option '$1', use --help or -h to get more info."; exit 1 ;; | ||
160 | esac | ||
161 | shift | ||
162 | done | ||
163 | |||
164 | # sanity checks; abort if not given | ||
165 | [ -z "${MROOT}" ] && die "\$MROOT not given." | ||
166 | [ -z "${MAGERC}" ] && die "\$MAGERC not given." | ||
167 | [ -z "${PROFILE}" ] && die "\$PROFILE not given." | ||
168 | |||
169 | # they may be empty, they are included in the profile | ||
170 | [ -z "${TOOLCHAIN}" ] && echo "\$TOOLCHAIN not given, using toolchain from profile." | ||
171 | [[ ${ABORT_AFTER_STAGE1} = false ]] && [ -z "${BASESYSTEM}" ] \ | ||
172 | && echo "\$BASESYSTEM not given, using basesystem from profile." | ||
173 | |||
174 | # check needed global commands, dirs and files | ||
175 | [ ! -d /usr/mage ] && die "/usr/mage does not exists" | ||
176 | [ ! -x /sbin/mage ] && die "'/sbin/mage' not found. Please install '>= app-mage/mage-0.4' first." | ||
177 | [ ! -x /bin/mount ] && die "'/bin/mount' not found. Please install '>= sys-apps/util-linux' first." | ||
178 | [ ! -f ${MAGERC} ] && die "Please setup your mage.rc first." | ||
179 | [ ! -f /etc/resolv.conf ] && die "/etc/resolv.conf missing. Please setup your networking first." | ||
180 | |||
181 | # install fake-root if not exist | ||
182 | [ ! -d ${MROOT} ] && { install -d ${MROOT} || die "create fakedir"; } | ||
183 | |||
184 | # create a fake dirs and mount them to / of the host system | ||
185 | MY_MAGEDIR="$(read_magerc MAGEDIR ${MAGERC})" | ||
186 | MY_PKGDIR="$(read_magerc PKGDIR ${MAGERC})" | ||
187 | |||
188 | install -d ${MROOT}/${MY_MAGEDIR} || die "create magedir" | ||
189 | install -d ${MROOT}/${MY_PKGDIR} || die "create pkgdir" | ||
190 | |||
191 | mount -o bind ${MROOT}/${MY_MAGEDIR} ${MY_MAGEDIR} || die "mount magedir" | ||
192 | mount -o bind ${MROOT}/${MY_PKGDIR} ${MY_PKGDIR} || die "mount pkgdir" | ||
193 | |||
194 | # link to the right profile | ||
195 | ln -snf ${MY_MAGEDIR}/profiles/${PROFILE} /etc/mage-profile || die "link profile" | ||
196 | |||
197 | # update mage tree | ||
198 | niro | 977 | if [[ ${MAGEUPDATE} = true ]] |
199 | then | ||
200 | niro | 1075 | if [[ ${MAGEUPDATETARBALL} = true ]] |
201 | then | ||
202 | MAGERC="${MAGERC}" mage update-tarball || die "update mage-tree" | ||
203 | else | ||
204 | MAGERC="${MAGERC}" mage update || die "update mage-tree" | ||
205 | fi | ||
206 | niro | 977 | fi |
207 | niro | 324 | |
208 | # now get the toolchain and the basesystem layout file | ||
209 | # [ -z "${TOOLCHAIN}" ] && TOOLCHAIN="toolchain.defaults" | ||
210 | # [ -z "${BASESYSTEM}" ] && BASESYSTEM="basesystem.defaults" | ||
211 | # # read them | ||
212 | # TOOLCHAIN="$(< /etc/mage-profile/${TOOLCHAIN})" | ||
213 | # BASESYSTEM="$(< /etc/mage-profile/${BASESYSTEM})" | ||
214 | |||
215 | niro | 422 | # this way toolchain and basesystem can be packages; |
216 | niro | 324 | # only if nothing set the layout files from the profile will be taken |
217 | niro | 683 | [ -z "${TOOLCHAIN}" ] && TOOLCHAIN="$(< ${MY_MAGEDIR}/profiles/${PROFILE}/toolchain.defaults)" |
218 | [ -z "${BASESYSTEM}" ] && BASESYSTEM="$(< ${MY_MAGEDIR}/profiles/${PROFILE}/basesystem.defaults)" | ||
219 | niro | 324 | |
220 | # install toolchain | ||
221 | niro | 2181 | if ! MROOT="${MROOT}" MAGERC="${MAGERC}" magequery -n ${TOOLCHAIN} |
222 | then | ||
223 | CONFIG_PROTECT="-*" MROOT="${MROOT}" MAGERC="${MAGERC}" mage install ${TOOLCHAIN} || die "toolchain install" | ||
224 | fi | ||
225 | niro | 324 | |
226 | # umount dirs, they are not needed anymore | ||
227 | umount ${MY_MAGEDIR} ${MY_PKGDIR} || die "umount mage/pkgdir" | ||
228 | |||
229 | # copy some needed files to the fake-root | ||
230 | install -m 0644 ${MAGERC} ${MROOT}/etc/mage.rc || die "install mage.rc" | ||
231 | install -m 0644 /etc/resolv.conf ${MROOT}/etc/resolv.conf || die "install resolv.conf" | ||
232 | |||
233 | # abort if wanted | ||
234 | if [[ ${ABORT_AFTER_STAGE1} = true ]] | ||
235 | then | ||
236 | echo "Stage1 complete; user requested to abort after this step." | ||
237 | echo "Exiting ..." | ||
238 | exit 0 | ||
239 | fi | ||
240 | |||
241 | # now create an initrc for the installation of the basesystem | ||
242 | :> ${MROOT}/.installrc | ||
243 | niro | 422 | add_initrc "export MAGE_BOOTSTRAP=true" |
244 | niro | 324 | add_initrc "export HOME=/root" |
245 | add_initrc "export PATH=/bin:/usr/bin:/sbin:/usr/sbin" | ||
246 | add_initrc "export BASESYSTEM=${BASESYSTEM}" | ||
247 | add_initrc "export PROFILE=${PROFILE}" | ||
248 | add_initrc "export CONFIG_PROTECT=-*" | ||
249 | add_initrc "export MY_MAGEDIR=${MY_MAGEDIR}" | ||
250 | |||
251 | # add proxies if defined | ||
252 | [[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}" | ||
253 | [[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}" | ||
254 | [[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}" | ||
255 | [[ -n ${RSYNC_PROXY} ]] && add_initrc "export RSYNC_PROXY=${RSYNC_PROXY}" | ||
256 | |||
257 | # install comands | ||
258 | add_initrc "ln -snf ${MY_MAGEDIR}/profiles/${PROFILE} /etc/mage-profile" | ||
259 | add_initrc "mage install ${BASESYSTEM}" | ||
260 | add_initrc "mage clean" | ||
261 | |||
262 | # chroot the toolchain | ||
263 | enter_chroot | ||
264 | |||
265 | echo "System bootstrap to '${MROOT}' finished." | ||
266 | exit 0 |
Properties
Name | Value |
---|---|
svn:executable | * |