Annotation of /trunk/mlivecdbuild/mlivecdbuild2.sh
Parent Directory | Revision Log
Revision 3226 -
(hide annotations)
(download)
(as text)
Tue Sep 19 09:30:48 2023 UTC (8 months, 1 week ago) by niro
File MIME type: application/x-sh
File size: 17877 byte(s)
Tue Sep 19 09:30:48 2023 UTC (8 months, 1 week ago) by niro
File MIME type: application/x-sh
File size: 17877 byte(s)
-no line break
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 | niro | 1422 | # get full path to isolinux.bin, may vary on multilib systems |
23 | if [[ -f /usr/share/syslinux/isolinux.bin ]] | ||
24 | niro | 1402 | then |
25 | niro | 3223 | ISOLINUX_BIN="/usr/share/syslinux/isolinux.bin" |
26 | niro | 1422 | elif [[ -f /usr/lib64/mkinitrd/isolinux.bin ]] |
27 | then | ||
28 | niro | 3223 | ISOLINUX_BIN="/usr/lib64/mkinitrd/isolinux.bin" |
29 | niro | 1402 | else |
30 | niro | 3223 | ISOLINUX_BIN="/usr/lib/mkinitrd/isolinux.bin" |
31 | niro | 1402 | fi |
32 | |||
33 | niro | 3224 | if [[ -f /usr/share/syslinux/ldlinux.c32 ]] |
34 | then | ||
35 | LDLINUX_C32="/usr/share/syslinux/ldlinux.c32" | ||
36 | else | ||
37 | LDLINUX_C32="" | ||
38 | fi | ||
39 | |||
40 | niro | 346 | die() { echo "ERROR: $@"; exit 1; } |
41 | |||
42 | # get_profile $filename | ||
43 | get_profile() | ||
44 | { | ||
45 | local file="$1" | ||
46 | |||
47 | if [[ -z ${file} ]] || [[ ! -e ${PROFILES_DIR}/${CDPROFILE}/${file} ]] | ||
48 | then | ||
49 | echo "${GLOBAL_PROFILE}/${file}" | ||
50 | return 0 | ||
51 | fi | ||
52 | |||
53 | echo "${PROFILES_DIR}/${CDPROFILE}/${file}" | ||
54 | } | ||
55 | |||
56 | bootstrap_system() | ||
57 | { | ||
58 | mage-bootstrap \ | ||
59 | --root "${CDCHROOTDIR}" \ | ||
60 | --magerc "${MAGERC}" \ | ||
61 | --profile "${MAGE_PROFILE}" \ | ||
62 | --toolchain "${TOOLCHAIN}" \ | ||
63 | --basesystem "${BASESYSTEM}" \ | ||
64 | niro | 2098 | --update-tarball \ |
65 | niro | 346 | || die "bootstrapping toolchain" |
66 | } | ||
67 | |||
68 | niro | 360 | custom_services() |
69 | { | ||
70 | local cmd="$1" | ||
71 | local services="$2" | ||
72 | niro | 1403 | local systemdcmd |
73 | niro | 360 | |
74 | case ${cmd} in | ||
75 | niro | 2319 | add|del|default|is-enabled) |
76 | niro | 471 | # add given services from profile |
77 | if [[ -n ${services} ]] | ||
78 | then | ||
79 | local i | ||
80 | for i in ${services} | ||
81 | do | ||
82 | niro | 1403 | # systemd |
83 | niro | 1821 | if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
84 | niro | 1403 | then |
85 | case ${cmd} in | ||
86 | add) chroot ${CDCHROOTDIR} systemctl enable ${i} ;; | ||
87 | del) chroot ${CDCHROOTDIR} systemctl disable ${i} ;; | ||
88 | niro | 2319 | is-enabled) chroot ${CDCHROOTDIR} systemctl is-enabled ${i} ;; |
89 | niro | 1531 | default) |
90 | # convert targets | ||
91 | case ${i} in | ||
92 | niro | 1821 | 2|3|multi-user) service="multi-user.target" ;; |
93 | 5|graphical) service="graphical.target" ;; | ||
94 | niro | 1531 | esac |
95 | chroot ${CDCHROOTDIR} systemctl enable ${i} ;; | ||
96 | niro | 1403 | esac |
97 | fi | ||
98 | # busybox and sysvinit | ||
99 | niro | 1821 | if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] && [[ ! -x ${CDCHROOTDIR}/bin/systemctl ]] && [[ ! -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
100 | niro | 1403 | then |
101 | MROOT="${CDCHROOTDIR}" rc-config ${cmd} ${i} || die "rc ${cmd} ${i}" | ||
102 | fi | ||
103 | niro | 471 | done |
104 | fi | ||
105 | ;; | ||
106 | niro | 360 | *) die "custom_services: unkown command ${cmd}";; |
107 | esac | ||
108 | } | ||
109 | |||
110 | add_initrc() | ||
111 | { | ||
112 | local var="$1" | ||
113 | |||
114 | # sanity checks | ||
115 | niro | 473 | [[ -z ${CDCHROOTDIR} ]] && die "\$CDCHROOTDIR not given." |
116 | niro | 360 | echo "${var}" >> ${CDCHROOTDIR}/.installrc || die "add_initrc() adding \$var" |
117 | } | ||
118 | |||
119 | custom_packages() | ||
120 | { | ||
121 | local cmd="$1" | ||
122 | local packages="$2" | ||
123 | |||
124 | case ${cmd} in | ||
125 | niro | 471 | install|uninstall) |
126 | if [[ -n ${packages} ]] | ||
127 | then | ||
128 | :> ${CDCHROOTDIR}/.installrc | ||
129 | niro | 472 | |
130 | # respect proxies | ||
131 | [[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}" | ||
132 | [[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}" | ||
133 | [[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}" | ||
134 | |||
135 | niro | 580 | # do not auto-start any services! |
136 | add_initrc "export MAGE_BOOTSTRAP=true" | ||
137 | niro | 863 | add_initrc 'die() { if [ $? -eq 1 ]; then echo "ERROR: $@"; exit 1; fi; }' |
138 | niro | 580 | |
139 | niro | 471 | local i |
140 | for i in ${packages} | ||
141 | do | ||
142 | niro | 863 | add_initrc "mage ${cmd} ${i} || die ${i}" |
143 | niro | 471 | done |
144 | add_initrc "mage clean" | ||
145 | |||
146 | # now run the .installrc script | ||
147 | mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc" | ||
148 | mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys" | ||
149 | mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev" | ||
150 | chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting" | ||
151 | umount ${CDCHROOTDIR}/dev || die "umount dev" | ||
152 | umount ${CDCHROOTDIR}/proc || die "umount proc" | ||
153 | umount ${CDCHROOTDIR}/sys || die "umount sys" | ||
154 | [ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc | ||
155 | fi | ||
156 | ;; | ||
157 | niro | 360 | *) die "custom_packages: unkown command ${cmd}";; |
158 | esac | ||
159 | } | ||
160 | |||
161 | read_config() | ||
162 | { | ||
163 | local file="$1" | ||
164 | local pkg | ||
165 | |||
166 | ( cat ${file}; echo ) | while read pkg | ||
167 | do | ||
168 | case "${pkg}" in | ||
169 | \#*|"") continue ;; | ||
170 | esac | ||
171 | echo "${pkg}" | ||
172 | done | ||
173 | } | ||
174 | |||
175 | niro | 346 | prepare_iso() |
176 | { | ||
177 | echo Preparing LiveCD ISO Image ... | ||
178 | |||
179 | # fixes some issues with xfree/xorg xkb | ||
180 | niro | 1821 | if [[ -L ${CDCHROOTDIR}/etc/X11/xkb ]] && |
181 | [[ -d ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ]] | ||
182 | niro | 346 | then |
183 | rm ${CDCHROOTDIR}/etc/X11/xkb || die | ||
184 | mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die | ||
185 | ln -s ../../../../etc/X11/xkb ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb || die | ||
186 | fi | ||
187 | |||
188 | niro | 1821 | # fix issues with >=dracut-014 which drops some default modules like livecd |
189 | if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] || | ||
190 | [[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] || | ||
191 | [[ -x ${CDCHROOTDIR}/usr/bin/dracut ]] | ||
192 | then | ||
193 | install -d ${CDCHROOTDIR}/etc/dracut.conf.d || die | ||
194 | niro | 3226 | echo 'add_dracutmodules+=" dmsquash-live "' > ${CDCHROOTDIR}/etc/dracut.conf.d/02-livecd.conf || die |
195 | niro | 1821 | fi |
196 | |||
197 | niro | 1403 | # only on sysvinit or busybox systems |
198 | if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] | ||
199 | then | ||
200 | install -m 0644 $(get_profile inittab) ${CDCHROOTDIR}/etc/inittab || die | ||
201 | fi | ||
202 | niro | 1821 | if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
203 | niro | 1446 | then |
204 | niro | 1531 | # check lock group on systemd systems |
205 | niro | 1446 | if [[ -z $(chroot ${CDCHROOTDIR} getent group lock) ]] |
206 | then | ||
207 | niro | 1531 | echo "adding missing group 'lock'" |
208 | niro | 2122 | chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 54" lock |
209 | niro | 1446 | fi |
210 | niro | 1531 | # dbus plugdev group |
211 | if [[ -z $(chroot ${CDCHROOTDIR} getent group plugdev) ]] | ||
212 | then | ||
213 | echo "adding missing group 'plugdev'" | ||
214 | niro | 2122 | chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 302" plugdev |
215 | niro | 1531 | fi |
216 | # dbus messagebus group | ||
217 | if [[ -z $(chroot ${CDCHROOTDIR} getent group messagebus) ]] | ||
218 | then | ||
219 | echo "adding missing group 'messagebus'" | ||
220 | niro | 2122 | chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 300" messagebus |
221 | niro | 1531 | fi |
222 | # dbus messagebus user | ||
223 | if [[ -z $(chroot ${CDCHROOTDIR} getent passwd messagebus) ]] | ||
224 | then | ||
225 | echo "adding missing user 'messagebus'" | ||
226 | niro | 2122 | chroot ${CDCHROOTDIR} /usr/lib/mage/museradd -o "-u 300 -g messagebus -d /dev/null -s /bin/false" messagebus |
227 | niro | 1531 | fi |
228 | niro | 1446 | fi |
229 | niro | 346 | install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die |
230 | install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die | ||
231 | install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die | ||
232 | niro | 712 | install -m 0644 $(get_profile net.eth0) ${CDCHROOTDIR}/etc/conf.d/net.eth0 || die |
233 | niro | 346 | echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die |
234 | niro | 1821 | install -d ${CDCHROOTDIR}/mnt/magellan || die |
235 | niro | 346 | |
236 | echo Setting up services ... | ||
237 | |||
238 | niro | 1531 | # install systemd default services |
239 | if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] | ||
240 | then | ||
241 | # install tmpfs /tmp and /var/tmp | ||
242 | install -m 0644 $(get_profile tmp.mount) ${CDCHROOTDIR}/lib/systemd/system/ || die | ||
243 | install -m 0644 $(get_profile var-tmp.mount) ${CDCHROOTDIR}/lib/systemd/system/ || die | ||
244 | # enable them | ||
245 | ln -snf ../tmp.mount ${CDCHROOTDIR}/lib/systemd/system/local-fs.target.wants/tmp.mount || die | ||
246 | ln -snf ../var-tmp.mount ${CDCHROOTDIR}/lib/systemd/system/local-fs.target.wants/var-tmp.mount || die | ||
247 | niro | 1821 | fi |
248 | # newer systemd goes to /usr/lib | ||
249 | if [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] | ||
250 | then | ||
251 | # install tmpfs /tmp and /var/tmp | ||
252 | install -m 0644 $(get_profile tmp.mount) ${CDCHROOTDIR}/usr/lib/systemd/system/ || die | ||
253 | install -m 0644 $(get_profile var-tmp.mount) ${CDCHROOTDIR}/usr/lib/systemd/system/ || die | ||
254 | # enable them | ||
255 | ln -snf ../tmp.mount ${CDCHROOTDIR}/usr/lib/systemd/system/local-fs.target.wants/tmp.mount || die | ||
256 | ln -snf ../var-tmp.mount ${CDCHROOTDIR}/usr/lib/systemd/system/local-fs.target.wants/var-tmp.mount || die | ||
257 | fi | ||
258 | niro | 1531 | |
259 | niro | 1821 | if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
260 | then | ||
261 | niro | 1531 | install -m 0644 $(get_profile getty) ${CDCHROOTDIR}/etc/conf.d/getty || die |
262 | |||
263 | niro | 2316 | custom_services add getty@tty1.service |
264 | niro | 1531 | custom_services add remote-fs.target |
265 | # disable readahead | ||
266 | niro | 3225 | custom_services is-enabled systemd-readahead-replay.service && custom_services del systemd-readahead-replay.service |
267 | niro | 2319 | custom_services is-enabled systemd-readahead-collect.service && custom_services del systemd-readahead-collect.service |
268 | niro | 1531 | fi |
269 | |||
270 | niro | 978 | # # add hardware detection |
271 | niro | 1403 | # if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] |
272 | # then | ||
273 | # MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect" | ||
274 | # fi | ||
275 | niro | 346 | |
276 | # del checkfs | ||
277 | niro | 1403 | if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] |
278 | then | ||
279 | MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs" | ||
280 | fi | ||
281 | niro | 346 | |
282 | niro | 360 | # add custom packages |
283 | [[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}" | ||
284 | [ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))" | ||
285 | |||
286 | # del custom packages | ||
287 | [[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}" | ||
288 | [ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))" | ||
289 | |||
290 | # add given services from profile | ||
291 | [[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}" | ||
292 | [ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))" | ||
293 | |||
294 | # del given services from profile | ||
295 | [[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}" | ||
296 | [ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))" | ||
297 | |||
298 | # setup default runlevel | ||
299 | [[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}" | ||
300 | |||
301 | if [ -f $(get_profile prepare_custom) ] | ||
302 | then | ||
303 | echo Running custom user script ... | ||
304 | source $(get_profile prepare_custom) || die "running custom user script" | ||
305 | fi | ||
306 | |||
307 | niro | 346 | echo Cleaning unwanted files ... |
308 | niro | 1403 | # do this only if not a symlink! |
309 | if [[ ! -L ${CDCHROOTDIR}/etc/mtab ]] | ||
310 | then | ||
311 | :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab" | ||
312 | fi | ||
313 | niro | 360 | [ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history |
314 | niro | 346 | } |
315 | |||
316 | generate_rootfs() | ||
317 | { | ||
318 | niro | 1403 | local loopdev |
319 | local size | ||
320 | |||
321 | if [ -f ${LIVECDROOT}/loop/LiveOS/ext3fs.img ] | ||
322 | then | ||
323 | rm ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die | ||
324 | fi | ||
325 | if [ -f ${CDISOROOT}/LiveOS/squashfs.img ] | ||
326 | then | ||
327 | rm ${CDISOROOT}/LiveOS/squashfs.img | ||
328 | fi | ||
329 | if [ -f ${CDISOROOT}/livecdrootfs.sqsh ] | ||
330 | then | ||
331 | rm ${CDISOROOT}/livecdrootfs.sqsh | ||
332 | fi | ||
333 | |||
334 | niro | 346 | echo Generating squashfs compressed rootfs loopfile ... |
335 | niro | 1821 | if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] || |
336 | [[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] || | ||
337 | [[ -x ${CDCHROOTDIR}/usr/bin/dracut ]] | ||
338 | niro | 1403 | then |
339 | install -d ${LIVECDROOT}/loop/{LiveOS,mnt} || die | ||
340 | niro | 346 | |
341 | niro | 1403 | # get the actual size of the chroot |
342 | niro | 1531 | size=$(du -s ${LIVECDROOT}/chroot | sed 's:^\(.*\)[[:space:]].*:\1:') |
343 | niro | 1403 | |
344 | # generate a ext3fs file for devicemapper | ||
345 | dd if=/dev/zero of=${LIVECDROOT}/loop/LiveOS/ext3fs.img bs=1024 count=$(( ${size} + 10 )) || die | ||
346 | # create a filesystem | ||
347 | mkfs.ext3 -L "_${CDID}_EXT3" -m 1 -b 1024 -F ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die | ||
348 | # set mount_counts and check_intervals to 0 | ||
349 | # set dir_index top, to speed up thing with hashed b-trees | ||
350 | # allow acls too | ||
351 | tune2fs -c0 -i0 -Odir_index -ouser_xattr,acl ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die | ||
352 | |||
353 | # losetup the device | ||
354 | loopdev=$(losetup -f) | ||
355 | [[ -z ${loopdev} ]] && die "No unused loopdev found. Maybe you want 'modprobe loop'?" | ||
356 | |||
357 | # mount the image | ||
358 | losetup ${loopdev} ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die | ||
359 | mount ${loopdev} ${LIVECDROOT}/loop/mnt || die | ||
360 | |||
361 | # copy everything to the image file and preserve permissions | ||
362 | ( cd ${CDCHROOTDIR} && tar cpf - . ) | ( cd ${LIVECDROOT}/loop/mnt && tar xvpf - ) | ||
363 | niro | 2099 | sleep 3 |
364 | niro | 1403 | |
365 | # now umount everything and create the squashfs image | ||
366 | umount ${LIVECDROOT}/loop/mnt || die | ||
367 | losetup -d ${loopdev} || die | ||
368 | # remove mount to not ending up in the squashfs image | ||
369 | if [[ -d ${LIVECDROOT}/loop/mnt ]] | ||
370 | then | ||
371 | rm -r ${LIVECDROOT}/loop/mnt || die | ||
372 | fi | ||
373 | mksquashfs ${LIVECDROOT}/loop ${LIVECDROOT}/livecdrootfs.sqsh || die | ||
374 | |||
375 | # final cleanup | ||
376 | if [[ -d ${LIVECDROOT}/loop ]] | ||
377 | then | ||
378 | rm -r ${LIVECDROOT}/loop || die | ||
379 | fi | ||
380 | else | ||
381 | mksquashfs ${CDCHROOTDIR} ${LIVECDROOT}/livecdrootfs.sqsh || die | ||
382 | fi | ||
383 | |||
384 | niro | 346 | echo Moving rootfs loopfile to isoroot ... |
385 | install -d ${CDISOROOT} | ||
386 | niro | 1821 | if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] || |
387 | [[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] || | ||
388 | [[ -x ${CDCHROOTDIR}/usr/bin/dracut ]] | ||
389 | niro | 1403 | then |
390 | install -d ${CDISOROOT}/LiveOS | ||
391 | mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT}/LiveOS/squashfs.img | ||
392 | else | ||
393 | mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT} | ||
394 | fi | ||
395 | niro | 346 | } |
396 | |||
397 | install_bootloader() | ||
398 | { | ||
399 | echo Installing Bootloader ... | ||
400 | |||
401 | # iso linux binary | ||
402 | install -d ${CDISOROOT}/isolinux | ||
403 | niro | 1402 | install ${ISOLINUX_BIN} ${CDISOROOT}/isolinux || die |
404 | niro | 3224 | if [[ -n ${LDLINUX_C32} ]] |
405 | then | ||
406 | install ${LDLINUX_C32} ${CDISOROOT}/isolinux || die | ||
407 | fi | ||
408 | niro | 346 | |
409 | # kernel | ||
410 | niro | 2123 | # support kernel installations without symlinks |
411 | if [ -L ${CDCHROOTDIR}/boot/vmlinuz ] | ||
412 | then | ||
413 | local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))" | ||
414 | else | ||
415 | local kimg="$(find ${CDCHROOTDIR}/boot -name kernel-\* -printf '%f\n')" | ||
416 | fi | ||
417 | niro | 346 | install ${CDCHROOTDIR}/boot/${kimg} ${CDISOROOT}/isolinux/${CDKERNELNAME} || die |
418 | |||
419 | install -m 0644 $(get_profile isolinux.cfg) ${CDISOROOT}/isolinux || die | ||
420 | install -m 0644 $(get_profile boot.lss) ${CDISOROOT}/isolinux || die | ||
421 | install -m 0644 $(get_profile boot.msg) ${CDISOROOT}/isolinux || die | ||
422 | install -m 0644 $(get_profile help.msg) ${CDISOROOT}/isolinux || die | ||
423 | niro | 1531 | # support the new layout too |
424 | if [[ -f $(get_profile index.msg) ]] | ||
425 | then | ||
426 | install -m 0644 $(get_profile index.msg) ${CDISOROOT}/isolinux || die | ||
427 | fi | ||
428 | if [[ -f $(get_profile debug.msg) ]] | ||
429 | then | ||
430 | install -m 0644 $(get_profile debug.msg) ${CDISOROOT}/isolinux || die | ||
431 | fi | ||
432 | niro | 346 | |
433 | return 0 | ||
434 | } | ||
435 | |||
436 | generate_initrd() | ||
437 | { | ||
438 | local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})" | ||
439 | |||
440 | niro | 1403 | is_loc_mounted "${CDCHROOTDIR}/sys" || mount -t sysfs sysfs ${CDCHROOTDIR}/sys |
441 | is_loc_mounted "${CDCHROOTDIR}/proc" || mount -t proc proc ${CDCHROOTDIR}/proc | ||
442 | is_loc_mounted "${CDCHROOTDIR}/dev" || mount -o bind /dev ${CDCHROOTDIR}/dev | ||
443 | |||
444 | niro | 346 | echo Generating initrd image ... |
445 | echo '#!/bin/bash' > ${CHROOTSH} || die | ||
446 | niro | 1403 | echo 'export LC_ALL=C' >> ${CHROOTSH} || die |
447 | niro | 2123 | # support kernel installations without symlinks |
448 | if [ -L ${CDCHROOTDIR}/boot/vmlinuz ] | ||
449 | then | ||
450 | echo 'kv="$(readlink /boot/vmlinuz)"' >> ${CHROOTSH} || die | ||
451 | else | ||
452 | echo "kv=\$(find /boot -name kernel-\* -printf '%f\n')" >> ${CHROOTSH} || die | ||
453 | fi | ||
454 | echo 'kv="${kv/kernel-/}"' >> ${CHROOTSH} || die | ||
455 | niro | 1403 | # prefer dracut |
456 | niro | 1821 | echo 'if [[ -x /sbin/dracut ]] || [[ -x /usr/sbin/dracut ]] || [[ -x /usr/bin/dracut ]]' >> ${CHROOTSH} || die |
457 | niro | 1403 | echo 'then' >> ${CHROOTSH} || die |
458 | echo ' dracut -v -f /initrd.gz ${kv}' >> ${CHROOTSH} || die | ||
459 | echo 'else' >> ${CHROOTSH} || die | ||
460 | echo ' mkinitrd-livecd -f --initramfs /initrd.gz ${kv}' >> ${CHROOTSH} || die | ||
461 | echo 'fi' >> ${CHROOTSH} || die | ||
462 | niro | 346 | chmod +x ${CHROOTSH} || die |
463 | chroot ${CDCHROOTDIR} /$(basename ${CHROOTSH}) || die | ||
464 | [[ -f ${CHROOTSH} ]] && rm ${CHROOTSH} || die | ||
465 | |||
466 | niro | 1403 | is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev |
467 | is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc | ||
468 | is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys | ||
469 | |||
470 | niro | 346 | # move initrd to isoroot |
471 | install -d ${CDISOROOT}/isolinux || die | ||
472 | mv ${CDCHROOTDIR}/initrd.gz ${CDISOROOT}/isolinux || die | ||
473 | } | ||
474 | |||
475 | generate_iso() | ||
476 | { | ||
477 | echo Generating ISO Image ... | ||
478 | install -d ${CDISOROOT} | ||
479 | pushd ${CDISOROOT} && | ||
480 | mkisofs -rock \ | ||
481 | -full-iso9660-filenames \ | ||
482 | -allow-leading-dots \ | ||
483 | -disable-deep-relocation \ | ||
484 | -output ${LIVECDROOT}/${CDISONAME} \ | ||
485 | -eltorito-boot isolinux/isolinux.bin \ | ||
486 | -eltorito-catalog isolinux/boot.cat \ | ||
487 | -no-emul-boot \ | ||
488 | -boot-load-size 4 \ | ||
489 | -boot-info-table \ | ||
490 | -volid "${CDID}" \ | ||
491 | ${CDISOROOT} #&> /dev/null | ||
492 | popd | ||
493 | } | ||
494 | |||
495 | enter_livecd() | ||
496 | { | ||
497 | niro | 1403 | is_loc_mounted "${CDCHROOTDIR}/sys" || mount -t sysfs sysfs ${CDCHROOTDIR}/sys |
498 | is_loc_mounted "${CDCHROOTDIR}/proc" || mount -t proc proc ${CDCHROOTDIR}/proc | ||
499 | is_loc_mounted "${CDCHROOTDIR}/dev" || mount -o bind /dev ${CDCHROOTDIR}/dev | ||
500 | niro | 346 | |
501 | chroot ${CDCHROOTDIR} \ | ||
502 | /usr/bin/env -i \ | ||
503 | HOME=/root \ | ||
504 | TERM=$TERM PS1='\u:\w\$ ' \ | ||
505 | PATH=/bin:/usr/bin:/sbin:/usr/sbin \ | ||
506 | niro | 472 | http_proxy=${http_proxy} \ |
507 | ftp_proxy=${ftp_proxy} \ | ||
508 | no_proxy=${no_proxy} \ | ||
509 | niro | 346 | /bin/bash -i |
510 | niro | 609 | |
511 | niro | 1403 | is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev |
512 | is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc | ||
513 | is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys | ||
514 | niro | 346 | } |
515 | |||
516 | niro | 1403 | is_loc_mounted() |
517 | { | ||
518 | local filesys | ||
519 | local i | ||
520 | filesys=$1 | ||
521 | |||
522 | i="$(cat /proc/mounts | grep " ${filesys} " | cut -d ' ' -f2)" | ||
523 | [[ ${i} != ${filesys} ]] && return 1 | ||
524 | |||
525 | return 0 | ||
526 | } | ||
527 | |||
528 | trap_exit() | ||
529 | { | ||
530 | is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev | ||
531 | is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc | ||
532 | is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys | ||
533 | } | ||
534 | |||
535 | niro | 360 | usage() |
536 | { | ||
537 | echo "Usage: $(basename $0) [command] [profile] ..." | ||
538 | echo | ||
539 | echo "Commands:" | ||
540 | echo " bootstrap - bootstraps the rootfs for the livecd" | ||
541 | echo " prepare - prepare the rootfs to run from a livecd" | ||
542 | echo " rootfs - generates the squashfs rootfs image" | ||
543 | echo " initrd - generates a livecd suitable initrd" | ||
544 | echo " bootloader - installs the bootloader" | ||
545 | echo " isogen - generate the final livecd iso image" | ||
546 | echo " all - runs all tasks to get a livecd from zero" | ||
547 | niro | 472 | echo " enter - enters the rootfs of a livecd" |
548 | niro | 360 | echo |
549 | echo " for example '$(basename $0) all default'" | ||
550 | echo " creates a livecd using the default profile." | ||
551 | echo | ||
552 | } | ||
553 | |||
554 | niro | 1403 | # set some proper traps |
555 | trap "trap_exit" SIGINT SIGQUIT | ||
556 | |||
557 | niro | 346 | # source profile config - overrides all other vars |
558 | [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config | ||
559 | |||
560 | niro | 360 | case $1 in |
561 | bootstrap) bootstrap_system;; | ||
562 | prepare) prepare_iso;; | ||
563 | rootfs) generate_rootfs;; | ||
564 | initrd) generate_initrd;; | ||
565 | bootloader) install_bootloader;; | ||
566 | isogen) generate_iso;; | ||
567 | all) | ||
568 | bootstrap_system | ||
569 | prepare_iso | ||
570 | generate_rootfs | ||
571 | generate_initrd | ||
572 | install_bootloader | ||
573 | niro | 713 | generate_iso |
574 | niro | 360 | ;; |
575 | niro | 472 | enter) enter_livecd ;; |
576 | niro | 360 | *|'') usage;; |
577 | esac |