Annotation of /trunk/mlivecdbuild/mlivecdbuild2.sh
Parent Directory
|
Revision Log
Revision 580 -
(hide annotations)
(download)
(as text)
Fri Oct 12 21:29:13 2007 UTC (16 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 9320 byte(s)
Fri Oct 12 21:29:13 2007 UTC (16 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 9320 byte(s)
-prevent services from start when installing custom_packages
1 | niro | 346 | #!/bin/bash |
2 | |||
3 | # some default settings - gets overidden with the profile config | ||
4 | niro | 360 | CDPROFILE="$2" |
5 | niro | 346 | [[ -z ${CDPROFILE} ]] && CDPROFILE="default" |
6 | LIVECDROOT="/mnt/MLIVECDBUILD/${CDPROFILE}" | ||
7 | CDCHROOTDIR="${LIVECDROOT}/chroot" | ||
8 | CDISONAME="livecd-${CDPROFILE}.iso" | ||
9 | CDISOROOT="${LIVECDROOT}/isoroot" | ||
10 | CDKERNELNAME="magelive" | ||
11 | CDHOSTNAME="livecd-${CDPROFILE}" | ||
12 | MAGERC="/etc/mage.rc" | ||
13 | MAGE_PROFILE="$(basename $(readlink /etc/mage-profile))" | ||
14 | #TOOLCHAIN=toolchain | ||
15 | BASESYSTEM=livecdsystem26 | ||
16 | CDID="mlcd-$(date +%F-%k%M)" | ||
17 | |||
18 | # global profile pathes | ||
19 | PROFILES_DIR="/usr/lib/mlivecdbuild/profiles" | ||
20 | GLOBAL_PROFILE="${PROFILES_DIR}/global" | ||
21 | |||
22 | die() { echo "ERROR: $@"; exit 1; } | ||
23 | |||
24 | # get_profile $filename | ||
25 | get_profile() | ||
26 | { | ||
27 | local file="$1" | ||
28 | |||
29 | if [[ -z ${file} ]] || [[ ! -e ${PROFILES_DIR}/${CDPROFILE}/${file} ]] | ||
30 | then | ||
31 | echo "${GLOBAL_PROFILE}/${file}" | ||
32 | return 0 | ||
33 | fi | ||
34 | |||
35 | echo "${PROFILES_DIR}/${CDPROFILE}/${file}" | ||
36 | } | ||
37 | |||
38 | bootstrap_system() | ||
39 | { | ||
40 | mage-bootstrap \ | ||
41 | --root "${CDCHROOTDIR}" \ | ||
42 | --magerc "${MAGERC}" \ | ||
43 | --profile "${MAGE_PROFILE}" \ | ||
44 | --toolchain "${TOOLCHAIN}" \ | ||
45 | --basesystem "${BASESYSTEM}" \ | ||
46 | || die "bootstrapping toolchain" | ||
47 | } | ||
48 | |||
49 | niro | 360 | custom_services() |
50 | { | ||
51 | local cmd="$1" | ||
52 | local services="$2" | ||
53 | |||
54 | case ${cmd} in | ||
55 | niro | 471 | add|del|default) |
56 | # add given services from profile | ||
57 | if [[ -n ${services} ]] | ||
58 | then | ||
59 | local i | ||
60 | for i in ${services} | ||
61 | do | ||
62 | MROOT="${CDCHROOTDIR}" rc-config ${cmd} ${i} || die "rc ${cmd} ${i}" | ||
63 | done | ||
64 | fi | ||
65 | ;; | ||
66 | niro | 360 | *) die "custom_services: unkown command ${cmd}";; |
67 | esac | ||
68 | } | ||
69 | |||
70 | add_initrc() | ||
71 | { | ||
72 | local var="$1" | ||
73 | |||
74 | # sanity checks | ||
75 | niro | 473 | [[ -z ${CDCHROOTDIR} ]] && die "\$CDCHROOTDIR not given." |
76 | niro | 360 | echo "${var}" >> ${CDCHROOTDIR}/.installrc || die "add_initrc() adding \$var" |
77 | } | ||
78 | |||
79 | custom_packages() | ||
80 | { | ||
81 | local cmd="$1" | ||
82 | local packages="$2" | ||
83 | |||
84 | case ${cmd} in | ||
85 | niro | 471 | install|uninstall) |
86 | if [[ -n ${packages} ]] | ||
87 | then | ||
88 | :> ${CDCHROOTDIR}/.installrc | ||
89 | niro | 472 | |
90 | # respect proxies | ||
91 | [[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}" | ||
92 | [[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}" | ||
93 | [[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}" | ||
94 | |||
95 | niro | 580 | # do not auto-start any services! |
96 | add_initrc "export MAGE_BOOTSTRAP=true" | ||
97 | |||
98 | niro | 471 | local i |
99 | for i in ${packages} | ||
100 | do | ||
101 | add_initrc "mage install ${i}" | ||
102 | done | ||
103 | add_initrc "mage clean" | ||
104 | |||
105 | # now run the .installrc script | ||
106 | mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc" | ||
107 | mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys" | ||
108 | mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev" | ||
109 | chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting" | ||
110 | umount ${CDCHROOTDIR}/dev || die "umount dev" | ||
111 | umount ${CDCHROOTDIR}/proc || die "umount proc" | ||
112 | umount ${CDCHROOTDIR}/sys || die "umount sys" | ||
113 | [ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc | ||
114 | fi | ||
115 | ;; | ||
116 | niro | 360 | *) die "custom_packages: unkown command ${cmd}";; |
117 | esac | ||
118 | } | ||
119 | |||
120 | read_config() | ||
121 | { | ||
122 | local file="$1" | ||
123 | local pkg | ||
124 | |||
125 | ( cat ${file}; echo ) | while read pkg | ||
126 | do | ||
127 | case "${pkg}" in | ||
128 | \#*|"") continue ;; | ||
129 | esac | ||
130 | echo "${pkg}" | ||
131 | done | ||
132 | } | ||
133 | |||
134 | niro | 346 | prepare_iso() |
135 | { | ||
136 | echo Preparing LiveCD ISO Image ... | ||
137 | |||
138 | # fixes some issues with xfree/xorg xkb | ||
139 | niro | 473 | if [[ -L ${CDCHROOTDIR}/etc/X11/xkb ]] && [[ -d /usr/X11R6/lib/X11/xkb ]] |
140 | niro | 346 | then |
141 | rm ${CDCHROOTDIR}/etc/X11/xkb || die | ||
142 | mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die | ||
143 | ln -s ../../../../etc/X11/xkb ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb || die | ||
144 | fi | ||
145 | |||
146 | install -m 0644 $(get_profile inittab) ${CDCHROOTDIR}/etc/inittab || die | ||
147 | install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die | ||
148 | install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die | ||
149 | install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die | ||
150 | echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die | ||
151 | |||
152 | echo Setting up services ... | ||
153 | |||
154 | # add hardware detection | ||
155 | MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect" | ||
156 | |||
157 | # del checkfs | ||
158 | MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs" | ||
159 | |||
160 | niro | 360 | # add custom packages |
161 | [[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}" | ||
162 | [ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))" | ||
163 | |||
164 | # del custom packages | ||
165 | [[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}" | ||
166 | [ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))" | ||
167 | |||
168 | # add given services from profile | ||
169 | [[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}" | ||
170 | [ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))" | ||
171 | |||
172 | # del given services from profile | ||
173 | [[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}" | ||
174 | [ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))" | ||
175 | |||
176 | # setup default runlevel | ||
177 | [[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}" | ||
178 | |||
179 | if [ -f $(get_profile prepare_custom) ] | ||
180 | then | ||
181 | echo Running custom user script ... | ||
182 | source $(get_profile prepare_custom) || die "running custom user script" | ||
183 | fi | ||
184 | |||
185 | niro | 346 | echo Cleaning unwanted files ... |
186 | :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab" | ||
187 | niro | 360 | [ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history |
188 | niro | 346 | } |
189 | |||
190 | generate_rootfs() | ||
191 | { | ||
192 | echo Generating squashfs compressed rootfs loopfile ... | ||
193 | mksquashfs ${CDCHROOTDIR} ${LIVECDROOT}/livecdrootfs.sqsh #>/dev/null 2>&1 | ||
194 | |||
195 | echo Moving rootfs loopfile to isoroot ... | ||
196 | install -d ${CDISOROOT} | ||
197 | mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT} | ||
198 | } | ||
199 | |||
200 | install_bootloader() | ||
201 | { | ||
202 | echo Installing Bootloader ... | ||
203 | |||
204 | # iso linux binary | ||
205 | install -d ${CDISOROOT}/isolinux | ||
206 | niro | 348 | install /usr/lib/mkinitrd/isolinux.bin ${CDISOROOT}/isolinux || die |
207 | niro | 346 | |
208 | # kernel | ||
209 | local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))" | ||
210 | install ${CDCHROOTDIR}/boot/${kimg} ${CDISOROOT}/isolinux/${CDKERNELNAME} || die | ||
211 | |||
212 | install -m 0644 $(get_profile isolinux.cfg) ${CDISOROOT}/isolinux || die | ||
213 | install -m 0644 $(get_profile boot.lss) ${CDISOROOT}/isolinux || die | ||
214 | install -m 0644 $(get_profile boot.msg) ${CDISOROOT}/isolinux || die | ||
215 | install -m 0644 $(get_profile help.msg) ${CDISOROOT}/isolinux || die | ||
216 | |||
217 | return 0 | ||
218 | } | ||
219 | |||
220 | generate_initrd() | ||
221 | { | ||
222 | local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})" | ||
223 | |||
224 | echo Generating initrd image ... | ||
225 | echo '#!/bin/bash' > ${CHROOTSH} || die | ||
226 | echo 'kv="$(readlink /boot/vmlinuz)"' >> ${CHROOTSH} || die | ||
227 | echo 'kv="${kv/kernel-}/"' >> ${CHROOTSH} || die | ||
228 | echo 'mkinitrd-livecd -f --initramfs /initrd.gz ${kv}' >> ${CHROOTSH} || die | ||
229 | chmod +x ${CHROOTSH} || die | ||
230 | chroot ${CDCHROOTDIR} /$(basename ${CHROOTSH}) || die | ||
231 | [[ -f ${CHROOTSH} ]] && rm ${CHROOTSH} || die | ||
232 | |||
233 | # move initrd to isoroot | ||
234 | install -d ${CDISOROOT}/isolinux || die | ||
235 | mv ${CDCHROOTDIR}/initrd.gz ${CDISOROOT}/isolinux || die | ||
236 | } | ||
237 | |||
238 | generate_iso() | ||
239 | { | ||
240 | echo Generating ISO Image ... | ||
241 | install -d ${CDISOROOT} | ||
242 | pushd ${CDISOROOT} && | ||
243 | mkisofs -rock \ | ||
244 | -full-iso9660-filenames \ | ||
245 | -allow-leading-dots \ | ||
246 | -disable-deep-relocation \ | ||
247 | -output ${LIVECDROOT}/${CDISONAME} \ | ||
248 | -eltorito-boot isolinux/isolinux.bin \ | ||
249 | -eltorito-catalog isolinux/boot.cat \ | ||
250 | -no-emul-boot \ | ||
251 | -boot-load-size 4 \ | ||
252 | -boot-info-table \ | ||
253 | -volid "${CDID}" \ | ||
254 | ${CDISOROOT} #&> /dev/null | ||
255 | popd | ||
256 | } | ||
257 | |||
258 | niro | 464 | generate_dvd() |
259 | { | ||
260 | echo Generating DVD Image ... | ||
261 | install -d ${CDISOROOT} | ||
262 | pushd ${CDISOROOT} && | ||
263 | growisofs -dvd-compat \ | ||
264 | -rock \ | ||
265 | -full-iso9660-filenames \ | ||
266 | -allow-leading-dots \ | ||
267 | -disable-deep-relocation \ | ||
268 | -output ${LIVECDROOT}/${CDISONAME} \ | ||
269 | -eltorito-boot isolinux/isolinux.bin \ | ||
270 | -eltorito-catalog isolinux/boot.cat \ | ||
271 | -no-emul-boot \ | ||
272 | -boot-load-size 4 \ | ||
273 | -boot-info-table \ | ||
274 | -volid "${CDID}" \ | ||
275 | ${CDISOROOT} #&> /dev/null | ||
276 | popd | ||
277 | } | ||
278 | |||
279 | niro | 346 | enter_livecd() |
280 | { | ||
281 | mount -t sysfs sysfs ${CDCHROOTDIR}/proc | ||
282 | mount -t proc proc ${CDCHROOTDIR}/proc | ||
283 | mount -o bind /dev ${CDCHROOTDIR}/dev | ||
284 | |||
285 | chroot ${CDCHROOTDIR} \ | ||
286 | /usr/bin/env -i \ | ||
287 | HOME=/root \ | ||
288 | TERM=$TERM PS1='\u:\w\$ ' \ | ||
289 | PATH=/bin:/usr/bin:/sbin:/usr/sbin \ | ||
290 | niro | 472 | http_proxy=${http_proxy} \ |
291 | ftp_proxy=${ftp_proxy} \ | ||
292 | no_proxy=${no_proxy} \ | ||
293 | niro | 346 | /bin/bash -i |
294 | } | ||
295 | |||
296 | niro | 360 | usage() |
297 | { | ||
298 | echo "Usage: $(basename $0) [command] [profile] ..." | ||
299 | echo | ||
300 | echo "Commands:" | ||
301 | echo " bootstrap - bootstraps the rootfs for the livecd" | ||
302 | echo " prepare - prepare the rootfs to run from a livecd" | ||
303 | echo " rootfs - generates the squashfs rootfs image" | ||
304 | echo " initrd - generates a livecd suitable initrd" | ||
305 | echo " bootloader - installs the bootloader" | ||
306 | echo " isogen - generate the final livecd iso image" | ||
307 | niro | 464 | echo " dvdgen - same as isogen but creates a dvd-image" |
308 | niro | 360 | echo " all - runs all tasks to get a livecd from zero" |
309 | niro | 472 | echo " enter - enters the rootfs of a livecd" |
310 | niro | 360 | echo |
311 | echo " for example '$(basename $0) all default'" | ||
312 | echo " creates a livecd using the default profile." | ||
313 | echo | ||
314 | } | ||
315 | |||
316 | niro | 346 | # source profile config - overrides all other vars |
317 | [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config | ||
318 | |||
319 | niro | 360 | case $1 in |
320 | bootstrap) bootstrap_system;; | ||
321 | prepare) prepare_iso;; | ||
322 | rootfs) generate_rootfs;; | ||
323 | initrd) generate_initrd;; | ||
324 | bootloader) install_bootloader;; | ||
325 | isogen) generate_iso;; | ||
326 | niro | 464 | dvdgen) generate_dvd;; |
327 | niro | 360 | all) |
328 | bootstrap_system | ||
329 | prepare_iso | ||
330 | generate_rootfs | ||
331 | generate_initrd | ||
332 | install_bootloader | ||
333 | niro | 464 | if [[ ${DEFINE_DVD} = 1 ]] |
334 | then | ||
335 | generate_dvd | ||
336 | else | ||
337 | generate_iso | ||
338 | fi | ||
339 | niro | 360 | ;; |
340 | niro | 472 | enter) enter_livecd ;; |
341 | niro | 360 | *|'') usage;; |
342 | esac |