2021-05-03 22:39:00 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -eux
|
2021-06-25 19:47:38 +00:00
|
|
|
|
|
|
|
FAILANY=0
|
2024-04-04 18:16:16 +00:00
|
|
|
BOOTISO=/var/tmp/lorax-rhel10-iso/images/boot.iso
|
2021-06-25 19:47:38 +00:00
|
|
|
KSNAME=fedora-minimal.ks
|
|
|
|
KS="/usr/share/doc/lorax/$KSNAME"
|
|
|
|
OUTISO=/var/tmp/out.iso
|
|
|
|
ISODIR=/var/tmp/iso
|
|
|
|
## Functions for testing mkkiso
|
|
|
|
|
|
|
|
|
|
|
|
function fail {
|
|
|
|
echo -e "\n\n#### ERROR: $1\n"
|
|
|
|
FAIL=1
|
|
|
|
FAILANY=1
|
|
|
|
}
|
|
|
|
|
|
|
|
function status {
|
|
|
|
if [ "$FAIL" -eq 0 ]; then
|
|
|
|
echo -e "\n\n#### PASS: $1\n"
|
|
|
|
else
|
|
|
|
echo -e "\n\n#### FAIL: $1\n"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function running {
|
|
|
|
FAIL=0
|
|
|
|
echo -e "\n\n#### RUN: $1\n"
|
|
|
|
}
|
|
|
|
|
2021-11-11 18:18:50 +00:00
|
|
|
# unmount the dirs lazily because sometimes some outside thing is still touching them
|
|
|
|
function umount_dirs {
|
|
|
|
umount --lazy "$ISODIR"
|
2022-05-11 19:08:00 +00:00
|
|
|
rm -f "$OUTISO"
|
2021-11-11 18:18:50 +00:00
|
|
|
}
|
|
|
|
|
2021-06-25 19:47:38 +00:00
|
|
|
[ -e "$ISODIR" ] || mkdir "$ISODIR"
|
|
|
|
|
|
|
|
# Only add kickstart
|
|
|
|
function ks_only {
|
2022-07-25 17:39:21 +00:00
|
|
|
running "Add kickstart to iso using --ks"
|
2021-06-25 19:47:38 +00:00
|
|
|
|
2022-05-26 21:51:22 +00:00
|
|
|
mkksiso --ks $KS $BOOTISO $OUTISO || exit 1
|
2021-06-25 19:47:38 +00:00
|
|
|
mount $OUTISO $ISODIR || exit 1
|
|
|
|
|
|
|
|
test_ks
|
|
|
|
|
2022-07-25 17:39:21 +00:00
|
|
|
status "Add kickstart to iso using --ks"
|
|
|
|
umount_dirs
|
|
|
|
}
|
|
|
|
|
|
|
|
# Only add kickstart
|
|
|
|
function ks_pos_only {
|
|
|
|
running "Add kickstart to iso using positional argument"
|
|
|
|
|
|
|
|
mkksiso $KS $BOOTISO $OUTISO || exit 1
|
|
|
|
mount $OUTISO $ISODIR || exit 1
|
|
|
|
|
|
|
|
test_ks
|
|
|
|
|
|
|
|
status "Add kickstart to iso using positional argument"
|
2021-11-11 18:18:50 +00:00
|
|
|
umount_dirs
|
2021-06-25 19:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_ks {
|
|
|
|
## This all needs to be another function
|
|
|
|
# Is there a kickstart in / of the iso?
|
|
|
|
[ -e "$ISODIR/$KSNAME" ] || fail "Missing kickstart"
|
|
|
|
|
2022-06-01 23:20:10 +00:00
|
|
|
# Is the kickstart in the GRUB2 BIOS config?
|
|
|
|
grep "inst.ks=.*$KSNAME" "$ISODIR/boot/grub2/grub.cfg" || fail "Missing BIOS grub.cfg kickstart entry"
|
2021-06-25 19:47:38 +00:00
|
|
|
|
|
|
|
# Is the kickstart in the UEFI config?
|
2022-05-11 19:08:00 +00:00
|
|
|
grep "inst.ks=.*$KSNAME" "$ISODIR/EFI/BOOT/grub.cfg" || fail "Missing UEFI grub.cfg kickstart entry"
|
2021-06-25 19:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Add ks and cmdline
|
|
|
|
function ks_serial {
|
|
|
|
running "Add kickstart and serial cmdline"
|
|
|
|
|
2022-05-26 21:51:22 +00:00
|
|
|
mkksiso -c "console=ttyS0,115200n8" --ks $KS $BOOTISO $OUTISO || exit 1
|
2021-06-25 19:47:38 +00:00
|
|
|
mount $OUTISO $ISODIR || exit 1
|
|
|
|
|
|
|
|
test_ks
|
2022-05-26 21:51:22 +00:00
|
|
|
test_serial
|
2021-06-25 19:47:38 +00:00
|
|
|
|
|
|
|
status "Add kickstart and serial cmdline"
|
2021-11-11 18:18:50 +00:00
|
|
|
umount_dirs
|
2021-06-25 19:47:38 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 21:51:22 +00:00
|
|
|
# Only add serial console to cmdline
|
|
|
|
function only_serial {
|
|
|
|
running "Add serial cmdline (no ks)"
|
|
|
|
|
|
|
|
mkksiso -c "console=ttyS0,115200n8" $BOOTISO $OUTISO || exit 1
|
|
|
|
mount $OUTISO $ISODIR || exit 1
|
|
|
|
|
|
|
|
test_serial
|
|
|
|
|
|
|
|
status "Add kickstart and serial cmdline"
|
|
|
|
umount_dirs
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_serial {
|
2021-06-25 19:47:38 +00:00
|
|
|
|
|
|
|
# Is the serial in the BIOS config?
|
2022-06-01 23:20:10 +00:00
|
|
|
grep "console=ttyS0,115200n8" "$ISODIR/boot/grub2/grub.cfg" || fail "Missing BIOS grub.cfg cmdline entry"
|
2021-06-25 19:47:38 +00:00
|
|
|
|
|
|
|
# Is the serial in the UEFI config?
|
2022-05-11 19:08:00 +00:00
|
|
|
grep "console=ttyS0,115200n8" "$ISODIR/EFI/BOOT/grub.cfg" || fail "Missing UEFI grub.cfg cmdline entry"
|
2021-06-25 19:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# New VOLID
|
|
|
|
function new_volid {
|
|
|
|
running "Use a new VOLID"
|
|
|
|
|
2022-05-26 21:51:22 +00:00
|
|
|
mkksiso -V "mkksiso-test" --ks $KS $BOOTISO $OUTISO || exit 1
|
2021-06-25 19:47:38 +00:00
|
|
|
mount $OUTISO $ISODIR || exit 1
|
|
|
|
|
|
|
|
test_ks
|
|
|
|
test_volid
|
|
|
|
|
|
|
|
status "Use a new VOLID"
|
2021-11-11 18:18:50 +00:00
|
|
|
umount_dirs
|
2021-06-25 19:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_volid {
|
|
|
|
# Is the VOLID in the BIOS config?
|
2022-06-01 23:20:10 +00:00
|
|
|
grep "hd:LABEL=mkksiso-test" "$ISODIR/boot/grub2/grub.cfg" || fail "Missing BIOS grub.cfg kickstart entry"
|
2021-06-25 19:47:38 +00:00
|
|
|
|
|
|
|
# Is the VOLID in the UEFI config?
|
2022-05-11 19:08:00 +00:00
|
|
|
grep "hd:LABEL=mkksiso-test" "$ISODIR/EFI/BOOT/grub.cfg" || fail "Missing UEFI grub.cfg kickstart entry"
|
2021-06-25 19:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Add extra files
|
|
|
|
function add_files {
|
|
|
|
running "Add files"
|
|
|
|
|
2022-05-26 21:51:22 +00:00
|
|
|
mkksiso -a /etc/services --ks $KS $BOOTISO $OUTISO || exit 1
|
2021-06-25 19:47:38 +00:00
|
|
|
mount $OUTISO $ISODIR || exit 1
|
|
|
|
|
|
|
|
test_ks
|
|
|
|
test_files
|
|
|
|
|
|
|
|
status "Add files"
|
2021-11-11 18:18:50 +00:00
|
|
|
umount_dirs
|
2021-06-25 19:47:38 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 21:51:22 +00:00
|
|
|
# Remove quiet from the cmdline
|
|
|
|
function remove_quiet {
|
|
|
|
running "remove quiet from cmdline (no ks)"
|
|
|
|
|
|
|
|
mkksiso --rm "quiet" $BOOTISO $OUTISO || exit 1
|
|
|
|
mount $OUTISO $ISODIR || exit 1
|
|
|
|
|
|
|
|
test_quiet
|
|
|
|
|
|
|
|
status "Remove quiet from cmdline"
|
|
|
|
umount_dirs
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_quiet {
|
|
|
|
# Is quiet in the BIOS config?
|
|
|
|
! grep "append.*quiet" "$ISODIR/boot/grub2/grub.cfg" || fail "quiet not removed from BIOS grub.cfg cmdline entry"
|
|
|
|
|
|
|
|
# Is quiet in the UEFI config?
|
|
|
|
! grep "linux.*quiet" "$ISODIR/EFI/BOOT/grub.cfg" || fail "quiet not removed from UEFI grub.cfg cmdline entry"
|
|
|
|
}
|
|
|
|
|
2022-07-25 17:39:21 +00:00
|
|
|
# Test error if passing both --ks FILE and 3 arguments
|
|
|
|
function test_two_kickstarts {
|
|
|
|
running "Test two kickstart error"
|
|
|
|
|
|
|
|
mkksiso --ks $KS $KS $BOOTISO $OUTISO && fail "No error using --ks and positional argument"
|
|
|
|
|
|
|
|
status "Test two kickstart error"
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:47:38 +00:00
|
|
|
function test_files {
|
|
|
|
[ -e "$ISODIR/services" ] || fail "Missing file from iso"
|
|
|
|
}
|
|
|
|
|
2024-02-02 01:56:56 +00:00
|
|
|
# Test adding an updates.img file
|
|
|
|
function add_updatesimg {
|
|
|
|
running "Add updates.img"
|
|
|
|
|
|
|
|
# nothing in the file, just test that it is there
|
|
|
|
touch /tmp/test-updates.img
|
|
|
|
mkksiso -u /tmp/test-updates.img $BOOTISO $OUTISO || exit 1
|
|
|
|
mount $OUTISO $ISODIR || exit 1
|
|
|
|
|
|
|
|
test_updatesimg
|
|
|
|
|
|
|
|
status "Add updates.img"
|
|
|
|
umount_dirs
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_updatesimg {
|
|
|
|
[ -e "$ISODIR/updates/updates.img" ] || fail "Missing file from iso"
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:47:38 +00:00
|
|
|
# All of the changes
|
|
|
|
function run_all {
|
|
|
|
running "Use all the options"
|
|
|
|
|
2024-02-02 01:56:56 +00:00
|
|
|
touch /tmp/test-updates.img
|
|
|
|
mkksiso -u /tmp/test-updates.img -a /etc/services -V "mkksiso-test" -c "console=ttyS0,115200n8" --rm "quiet" --ks $KS $BOOTISO $OUTISO || exit 1
|
2021-06-25 19:47:38 +00:00
|
|
|
mount $OUTISO $ISODIR || exit 1
|
|
|
|
|
|
|
|
test_ks
|
2022-05-26 21:51:22 +00:00
|
|
|
test_serial
|
2021-06-25 19:47:38 +00:00
|
|
|
test_volid
|
|
|
|
test_files
|
2024-02-02 01:56:56 +00:00
|
|
|
test_updatesimg
|
2022-05-26 21:51:22 +00:00
|
|
|
test_quiet
|
2021-06-25 19:47:38 +00:00
|
|
|
|
|
|
|
status "Use all the options"
|
2021-11-11 18:18:50 +00:00
|
|
|
umount_dirs
|
2021-06-25 19:47:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-13 18:26:01 +00:00
|
|
|
# All of the changes as a user (lorax-ted) with --skip-mkefiboot
|
2022-07-13 22:23:16 +00:00
|
|
|
function run_as_user {
|
|
|
|
running "Use all the options as a user"
|
|
|
|
|
|
|
|
[ ! -e "/home/lorax-ted" ] && useradd -m lorax-ted
|
2024-02-02 01:56:56 +00:00
|
|
|
touch /tmp/test-updates.img
|
|
|
|
su - lorax-ted -c "mkksiso --skip-mkefiboot -u /tmp/test-updates.img -a /etc/services -V "mkksiso-test" -c "console=ttyS0,115200n8" --rm "quiet" --ks $KS $BOOTISO $OUTISO" || exit 1
|
2022-07-13 22:23:16 +00:00
|
|
|
mount $OUTISO $ISODIR || exit 1
|
|
|
|
|
|
|
|
test_ks
|
|
|
|
test_serial
|
|
|
|
test_volid
|
|
|
|
test_files
|
2024-02-02 01:56:56 +00:00
|
|
|
test_updatesimg
|
2022-07-13 22:23:16 +00:00
|
|
|
test_quiet
|
|
|
|
|
2022-12-13 18:26:01 +00:00
|
|
|
status "Use all the options as a user with --skip-mkefiboot"
|
2022-07-13 22:23:16 +00:00
|
|
|
umount_dirs
|
|
|
|
}
|
|
|
|
|
2024-04-04 18:16:16 +00:00
|
|
|
if [ ! -e /usr/share/lorax/templates.d/80-rhel/ ]; then
|
|
|
|
echo "Failed to find lorax-templates-rhel templates in /usr/share/lorax/templates.d/"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-06-25 19:47:38 +00:00
|
|
|
|
2021-05-03 22:39:00 +00:00
|
|
|
# Gather up the list of system repo files and use them for lorax
|
2024-06-04 18:19:30 +00:00
|
|
|
REPOS=$(find /etc/yum.repos.d/ -maxdepth 1 -type f -name '*\.repo' ! -name 'fedora.repo' -exec echo -n "--repo {} " \;)
|
2021-05-03 22:39:00 +00:00
|
|
|
if [ -z "$REPOS" ]; then
|
|
|
|
echo "No system repos found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# NOTE: We must use --nomacboot because the test system doesn't have the hfsplus fs available
|
|
|
|
# Run lorax using the host's repository configuration file
|
2022-05-11 19:08:00 +00:00
|
|
|
if [ ! -e "$BOOTISO" ]; then
|
|
|
|
running "Build boot.iso with lorax"
|
2024-04-04 18:16:16 +00:00
|
|
|
lorax --product="Red Hat Enterprise Linux" --version=10 --release=10 --volid="RHEL-10-test" \
|
|
|
|
$REPOS --isfinal /var/tmp/lorax-rhel10-iso/ || exit 1
|
2022-05-11 19:08:00 +00:00
|
|
|
fi
|
2021-06-25 19:47:38 +00:00
|
|
|
|
|
|
|
# Test mkksiso on the new boot.iso
|
|
|
|
ks_only
|
2022-07-25 17:39:21 +00:00
|
|
|
ks_pos_only
|
2021-06-25 19:47:38 +00:00
|
|
|
ks_serial
|
2022-05-26 21:51:22 +00:00
|
|
|
only_serial
|
2021-06-25 19:47:38 +00:00
|
|
|
new_volid
|
|
|
|
add_files
|
2022-05-26 21:51:22 +00:00
|
|
|
remove_quiet
|
2022-07-25 17:39:21 +00:00
|
|
|
test_two_kickstarts
|
2024-02-02 01:56:56 +00:00
|
|
|
add_updatesimg
|
2021-06-25 19:47:38 +00:00
|
|
|
run_all
|
2022-07-13 22:23:16 +00:00
|
|
|
run_as_user
|
2021-06-25 19:47:38 +00:00
|
|
|
|
|
|
|
exit $FAILANY
|