#!/bin/sh

# ----------------------------
# generate_manulix_iso.sh
# version 0.8.5.2
# ----------------------------

[ -z "${CHROOT_DIR}" ] && CHROOT_DIR="mx-chroot"

# check for required binaries
REQD_BINS=""
which genisoimage >/dev/null 2>&1 || type genisoimage >/dev/null 2>&1 || REQD_BINS="genisoimage,${REQD_BINS}"
if [ ! -z "${REQD_BINS}" ]; then
  echo -e `basename ${0}`: "Required binaries (${REQD_BINS}\010) are not present."
  exit 1
fi

mx_with_datestamp="Manulix_$(date +%Y%m%d)"
[ -f "${mx_with_datestamp}.iso" ] && rm -f "${mx_with_datestamp}.iso" 2>/dev/null

## ->-> generate yaboot configuration file <-<-

cat > ./"${CHROOT_DIR}"/boot/yaboot.conf << "EOF"
message=/boot/yaboot.msg
delay=10

init-message="\nWelcome to Manulix BootCD\nHit <TAB> for boot options.\n"
timeout=100
fgcolor=black
bgcolor=white

default=3.0-libre-powerpc

#enablecdboot
#enableofboot
#enablenetboot

image=/boot/vmlinux-3.0-libre-powerpc
        label=3.0-libre-powerpc
	alias=bootcd
	initrd=/boot/initrd-3.0-libre-powerpc.cpio.gz
	append="rootdelay=2 init=/linuxrc root=/dev/ram0 ramdisk_size=65536"
	read-write
	pause-after
EOF

## ->-> generate ISO image <-<-

genisoimage -r -V "${mx_with_datestamp}" \
  -iso-level 2 -chrp-boot -hfs \
  -part -probe -no-desktop \
  -hfs-bless ./"${CHROOT_DIR}"/boot \
  -map ./"${CHROOT_DIR}"/boot/map.hfs \
  -b boot/yaboot -no-emul-boot \
  -hide-rr-moved -o "${mx_with_datestamp}.iso" ./"${CHROOT_DIR}"
