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