Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 100 lines (90 sloc) 3.2 KB
#!/bin/bash
if [ -z "$2" ]; then
echo "Usage: $0 fdi-bootable-x.y.z.iso 'proxy.url=https://192.168.9.1:443 proxy.type=foreman fdi.xyz=abc...' [output.iso]"
exit 2
fi
REQ_CMDS="guestmount dd mkisofs isohybrid implantisomd5"
if ! which $REQ_CMDS >/dev/null; then
echo "Install required tools: $REQ_CMDS"
exit 3
fi
function cleanup() {
echo "Cleaning up temporary directory..."
[ -d $TMP_NEW ] && rm -rf $TMP_NEW
}
TMP_NEW=$(mktemp -d)
trap cleanup EXIT
TIMESTAMP=$(date +%y%m%d_%H%M%S)
OUT_ISO=${1/.iso/-$TIMESTAMP}.iso
[ ! -z "$3" ] && OUT_ISO=$3
echo "Copying contents to destination directory..."
export LIBGUESTFS_BACKEND=direct
guestfish --ro -a "$1" -m /dev/sda copy-out / $TMP_NEW
chmod +w -R $TMP_NEW
find $TMP_NEW -name TRANS.TBL -exec rm -f {} \;
echo "Configuring bootloaders..."
cat >$TMP_NEW/isolinux/isolinux.cfg <<EOIS
default vesamenu.c32
menu background
menu autoboot Starting Discovery Image in # second{,s}. Press any key to interrupt.
menu clear
menu title Discovery Image
menu vshift 8
menu rows 18
menu margin 8
menu helpmsgrow 15
menu tabmsgrow 13
menu color border * #00000000 #00000000 none
menu color sel 0 #ffffffff #00000000 none
menu color title 0 #ff7ba3d0 #00000000 none
menu color tabmsg 0 #ff3a6496 #00000000 none
menu color unsel 0 #84b8ffff #00000000 none
menu color hotsel 0 #84b8ffff #00000000 none
menu color hotkey 0 #ffffffff #00000000 none
menu color help 0 #ffffffff #00000000 none
menu color scrollbar 0 #ffffffff #ff355594 none
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
timeout 30
prompt 0
label fdi
menu label Discovery
kernel vmlinuz0
append initrd=initrd0.img root=live:CDLABEL=fdi rootfstype=auto ro rd.live.image acpi=force rd.luks=0 rd.md=0 rd.dm=0 nomodeset $2
label check
menu label Check media
kernel vmlinuz0
append initrd=initrd0.img root=live:CDLABEL=fdi rootfstype=auto ro rd.live.image rd.live.check acpi=force nomodeset $2
EOIS
cat >$TMP_NEW/EFI/BOOT/grub.cfg <<EOGR
loadfont unicode.pf2
set default=0
set gfxmode=80x25
set gfxpayload=text
set timeout=3
search --no-floppy --set=root -l 'fdi'
menuentry 'Discovery' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /isolinux/vmlinuz0 root=live:LABEL=fdi rootfstype=auto ro rd.live.image acpi=force rd.luks=0 rd.md=0 rd.dm=0 nomodeset $2
initrdefi /isolinux/initrd0.img
}
menuentry 'Check media' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /isolinux/vmlinuz0 root=live:LABEL=fdi rootfstype=auto ro rd.live.image rd.live.check acpi=force nomodeset $2
initrdefi /isolinux/initrd0.img
}
EOGR
echo "Building new ISO image..."
if [ -f "$TMP_NEW/isolinux/efiboot.img" ]; then
EFI_OPTS="-eltorito-alt-boot -e isolinux/efiboot.img -no-emul-boot"
EXTRA_MSG="(BIOS/EFI compatible)"
else
EFI_OPTS=""
EXTRA_MSG="(BIOS-only compatible)"
fi
mkisofs -quiet -U -A "fdi" -V "fdi" -volset "fdi" -J -joliet-long -r -v -T \
-o $OUT_ISO -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
-input-charset utf-8 -boot-info-table $EFI_OPTS $TMP_NEW
isohybrid --partok --uefi $OUT_ISO
implantisomd5 $OUT_ISO
echo "Created: $OUT_ISO $EXTRA_MSG"