Debian Codegraph @

bin/fai-cd

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 #*********************************************************************
4 #
5 # fai-cd -- make a fai CD, a bootable CD that performs the FAI
6 #
7 # This script is part of FAI (Fully Automatic Installation)
8 # (c) 2004-2026 by Thomas Lange, [email protected]
9 # Universitaet zu Koeln
10 # Support for grub2 added by Sebastian Hetze, [email protected]
11 # with major support from Michael Prokop, [email protected]
12 # dracut/squashfs support by Kerim Gueney, [email protected]
13 # based on a script called make-fai-bootcd by Niall Young <[email protected]>
14 #
15 #*********************************************************************
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful, but
22 # WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 # General Public License for more details.
25 #
26 # A copy of the GNU General Public License is available as
27 # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
28 # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
29 # can also obtain it by writing to the Free Software Foundation, Inc.,
30 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
31 #*********************************************************************
32
33 set -e
34
35 # last die exit code 22
36
37 count=0
38 space=0
39 config_space=""
40 configset=0
41 forceremoval=0
42 burn=0
43 bootonly=0
44 squash_only=0
45 nomirror=0
46 hidevartmp=0
47 rel=0
48 target=0
49 autodiscover=0
50 vname="FAI_CD"
51
52 hidedirs="/usr/share/locale /usr/share/doc /var/lib/apt /var/lib/aptitude /var/cache/debconf /var/cache/apt /var/cache/man /usr/share/man /var/lib/dpkg/info /media/mirror/aptcache scip-shell filesystem . . `/usr/share/locale /usr/share/doc /var/lib/apt /var/lib/aptitude /var/cache/debconf /var/cache/apt /var/cache/man /usr/share/man /var/lib/dpkg/info /media/mirror/aptcache `."
53
54 # we need FAI_CONFIGDIR, NFSROOT
55
56 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57 usagescip-shell shell fai 6.6 usage().() {
58
59 catscip-shell system . . cat. <<-EOF
60 fai-cd Copyright (C) 2004-2026 Thomas Lange
61
62 Usage: fai-cd [OPTIONS] -m MIRRORDIR ISONAME
63 Usage: fai-cd [OPTIONS] -B ISONAME
64 Usage: fai-cd [OPTIONS] -S IMAGEFILE
65 Create a FAI CD, a bootable CD that performs the FAI or a squashfs boot image.
66 Read the man pages pages fai-cd(8) for more information.
67 EOF
68 exit 0
69 }
70 # - - - - - - - - - - - - - - - - - - - - - - - - - -
71 diescip-shell shell fai 6.6 die().() {
72
73 local e=$1 # first parameter is the exit code
74 shift
75
76 echoscip-shell system . . echo. -e "ERROR: $*" >&2 # print error message
77 exit $e
78 }
79 # - - - - - - - - - - - - - - - - - - - - - - - - - -
80 check_programsscip-shell shell fai 6.6 check_programs().() {
81
82 local msg
83 [scip-shell system . . `[`. $squash_only -eq 0 ] && ! command -v xorriso >&/dev/null && msg+="xorriso not found. Please install package."
84 command -v mksquashfs >&/dev/null || msg+="\nmksquashfs not found. Please install the package squashfs-tools."
85 command -v mkfs.vfat >&/dev/null || msg+="\nmkfs.vfat not found. Please install the package dosfstools."
86 command -v mcopy >&/dev/null || msg+="\nmcopy not found. Please install the package mtools."
87
88 if [scip-shell system . . `[`. -n "$msg" ]; then
89 diescip-shell shell fai 6.6 die(). 8 "$msg"
90 fi
91 }
92 # - - - - - - - - - - - - - - - - - - - - - - - - - -
93 create_new_nfsrootscip-shell shell fai 6.6 create_new_nfsroot().() {
94
95 mkdirscip-shell system . . mkdir. -p $tmp/cow/work $tmp/cow/rw $NEW
96
97 mountscip-shell system . . mount. -t overlay -o lowerdir=$NFSROOT,upperdir=$tmp/cow/rw,workdir=$tmp/cow/work,default_permissions overlay $NEW
98
99 customize_nfsrootscip-shell shell fai 6.6 customize_nfsroot(). $NEW
100 rmscip-shell system . . rm. -f $NEW/etc/resolv.conf
101 }
102 # - - - - - - - - - - - - - - - - - - - - - - - - - -
103 create_autodiscover_isoscip-shell shell fai 6.6 create_autodiscover_iso().() {
104
105 # boot-only CD does not need some dracut modules
106
107 local compress
108 local rel
109 rel=$(lsscip-shell system . . ls. $NEW/lib/modules/|headscip-shell system . . head. -1)
110 local target=$NEW/lib/modules/$rel/kernel
111
112 if [scip-shell system . . `[`. -n "$_OPTJ" ]; then
113 compress="--xz"
114 else
115 compress="--zstd"
116 fi
117 rmscip-shell system . . rm. $NEW/boot/initrd.img*
118 mountpointscip-shell system . . mountpoint. -q $NEW/proc || mountscip-shell system . . mount. --bind /procscip-shell filesystem . . `/proc`. $NEW/proc
119 mountpointscip-shell system . . mountpoint. -q $NEW/sys || mountscip-shell system . . mount. --bind /sysscip-shell filesystem . . `/sys`. $NEW/sys
120 TMPDIR=/tmpscip-shell filesystem . . `/tmp`. chrootscip-shell system . . chroot. $NEW dracut -o ' fs-lib livenet rootfs-block ' -a 'overlayfs bash fai-autodiscover' "$compress" /boot/initrd.img-$rel $rel 2>/dev/nullscip-shell filesystem . . `/dev/null`.
121 umountscip-shell system . . umount. $NEW/proc
122 umountscip-shell system . . umount. $NEW/sys
123 customize_nfsrootscip-shell shell fai 6.6 customize_nfsroot(). $target
124 }
125 # - - - - - - - - - - - - - - - - - - - - - - - - - -
126 create_squashfs_imagescip-shell shell fai 6.6 create_squashfs_image().() {
127
128 local output_path
129
130 # this is where the squashfs.img needs to be placed
131 mkdirscip-shell system . . mkdir. -p $tmp/LiveOS
132
133 # create the squashfs.img
134 output_path=$tmp/LiveOS/squashfs.img
135
136 if [scip-shell system . . `[`. $squash_only -eq 1 ]; then
137 output_path=$isoname
138 fi
139
140 echoscip-shell system . . echo. "Make squashfs file system"
141 mksquashfs $NEW $output_path $sqopt -xattrs-exclude '^system.posix_acl_access|system.posix_acl_default'
142 }
143 # - - - - - - - - - - - - - - - - - - - - - - - - - -
144 prepare_grub_cfgscip-shell shell fai 6.6 prepare_grub_cfg().() {
145
146 # prepare grub.cfg
147 cpscip-shell system . . cp. $grub_config $NEW/tmp/grub.cfg
148 # insert date into grub menu
149 perlscip-shell system . . perl. -pi -e "s/_VERSIONSTRING_/ $isoversion /" $NEW/tmp/grub.cfg
150 if [scip-shell system . . `[`. -n "$config_space" ] || [scip-shell system . . `[`. $configset -eq 1 ]; then
151 perlscip-shell system . . perl. -pi -e "s|FAI_CONFIG_SRC=(.*?)\S+|FAI_CONFIG_SRC=$config_space|" $NEW/tmp/grub.cfg
152 fi
153 provide_memtest_boot_optionscip-shell shell fai 6.6 provide_memtest_boot_option().
154 }
155 # - - - - - - - - - - - - - - - - - - - - - - - - - -
156 copy_kernel_initrdscip-shell shell fai 6.6 copy_kernel_initrd().() {
157
158 # copy kernel and initrd
159 cpscip-shell system . . cp. -p $NEW/boot/vmlinuz-$kernelversion $tmp/boot/vmlinuz
160 cpscip-shell system . . cp. -p $NEW/boot/initrd.img-$kernelversion $tmp/boot/initrd.img
161 cpscip-shell system . . cp. -p $NEW/boot/config-$kernelversion $tmp/boot/
162 rmscip-shell system . . rm. -f $NEW/tmp/grub.cfg
163 echoscip-shell system . . echo. "$isoversion" > $tmp/FAI-CD
164 }
165 # - - - - - - - - - - - - - - - - - - - - - - - - - -
166 create_grub2_image_arm64scip-shell shell fai 6.6 create_grub2_image_arm64().() {
167
168 mkdirscip-shell system . . mkdir. -p $tmp/boot/grub
169 if [scip-shell system . . `[`. -d $NEW/usr/lib/grub/arm64-efi ]; then
170
171 prepare_grub_cfgscip-shell shell fai 6.6 prepare_grub_cfg().
172
173 # create arch.efi and copy to vfat file system
174 TMPDIR=tmp chrootscip-shell system . . chroot. $NEW grub-mkstandalone \
175 --format=arm64-efi \
176 --output=/tmp/grubaa64.efi \
177 --locales="" \
178 "boot/grub/grub.cfg=/tmp/grub.cfg"
179 mvscip-shell system . . mv. $NEW/tmp/grubaa64.efi $scratch/BOOTAA64.EFI
180
181 mkfs.vfat -C $scratch/efiboot.img 6000 >/dev/nullscip-shell filesystem . . `/dev/null`.
182 mmd -i $scratch/efiboot.img EFI EFI/boot
183 mcopy -i $scratch/efiboot.img $scratch/BOOTAA64.EFI ::EFI/boot/
184 else
185 diescip-shell shell fai 6.6 die(). 11 "No grub-efi-arm64-bin installation found in NFSROOT. Aborting."
186 fi
187 copy_kernel_initrdscip-shell shell fai 6.6 copy_kernel_initrd().
188 }
189 # - - - - - - - - - - - - - - - - - - - - - - - - - -
190 create_grub2_image_x86scip-shell shell fai 6.6 create_grub2_image_x86().() {
191
192 mkdirscip-shell system . . mkdir. -p $tmp/boot/grub
193
194 if [scip-shell system . . `[`. -d $NEW/usr/lib/grub/x86_64-efi ]; then
195
196 prepare_grub_cfgscip-shell shell fai 6.6 prepare_grub_cfg().
197
198 # Populates the grub efi programs and grub config
199 cpscip-shell system . . cp. $NEW/tmp/grub.cfg $tmp/boot/grub/grub.cfg
200 cpscip-shell system . . cp. $NEW/tmp/grub.cfg $scratch/grub.cfg
201 cpscip-shell system . . cp. $NEW/usr/lib/shim/shimx64.efi.signed $scratch/BOOTx64.EFI
202 cpscip-shell system . . cp. $NEW/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed $scratch/grubx64.efi
203
204 mkdirscip-shell system . . mkdir. -p $tmp/EFI/BOOT/
205 cpscip-shell system . . cp. $NEW/usr/lib/shim/shimx64.efi.signed $tmp/EFI/BOOT/BOOTx64.EFI
206 mkfs.vfat -C $scratch/efiboot.img 6000 >/dev/nullscip-shell filesystem . . `/dev/null`.
207 mmd -i $scratch/efiboot.img efi efi/boot
208 mcopy -i $scratch/efiboot.img $scratch/grub.cfg ::efi/boot/
209 mcopy -i $scratch/efiboot.img $scratch/BOOTx64.EFI ::efi/boot/
210 mcopy -i $scratch/efiboot.img $scratch/grubx64.efi ::efi/boot/
211 else
212 diescip-shell shell fai 6.6 die(). 11 "No grub-efi-amd64-bin installation found in NFSROOT. Aborting."
213 fi
214 if [scip-shell system . . `[`. -d $NEW/usr/lib/grub/i386-pc ]; then
215 cpscip-shell system . . cp. -a $NEW/usr/lib/grub/i386-pc $NEW/tmp/grub
216 echoscip-shell system . . echo. -e "ext2\niso9660\ntar\n" > $NEW/tmp/grub/fs.lst
217 TMPDIR=/tmpscip-shell filesystem . . `/tmp`. chrootscip-shell system . . chroot. $NEW grub-mkstandalone \
218 --directory=/tmp/grub \
219 --format=i386-pc \
220 --output=/tmp/core.img \
221 --locales="" --fonts="" \
222 --install-modules="linux normal iso9660 biosdisk memdisk search ls echo test chain msdospart part_msdos part_gpt minicmd ext2 keystatus all_video font sleep gfxterm regexp read" \
223 --modules="linux normal iso9660 biosdisk search" \
224 "boot/grub/grub.cfg=/tmp/grub.cfg"
225 catscip-shell system . . cat. $NEW/usr/lib/grub/i386-pc/cdboot.img $NEW/tmp/core.img > $scratch/bios.img
226 rmscip-shell system . . rm. -rf $NEW/tmp/core.img $NEW/tmp/grub
227 else
228 diescip-shell shell fai 6.6 die(). 11 "No grub-pc installation found in NFSROOT. Aborting."
229 fi
230 copy_kernel_initrdscip-shell shell fai 6.6 copy_kernel_initrd().
231 }
232 # - - - - - - - - - - - - - - - - - - - - - - - - - -
233 provide_memtest_boot_optionscip-shell shell fai 6.6 provide_memtest_boot_option().() {
234
235 if [scip-shell system . . `[`. $bootonly -eq 1 ]; then
236 return
237 fi
238
239 if [scip-shell system . . `[`. -f $NEW/boot/memtest86+x64.efi ] || [scip-shell system . . `[`. -f $NEW/boot/memtest86+x64.bin ]; then
240 cpscip-shell system . . cp. -p $NEW/boot/memtest86+x64* $tmp/boot
241 echoscip-shell system . . echo. "Adding memtest86+ to grub menu"
242 else
243 return 0
244 fi
245
246 catscip-shell system . . cat. >> $NEW/tmp/grub.cfg <<'EOF'
247
248 if [ "$grub_platform" == efi -a "$grub_cpu" == x86_64 ]; then
249 menuentry "Memory test (memtest86+)" --unrestricted {
250 search --set=root --file /FAI-CD
251 linux /boot/memtest86+x64.efi
252 }
253 fi
254 if [ "$grub_platform" == pc ]; then
255 menuentry "Memory test (memtest86+)" --unrestricted {
256 search --set=root --file /FAI-CD
257 linux /boot/memtest86+x64.bin
258 }
259 fi
260 EOF
261 }
262 # - - - - - - - - - - - - - - - - - - - - - - - - - -
263 customize_nfsrootscip-shell shell fai 6.6 customize_nfsroot().() {
264
265 # hide/remove some dirs to save space and make the CD image smaller
266 local path=$1
267 local d
268
269 for d in $hidedirs; do
270 if [scip-shell system . . `[`. -d $path/$d ]; then
271 [scip-shell system . . `[`. "$debug" ] && echoscip-shell system . . echo. "hiding $d"
272 rmscip-shell system . . rm. -rf $path/$d/*
273 fi
274 done
275 }
276 # - - - - - - - - - - - - - - - - - - - - - - - - - -
277 cleanup_liveos_mountsscip-shell shell fai 6.6 cleanup_liveos_mounts().() {
278
279 mountpointscip-shell system . . mountpoint. -q $NEW && umountscip-shell system . . umount. $NEW
280 rmscip-shell system . . rm. -rf $tmp $scratch
281 }
282 # - - - - - - - - - - - - - - - - - - - - - - - - - -
283 mkiso_x86scip-shell shell fai 6.6 mkiso_x86().() {
284
285 echoscip-shell system . . echo. "Writing FAI CD-ROM image to $isoname. This may need some time."
286 xorriso -report_about HINT -as mkisofs -iso-level 3 \
287 -full-iso9660-filenames \
288 -volid "$vname" -appid "$aname" \
289 -eltorito-boot boot/grub/bios.img \
290 -no-emul-boot -boot-load-size 4 -boot-info-table \
291 --eltorito-catalog boot/grub/boot.cat \
292 --grub2-boot-info \
293 --grub2-mbr $NFSROOT/usr/lib/grub/i386-pc/boot_hybrid.img \
294 -eltorito-alt-boot -e EFI/efiboot.img -no-emul-boot \
295 -partition_offset 16 -appended_part_as_gpt \
296 -append_partition 2 0xef $scratch/efiboot.img \
297 -e --interval:appended_partition_2:all:: \
298 --exclude $tmp/cow \
299 -o $isoname -graft-points \
300 --sort-weight 0 /scip-shell filesystem . . `/`. --sort-weight 1 /bootscip-shell filesystem . . `/boot`. \
301 "$tmp" \
302 /boot/grub/bios.img=$scratch/bios.img \
303 /EFI/debian/grub.cfg=$scratch/grub.cfg \
304 || diescip-shell shell fai 6.6 die(). 12 "xorriso failed."
305
306 echoscip-shell system . . echo. -n "ISO image size and filename: "; duscip-shell system . . du. -h $isoname
307 }
308 # - - - - - - - - - - - - - - - - - - - - - - - - - -
309 mkiso_arm64scip-shell shell fai 6.6 mkiso_arm64().() {
310
311 echoscip-shell system . . echo. "Writing FAI CD-ROM image to $isoname. This may need some time."
312 cpscip-shell system . . cp. $scratch/efiboot.img $tmp/boot/grub/efi.img
313 xorriso -as mkisofs -r \
314 -volid "$vname" -appid "$aname" \
315 -J -joliet-long \
316 -e boot/grub/efi.img -no-emul-boot \
317 --exclude $tmp/cow \
318 -append_partition 2 0xef $scratch/efiboot.img \
319 -partition_cyl_align all \
320 "$tmp" \
321 -o $isoname \
322 || diescip-shell shell fai 6.6 die(). 12 "xorriso failed."
323
324 echoscip-shell system . . echo. -n "ISO image size and filename: "; duscip-shell system . . du. -h $isoname
325 }
326 # - - - - - - - - - - - - - - - - - - - - - - - - - -
327 addmirrorscip-shell shell fai 6.6 addmirror().() {
328
329 [scip-shell system . . `[`. $nomirror -eq 1 ] && return
330
331 mkdirscip-shell system . . mkdir. $NEW/media/mirror
332
333 echoscip-shell system . . echo. "Copying the mirror to CD image"
334 cpscip-shell system . . cp. -Pr $mirrordir/{dists,pool} $NEW/media/mirror 2>/dev/nullscip-shell filesystem . . `/dev/null`. || diescip-shell shell fai 6.6 die(). $? "Not enough space left on image for the mirror"
335
336 # create the sources.list for the CD
337 catscip-shell system . . cat. > $NEW/etc/apt/sources.list <<EOF
338 # mirror location for fai CD, file generated by fai-cd
339 EOF
340
341 dists=$(findscip-shell system . . find. $mirrordir -name "Packages*" | grepscip-shell system . . grep. binary | sedscip-shell system . . sed. 's/binary-.*//' | \
342 sed "s#$mirrordir/*dists/##" | xargs -r -n 1 dirname | sort | uniq )
343 [scip-shell system . . `[`. -z "$dists" ] && diescip-shell shell fai 6.6 die(). 19 "No suitable Packages file found in mirror."
344
345 for i in $dists ; do
346 comp=$(findscip-shell system . . find. $mirrordir/dists/$i -maxdepth 2 -type d -name "binary-*" | \
347 sed -e "s#$mirrordir/*dists/$i/##" -e 's#/binary-.*##' | uniq | tr '\n' " ")
348 echoscip-shell system . . echo. "deb [trusted=yes] file:/media/mirror $i $comp" >> $NEW/etc/apt/sources.list
349 done
350 }
351 # - - - - - - - - - - - - - - - - - - - - - - - - - -
352 add_config_spacescip-shell shell fai 6.6 add_config_space().() {
353
354 # copy config space into nfsroot-copy unless -d is given
355 if [scip-shell system . . `[`. $configset -eq 0 ]; then
356 echoscip-shell system . . echo. "Copying the config space to CD image"
357 cpscip-shell system . . cp. -Ppr $FAI_CONFIGDIR/. $NEW/var/lib/fai/config/ || diescip-shell shell fai 6.6 die(). $? "Not enough space left on image for the config directory"
358 fi
359 }
360 # - - - - - - - - - - - - - - - - - - - - - - - - - -
361 burnisoscip-shell shell fai 6.6 burniso().() {
362
363 wodim -v -eject $isoname
364 }
365 # - - - - - - - - - - - - - - - - - - - - - - - - - -
366 # main program
367
368 sqopt="-quiet -comp zstd -Xcompression-level 5"
369
370 # Parse commandline options
371 while getopts "AekfhHg:Jbs:SBMn:m:V:c:C:d:" opt ; do
372 case "$opt" in
373 A) autodiscover=1 ;;
374 c) csdir="$OPTARG" ;;
375 C) cdir="$OPTARG"
376 echoscip-shell system . . echo. "Using configuration files from $cdir";;
377 e) hidevartmp=1 ;;
378 f) forceremoval=1 ;;
379 h) usagescip-shell shell fai 6.6 usage(). ;;
380 H) hidedirs="" ;;
381 g) grub_config="$OPTARG" ;;
382 J) _OPTJ=1; sqopt="-quiet -comp xz";;
383 M) nomirror=1 ;;
384 m) mirrordir="$OPTARG" ;;
385 n) setnfsroot="$OPTARG" ;;
386 b) burn=1;;
387 s) echoscip-shell system . . echo. "WARNING. Option -s is ignored" > /dev/stderrscip-shell filesystem . . `/dev/stderr`. ;;
388 S) squash_only=1 ;;
389 B) bootonly=1 ;;
390 V) vname="$OPTARG" ;;
391 d) config_space="$OPTARG"; configset=1 ;;
392 ?) usagescip-shell shell fai 6.6 usage(). ;;
393 esac
394 done
395 shift $((OPTIND - 1))
396 isoname=$1
397
398
399 if [scip-shell system . . `[`. $autodiscover -eq 1 ]; then
400 nomirror=1
401 bootonly=1
402 hidedirs="
403 sound
404 net/ceph
405 fs/ceph
406 fs/ocfs2
407 fs/btrfs
408 fs/xfs
409 fs/bcachefs
410 drivers/net/wireless
411 drivers/block/drbd
412 drivers/hwmon
413 drivers/iio
414 drivers/staging/lustre
415 drivers/scsi
416 drivers/ata
417 drivers/target
418 drivers/pcmcia
419 drivers/mmc
420 drivers/media
421 drivers/infiniband
422 drivers/isdn
423 drivers/video
424 drivers/mtd
425 drivers/md
426 drivers/gpu/drm
427 "
428 fi
429
430 [scip-shell system . . `[`. $nomirror -eq 1 -a -n "$mirrordir" ] && diescip-shell shell fai 6.6 die(). 6 "Do not use -M and -m at the same time."
431 [scip-shell system . . `[`. "$#" -eq 0 ] && diescip-shell shell fai 6.6 die(). 2 "Please specify the output file for the ISO image."
432 if [scip-shell system . . `[`. $bootonly -eq 0 -a $nomirror -eq 0 ]; then
433 [scip-shell system . . `[`. -z "$mirrordir" ] && diescip-shell shell fai 6.6 die(). 4 "Please specify the directory of your mirror using -m"
434 [scip-shell system . . `[`. -d "$mirrordir" ] || diescip-shell shell fai 6.6 die(). 5 "$mirrordir is not a directory"
435 [scip-shell system . . `[`. -z "$(lsscip-shell system . . ls. $mirrordir)" ] && diescip-shell shell fai 6.6 die(). 18 "No mirror found in $mirrordir. Empty directory."
436 fi
437 [scip-shell system . . `[`. -f "$isoname" ] && [scip-shell system . . `[`. $forceremoval -eq 1 ] && rmscip-shell system . . rm. $isoname
438 [scip-shell system . . `[`. -f "$isoname" ] && diescip-shell shell fai 6.6 die(). 3 "Outputfile $isoname already exists. Please remove it or use -f."
439
440 if [scip-shell system . . `[`. $bootonly -eq 0 ]; then
441 [scip-shell system . . `[`. $(idscip-shell system . . id. -u) != "0" ] && diescip-shell shell fai 6.6 die(). 9 "Run this program as root."
442 fi
443
444 check_programsscip-shell shell fai 6.6 check_programs().
445
446 # use FAI_ETC_DIR from environment variable
447 if [scip-shell system . . `[`. -n "$FAI_ETC_DIR" -a -z "$cdir" ]; then
448 echoscip-shell system . . echo. "Using environment variable \$FAI_ETC_DIR."
449 cfdir=$FAI_ETC_DIR
450 fi
451 [scip-shell system . . `[`. -n "$cdir" ] && cfdir=$cdir
452 : ${cfdir:=/etc/fai}
453 cfdir=$(readlinkscip-shell system . . readlink. -f $cfdir) # canonicalize path
454 if [scip-shell system . . `[`. ! -d "$cfdir" ]; then
455 echoscip-shell system . . echo. "$cfdir is not a directory" >&2
456 exit 6
457 fi
458 . $cfdir/fai.conf
459 . $cfdir/nfsroot.conf
460 : ${FAI:=/var/lib/fai/config} # default value
461
462 if [scip-shell system . . `[`. -n "$setnfsroot" ]; then
463 NFSROOT=$setnfsroot # override by -n
464 fi
465 if [scip-shell system . . `[`. -n "$csdir" ]; then
466 FAI_CONFIGDIR=$csdir # override by -c
467 fi
468 NFSROOT=$(readlinkscip-shell system . . readlink. -f $NFSROOT) # resolve symlinks
469
470 [scip-shell system . . `[`. -f "$NFSROOT/bin/dracut" ] || diescip-shell shell fai 6.6 die(). 10 "Please create a NFSROOT that includes dracut."
471
472 [scip-shell system . . `[`. $hidevartmp -eq 1 ] && hidedirs+="/var/tmpscip-shell filesystem . . `/var/tmp`."
473
474 if [scip-shell system . . `[`. -z "$grub_config" ]; then
475 grub_config="$cfdir/grub.cfg" # set default if undefined
476 [scip-shell system . . `[`. $autodiscover -eq 1 ] && grub_config="$cfdir/grub.cfg.autodiscover" # set default if undefined
477 fi
478
479 # if grub_config contains / do not change it, else add prefix $cfdir
480 echoscip-shell system . . echo. $grub_config | grepscip-shell system . . grep. -q '/scip-shell filesystem . . `/`.' || grub_config="$cfdir/$grub_config"
481 [scip-shell system . . `[`. -f "$grub_config" ] || diescip-shell shell fai 6.6 die(). 13 "Grub menu file $grub_config not found."
482
483 if [scip-shell system . . `[`. $bootonly -eq 0 -o $configset -eq 1 ]; then
484 [scip-shell system . . `[`. -z "$FAI_CONFIGDIR" ] && diescip-shell shell fai 6.6 die(). 14 "Variable \$FAI_CONFIGDIR not set."
485 [scip-shell system . . `[`. -d $FAI_CONFIGDIR ] || diescip-shell shell fai 6.6 die(). 15 "Can't find config space $FAI_CONFIGDIR."
486 [scip-shell system . . `[`. -d $FAI_CONFIGDIR/class ] || diescip-shell shell fai 6.6 die(). 16 "Config space $FAI_CONFIGDIR seems to be empty."
487 fi
488
489 tmp=$(mktempscip-shell system . . mktemp. -t -d fai-cd.XXXXXX) || exit 13
490 scratch=$(mktempscip-shell system . . mktemp. -t -d scratch.XXXXXX) || exit 13
491 NEW=$tmp/nfsroot
492
493 trap "cleanup_liveos_mounts" EXIT ERR
494
495 create_new_nfsrootscip-shell shell fai 6.6 create_new_nfsroot().
496 if [scip-shell system . . `[`. $bootonly -eq 0 ]; then
497 addmirrorscip-shell shell fai 6.6 addmirror().
498 add_config_spacescip-shell shell fai 6.6 add_config_space().
499 create_squashfs_imagescip-shell shell fai 6.6 create_squashfs_image().
500 fi
501
502 if [scip-shell system . . `[`. $autodiscover -eq 1 ]; then
503 create_autodiscover_isoscip-shell shell fai 6.6 create_autodiscover_iso().
504 fi
505
506 [scip-shell system . . `[`. $squash_only -eq 1 ] && exit 0
507
508 kernelversion=$(lsscip-shell system . . ls. -tr $NEW/boot/vmlinu?-* | tailscip-shell system . . tail. -1 | sedscip-shell system . . sed. -e 's#.*/vmlinuz-##')
509 faiversion=$(dpkgscip-shell system . . dpkg. --root=$NEW -l fai-client 2>/dev/nullscip-shell filesystem . . `/dev/null`. |awkscip-shell system . . awk. '/fai-client/ {print $3}scip-shell filesystem . . `/fai-client/ {print $3}`.')
510 isoversion=$(printfscip-shell system . . printf. "FAI %-6s build $(datescip-shell system . . date. '+%Y %b %d - %R')" "$faiversion")
511 aname="Fully Automatic Installation by Thomas Lange, $isoversion"
512
513 case $(unamescip-shell system . . uname. -m) in
514 x86_64)
515 create_grub2_image_x86scip-shell shell fai 6.6 create_grub2_image_x86().
516 umountscip-shell system . . umount. $NEW
517 rmdirscip-shell system . . rmdir. $NEW
518 mkiso_x86scip-shell shell fai 6.6 mkiso_x86().
519 ;;
520 aarch64)
521 create_grub2_image_arm64scip-shell shell fai 6.6 create_grub2_image_arm64().
522 umountscip-shell system . . umount. $NEW
523 rmdirscip-shell system . . rmdir. $NEW
524 mkiso_arm64scip-shell shell fai 6.6 mkiso_arm64().
525 ;;
526 esac
527
528 [scip-shell system . . `[`. "$burn" -eq 1 ] && burnisoscip-shell shell fai 6.6 burniso().
529 exit 0