#!/bin/bash
#
#  Live CD Generator, simple tool that inputs metadata and packages
#  and outputs a live ISO.
#
#  Usage: mklivecd arch version
#
#  Ex. mklivecd.sh i686 2013.1

BRAND="Fuduntu"
IMAGE="LiveDVD"
KS="kickstart/fuduntu-live-desktop.ks"
COMPRESSION="xz"
OPTS="-vvv -ddd --compression-type=${COMPRESSION}"
LOGFILE="/tmp/fuduntu-build.log"
TMPFILES="/store/x1/users/${USER}/livecd"

ARCH=$1
VERSION=$2

if [ ! "$VERSION" ]; then
  echo -e "Usage: mklivecd ARCH VERSION\n\nEx.\nmkfuduntu-live.sh i686 2013.1"
  exit 1
fi

if [[ ! "$ARCH" =~ [i686|x86_64] ]]; then
  echo "Invalid architecture, supported architectures: i686, x86_64"
  exit 1
fi

if [ ! -d "${TMPFILES}" ]; then
  mkdir -p "${TMPFILES}"
fi

sudo setarch ${ARCH} livecd-creator ${OPTS} --logfile=${LOGFILE} --config=${KS} --fslabel=${BRAND}-${VERSION}-${ARCH}-${IMAGE} --cache=${TMPFILES}/live/${ARCH} --tmpdir=${TMPFILES}/tmp/${ARCH}
