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