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