#!/bin/sh
ISO_IMAGES=${ISO_IMAGES:-/archives/images_iso}
MIRRORS=${MIRRORS:-/archives/versions}
set -e
if [ ! "$#" = "1" ]; then
  echo "Usage: ./make_genuine_slackware_iso <edition>

<edition> should be slackware-<version> or slackware64-<version> and a mirror
of it should be available in \$MIRRORS. Set ISO_IMAGES and MIRRORS first."
  echo
  exit
fi
if [ ! -d $MIRRORS/$1  ]; then
  echo  "No mirror $MIRRORS/$1. Check your typing and settings,
mount the removable device hosting it if need be then run this script again."
  exit
  fi
if [ ! -d $ISO_IMAGES ]; then
  echo  "Directory $ISO_IMAGES that should host ISO images doesn't exist. Check your
typing and settings, mount the removable device hosting it if need be then
run this script again."
  exit
fi
if [ -f $ISO_IMAGES/${1}-install-dvd.iso ]; then
  echo "media/images_iso/${1}.iso is already there. Rebuild? [y/N] "
  read -e rebuild
  if [ ! "$rebuild" = "y" ]; then
    echo "bye, then."
    echo
    exit
  fi
fi
( cd $MIRRORS/$1
if [ "$SFX" = "64" ]; then
  EFIOPTIONS="-eltorito-alt-boot -e isolinux/efiboot.img -isohybrid-gpt-basdat -no-emul-boot"
fi
xorriso -as mkisofs \
    -isohybrid-mbr /usr/share/syslinux/isohdpfx.bin \
    -hide-rr-moved \
    -U \
    -V "SLINT$SFX_CURRENT" \
    -J \
    -joliet-long \
    -r \
    -v \
    -m source \
    -o $ISO_IMAGES/${1}-install-dvd.iso \
    -b isolinux/isolinux.bin \
    -c isolinux/boot.cat \
    -no-emul-boot \
    -boot-info-table $EFIOPTIONS . \
)
