Annotation of /trunk/mlivecdbuild/mlivecdbuild2.sh
Parent Directory | Revision Log
Revision 3225 -
(hide annotations)
(download)
(as text)
Tue Sep 19 09:27:33 2023 UTC (8 months, 1 week ago) by niro
File MIME type: application/x-sh
File size: 17882 byte(s)
Tue Sep 19 09:27:33 2023 UTC (8 months, 1 week ago) by niro
File MIME type: application/x-sh
File size: 17882 byte(s)
-fixed whitespaces
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 | echo 'add_dracutmodules+=" dmsquash-live "' \ | ||
195 | > ${CDCHROOTDIR}/etc/dracut.conf.d/02-livecd.conf || die | ||
196 | fi | ||
197 | |||
198 | niro | 1403 | # only on sysvinit or busybox systems |
199 | if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] | ||
200 | then | ||
201 | install -m 0644 $(get_profile inittab) ${CDCHROOTDIR}/etc/inittab || die | ||
202 | fi | ||
203 | niro | 1821 | if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
204 | niro | 1446 | then |
205 | niro | 1531 | # check lock group on systemd systems |
206 | niro | 1446 | if [[ -z $(chroot ${CDCHROOTDIR} getent group lock) ]] |
207 | then | ||
208 | niro | 1531 | echo "adding missing group 'lock'" |
209 | niro | 2122 | chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 54" lock |
210 | niro | 1446 | fi |
211 | niro | 1531 | # dbus plugdev group |
212 | if [[ -z $(chroot ${CDCHROOTDIR} getent group plugdev) ]] | ||
213 | then | ||
214 | echo "adding missing group 'plugdev'" | ||
215 | niro | 2122 | chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 302" plugdev |
216 | niro | 1531 | fi |
217 | # dbus messagebus group | ||
218 | if [[ -z $(chroot ${CDCHROOTDIR} getent group messagebus) ]] | ||
219 | then | ||
220 | echo "adding missing group 'messagebus'" | ||
221 | niro | 2122 | chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 300" messagebus |
222 | niro | 1531 | fi |
223 | # dbus messagebus user | ||
224 | if [[ -z $(chroot ${CDCHROOTDIR} getent passwd messagebus) ]] | ||
225 | then | ||
226 | echo "adding missing user 'messagebus'" | ||
227 | niro | 2122 | chroot ${CDCHROOTDIR} /usr/lib/mage/museradd -o "-u 300 -g messagebus -d /dev/null -s /bin/false" messagebus |
228 | niro | 1531 | fi |
229 | niro | 1446 | fi |
230 | niro | 346 | install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die |
231 | install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die | ||
232 | install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die | ||
233 | niro | 712 | install -m 0644 $(get_profile net.eth0) ${CDCHROOTDIR}/etc/conf.d/net.eth0 || die |
234 | niro | 346 | echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die |
235 | niro | 1821 | install -d ${CDCHROOTDIR}/mnt/magellan || die |
236 | niro | 346 | |
237 | echo Setting up services ... | ||
238 | |||
239 | niro | 1531 | # install systemd default services |
240 | if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] | ||
241 | then | ||
242 | # install tmpfs /tmp and /var/tmp | ||
243 | install -m 0644 $(get_profile tmp.mount) ${CDCHROOTDIR}/lib/systemd/system/ || die | ||
244 | install -m 0644 $(get_profile var-tmp.mount) ${CDCHROOTDIR}/lib/systemd/system/ || die | ||
245 | # enable them | ||
246 | ln -snf ../tmp.mount ${CDCHROOTDIR}/lib/systemd/system/local-fs.target.wants/tmp.mount || die | ||
247 | ln -snf ../var-tmp.mount ${CDCHROOTDIR}/lib/systemd/system/local-fs.target.wants/var-tmp.mount || die | ||
248 | niro | 1821 | fi |
249 | # newer systemd goes to /usr/lib | ||
250 | if [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] | ||
251 | then | ||
252 | # install tmpfs /tmp and /var/tmp | ||
253 | install -m 0644 $(get_profile tmp.mount) ${CDCHROOTDIR}/usr/lib/systemd/system/ || die | ||
254 | install -m 0644 $(get_profile var-tmp.mount) ${CDCHROOTDIR}/usr/lib/systemd/system/ || die | ||
255 | # enable them | ||
256 | ln -snf ../tmp.mount ${CDCHROOTDIR}/usr/lib/systemd/system/local-fs.target.wants/tmp.mount || die | ||
257 | ln -snf ../var-tmp.mount ${CDCHROOTDIR}/usr/lib/systemd/system/local-fs.target.wants/var-tmp.mount || die | ||
258 | fi | ||
259 | niro | 1531 | |
260 | niro | 1821 | if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
261 | then | ||
262 | niro | 1531 | install -m 0644 $(get_profile getty) ${CDCHROOTDIR}/etc/conf.d/getty || die |
263 | |||
264 | niro | 2316 | custom_services add getty@tty1.service |
265 | niro | 1531 | custom_services add remote-fs.target |
266 | # disable readahead | ||
267 | niro | 3225 | custom_services is-enabled systemd-readahead-replay.service && custom_services del systemd-readahead-replay.service |
268 | niro | 2319 | custom_services is-enabled systemd-readahead-collect.service && custom_services del systemd-readahead-collect.service |
269 | niro | 1531 | fi |
270 | |||
271 | niro | 978 | # # add hardware detection |
272 | niro | 1403 | # if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] |
273 | # then | ||
274 | # MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect" | ||
275 | # fi | ||
276 | niro | 346 | |
277 | # del checkfs | ||
278 | niro | 1403 | if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] |
279 | then | ||
280 | MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs" | ||
281 | fi | ||
282 | niro | 346 | |
283 | niro | 360 | # add custom packages |
284 | [[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}" | ||
285 | [ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))" | ||
286 | |||
287 | # del custom packages | ||
288 | [[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}" | ||
289 | [ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))" | ||
290 | |||
291 | # add given services from profile | ||
292 | [[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}" | ||
293 | [ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))" | ||
294 | |||
295 | # del given services from profile | ||
296 | [[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}" | ||
297 | [ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))" | ||
298 | |||
299 | # setup default runlevel | ||
300 | [[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}" | ||
301 | |||
302 | if [ -f $(get_profile prepare_custom) ] | ||
303 | then | ||
304 | echo Running custom user script ... | ||
305 | source $(get_profile prepare_custom) || die "running custom user script" | ||
306 | fi | ||
307 | |||
308 | niro | 346 | echo Cleaning unwanted files ... |
309 | niro | 1403 | # do this only if not a symlink! |
310 | if [[ ! -L ${CDCHROOTDIR}/etc/mtab ]] | ||
311 | then | ||
312 | :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab" | ||
313 | fi | ||
314 | niro | 360 | [ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history |
315 | niro | 346 | } |
316 | |||
317 | generate_rootfs() | ||
318 | { | ||
319 | niro | 1403 | local loopdev |
320 | local size | ||
321 | |||
322 | if [ -f ${LIVECDROOT}/loop/LiveOS/ext3fs.img ] | ||
323 | then | ||
324 | rm ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die | ||
325 | fi | ||
326 | if [ -f ${CDISOROOT}/LiveOS/squashfs.img ] | ||
327 | then | ||
328 | rm ${CDISOROOT}/LiveOS/squashfs.img | ||
329 | fi | ||
330 | if [ -f ${CDISOROOT}/livecdrootfs.sqsh ] | ||
331 | then | ||
332 | rm ${CDISOROOT}/livecdrootfs.sqsh | ||
333 | fi | ||
334 | |||
335 | niro | 346 | echo Generating squashfs compressed rootfs loopfile ... |
336 | niro | 1821 | if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] || |
337 | [[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] || | ||
338 | [[ -x ${CDCHROOTDIR}/usr/bin/dracut ]] | ||
339 | niro | 1403 | then |
340 | install -d ${LIVECDROOT}/loop/{LiveOS,mnt} || die | ||
341 | niro | 346 | |
342 | niro | 1403 | # get the actual size of the chroot |
343 | niro | 1531 | size=$(du -s ${LIVECDROOT}/chroot | sed 's:^\(.*\)[[:space:]].*:\1:') |
344 | niro | 1403 | |
345 | # generate a ext3fs file for devicemapper | ||
346 | dd if=/dev/zero of=${LIVECDROOT}/loop/LiveOS/ext3fs.img bs=1024 count=$(( ${size} + 10 )) || die | ||
347 | # create a filesystem | ||
348 | mkfs.ext3 -L "_${CDID}_EXT3" -m 1 -b 1024 -F ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die | ||
349 | # set mount_counts and check_intervals to 0 | ||
350 | # set dir_index top, to speed up thing with hashed b-trees | ||
351 | # allow acls too | ||
352 | tune2fs -c0 -i0 -Odir_index -ouser_xattr,acl ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die | ||
353 | |||
354 | # losetup the device | ||
355 | loopdev=$(losetup -f) | ||
356 | [[ -z ${loopdev} ]] && die "No unused loopdev found. Maybe you want 'modprobe loop'?" | ||
357 | |||
358 | # mount the image | ||
359 | losetup ${loopdev} ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die | ||
360 | mount ${loopdev} ${LIVECDROOT}/loop/mnt || die | ||
361 | |||
362 | # copy everything to the image file and preserve permissions | ||
363 | ( cd ${CDCHROOTDIR} && tar cpf - . ) | ( cd ${LIVECDROOT}/loop/mnt && tar xvpf - ) | ||
364 | niro | 2099 | sleep 3 |
365 | niro | 1403 | |
366 | # now umount everything and create the squashfs image | ||
367 | umount ${LIVECDROOT}/loop/mnt || die | ||
368 | losetup -d ${loopdev} || die | ||
369 | # remove mount to not ending up in the squashfs image | ||
370 | if [[ -d ${LIVECDROOT}/loop/mnt ]] | ||
371 | then | ||
372 | rm -r ${LIVECDROOT}/loop/mnt || die | ||
373 | fi | ||
374 | mksquashfs ${LIVECDROOT}/loop ${LIVECDROOT}/livecdrootfs.sqsh || die | ||
375 | |||
376 | # final cleanup | ||
377 | if [[ -d ${LIVECDROOT}/loop ]] | ||
378 | then | ||
379 | rm -r ${LIVECDROOT}/loop || die | ||
380 | fi | ||
381 | else | ||
382 | mksquashfs ${CDCHROOTDIR} ${LIVECDROOT}/livecdrootfs.sqsh || die | ||
383 | fi | ||
384 | |||
385 | niro | 346 | echo Moving rootfs loopfile to isoroot ... |
386 | install -d ${CDISOROOT} | ||
387 | niro | 1821 | if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] || |
388 | [[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] || | ||
389 | [[ -x ${CDCHROOTDIR}/usr/bin/dracut ]] | ||
390 | niro | 1403 | then |
391 | install -d ${CDISOROOT}/LiveOS | ||
392 | mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT}/LiveOS/squashfs.img | ||
393 | else | ||
394 | mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT} | ||
395 | fi | ||
396 | niro | 346 | } |
397 | |||
398 | install_bootloader() | ||
399 | { | ||
400 | echo Installing Bootloader ... | ||
401 | |||
402 | # iso linux binary | ||
403 | install -d ${CDISOROOT}/isolinux | ||
404 | niro | 1402 | install ${ISOLINUX_BIN} ${CDISOROOT}/isolinux || die |
405 | niro | 3224 | if [[ -n ${LDLINUX_C32} ]] |
406 | then | ||
407 | install ${LDLINUX_C32} ${CDISOROOT}/isolinux || die | ||
408 | fi | ||
409 | niro | 346 | |
410 | # kernel | ||
411 | niro | 2123 | # support kernel installations without symlinks |
412 | if [ -L ${CDCHROOTDIR}/boot/vmlinuz ] | ||
413 | then | ||
414 | local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))" | ||
415 | else | ||
416 | local kimg="$(find ${CDCHROOTDIR}/boot -name kernel-\* -printf '%f\n')" | ||
417 | fi | ||
418 | niro | 346 | install ${CDCHROOTDIR}/boot/${kimg} ${CDISOROOT}/isolinux/${CDKERNELNAME} || die |
419 | |||
420 | install -m 0644 $(get_profile isolinux.cfg) ${CDISOROOT}/isolinux || die | ||
421 | install -m 0644 $(get_profile boot.lss) ${CDISOROOT}/isolinux || die | ||
422 | install -m 0644 $(get_profile boot.msg) ${CDISOROOT}/isolinux || die | ||
423 | install -m 0644 $(get_profile help.msg) ${CDISOROOT}/isolinux || die | ||
424 | niro | 1531 | # support the new layout too |
425 | if [[ -f $(get_profile index.msg) ]] | ||
426 | then | ||
427 | install -m 0644 $(get_profile index.msg) ${CDISOROOT}/isolinux || die | ||
428 | fi | ||
429 | if [[ -f $(get_profile debug.msg) ]] | ||
430 | then | ||
431 | install -m 0644 $(get_profile debug.msg) ${CDISOROOT}/isolinux || die | ||
432 | fi | ||
433 | niro | 346 | |
434 | return 0 | ||
435 | } | ||
436 | |||
437 | generate_initrd() | ||
438 | { | ||
439 | local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})" | ||
440 | |||
441 | niro | 1403 | is_loc_mounted "${CDCHROOTDIR}/sys" || mount -t sysfs sysfs ${CDCHROOTDIR}/sys |
442 | is_loc_mounted "${CDCHROOTDIR}/proc" || mount -t proc proc ${CDCHROOTDIR}/proc | ||
443 | is_loc_mounted "${CDCHROOTDIR}/dev" || mount -o bind /dev ${CDCHROOTDIR}/dev | ||
444 | |||
445 | niro | 346 | echo Generating initrd image ... |
446 | echo '#!/bin/bash' > ${CHROOTSH} || die | ||
447 | niro | 1403 | echo 'export LC_ALL=C' >> ${CHROOTSH} || die |
448 | niro | 2123 | # support kernel installations without symlinks |
449 | if [ -L ${CDCHROOTDIR}/boot/vmlinuz ] | ||
450 | then | ||
451 | echo 'kv="$(readlink /boot/vmlinuz)"' >> ${CHROOTSH} || die | ||
452 | else | ||
453 | echo "kv=\$(find /boot -name kernel-\* -printf '%f\n')" >> ${CHROOTSH} || die | ||
454 | fi | ||
455 | echo 'kv="${kv/kernel-/}"' >> ${CHROOTSH} || die | ||
456 | niro | 1403 | # prefer dracut |
457 | niro | 1821 | echo 'if [[ -x /sbin/dracut ]] || [[ -x /usr/sbin/dracut ]] || [[ -x /usr/bin/dracut ]]' >> ${CHROOTSH} || die |
458 | niro | 1403 | echo 'then' >> ${CHROOTSH} || die |
459 | echo ' dracut -v -f /initrd.gz ${kv}' >> ${CHROOTSH} || die | ||
460 | echo 'else' >> ${CHROOTSH} || die | ||
461 | echo ' mkinitrd-livecd -f --initramfs /initrd.gz ${kv}' >> ${CHROOTSH} || die | ||
462 | echo 'fi' >> ${CHROOTSH} || die | ||
463 | niro | 346 | chmod +x ${CHROOTSH} || die |
464 | chroot ${CDCHROOTDIR} /$(basename ${CHROOTSH}) || die | ||
465 | [[ -f ${CHROOTSH} ]] && rm ${CHROOTSH} || die | ||
466 | |||
467 | niro | 1403 | is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev |
468 | is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc | ||
469 | is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys | ||
470 | |||
471 | niro | 346 | # move initrd to isoroot |
472 | install -d ${CDISOROOT}/isolinux || die | ||
473 | mv ${CDCHROOTDIR}/initrd.gz ${CDISOROOT}/isolinux || die | ||
474 | } | ||
475 | |||
476 | generate_iso() | ||
477 | { | ||
478 | echo Generating ISO Image ... | ||
479 | install -d ${CDISOROOT} | ||
480 | pushd ${CDISOROOT} && | ||
481 | mkisofs -rock \ | ||
482 | -full-iso9660-filenames \ | ||
483 | -allow-leading-dots \ | ||
484 | -disable-deep-relocation \ | ||
485 | -output ${LIVECDROOT}/${CDISONAME} \ | ||
486 | -eltorito-boot isolinux/isolinux.bin \ | ||
487 | -eltorito-catalog isolinux/boot.cat \ | ||
488 | -no-emul-boot \ | ||
489 | -boot-load-size 4 \ | ||
490 | -boot-info-table \ | ||
491 | -volid "${CDID}" \ | ||
492 | ${CDISOROOT} #&> /dev/null | ||
493 | popd | ||
494 | } | ||
495 | |||
496 | enter_livecd() | ||
497 | { | ||
498 | niro | 1403 | is_loc_mounted "${CDCHROOTDIR}/sys" || mount -t sysfs sysfs ${CDCHROOTDIR}/sys |
499 | is_loc_mounted "${CDCHROOTDIR}/proc" || mount -t proc proc ${CDCHROOTDIR}/proc | ||
500 | is_loc_mounted "${CDCHROOTDIR}/dev" || mount -o bind /dev ${CDCHROOTDIR}/dev | ||
501 | niro | 346 | |
502 | chroot ${CDCHROOTDIR} \ | ||
503 | /usr/bin/env -i \ | ||
504 | HOME=/root \ | ||
505 | TERM=$TERM PS1='\u:\w\$ ' \ | ||
506 | PATH=/bin:/usr/bin:/sbin:/usr/sbin \ | ||
507 | niro | 472 | http_proxy=${http_proxy} \ |
508 | ftp_proxy=${ftp_proxy} \ | ||
509 | no_proxy=${no_proxy} \ | ||
510 | niro | 346 | /bin/bash -i |
511 | niro | 609 | |
512 | niro | 1403 | is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev |
513 | is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc | ||
514 | is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys | ||
515 | niro | 346 | } |
516 | |||
517 | niro | 1403 | is_loc_mounted() |
518 | { | ||
519 | local filesys | ||
520 | local i | ||
521 | filesys=$1 | ||
522 | |||
523 | i="$(cat /proc/mounts | grep " ${filesys} " | cut -d ' ' -f2)" | ||
524 | [[ ${i} != ${filesys} ]] && return 1 | ||
525 | |||
526 | return 0 | ||
527 | } | ||
528 | |||
529 | trap_exit() | ||
530 | { | ||
531 | is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev | ||
532 | is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc | ||
533 | is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys | ||
534 | } | ||
535 | |||
536 | niro | 360 | usage() |
537 | { | ||
538 | echo "Usage: $(basename $0) [command] [profile] ..." | ||
539 | echo | ||
540 | echo "Commands:" | ||
541 | echo " bootstrap - bootstraps the rootfs for the livecd" | ||
542 | echo " prepare - prepare the rootfs to run from a livecd" | ||
543 | echo " rootfs - generates the squashfs rootfs image" | ||
544 | echo " initrd - generates a livecd suitable initrd" | ||
545 | echo " bootloader - installs the bootloader" | ||
546 | echo " isogen - generate the final livecd iso image" | ||
547 | echo " all - runs all tasks to get a livecd from zero" | ||
548 | niro | 472 | echo " enter - enters the rootfs of a livecd" |
549 | niro | 360 | echo |
550 | echo " for example '$(basename $0) all default'" | ||
551 | echo " creates a livecd using the default profile." | ||
552 | echo | ||
553 | } | ||
554 | |||
555 | niro | 1403 | # set some proper traps |
556 | trap "trap_exit" SIGINT SIGQUIT | ||
557 | |||
558 | niro | 346 | # source profile config - overrides all other vars |
559 | [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config | ||
560 | |||
561 | niro | 360 | case $1 in |
562 | bootstrap) bootstrap_system;; | ||
563 | prepare) prepare_iso;; | ||
564 | rootfs) generate_rootfs;; | ||
565 | initrd) generate_initrd;; | ||
566 | bootloader) install_bootloader;; | ||
567 | isogen) generate_iso;; | ||
568 | all) | ||
569 | bootstrap_system | ||
570 | prepare_iso | ||
571 | generate_rootfs | ||
572 | generate_initrd | ||
573 | install_bootloader | ||
574 | niro | 713 | generate_iso |
575 | niro | 360 | ;; |
576 | niro | 472 | enter) enter_livecd ;; |
577 | niro | 360 | *|'') usage;; |
578 | esac |