#!/bin/sh
# Gently borrowed code from x11/XFree86-4

yesno () {
  answ=X
  while [ $answ = X ]; do
    echo -n "$2 [$1] "
    read answ
    if [ X$answ = X ]; then answ=$1; fi
    case $answ in
      y|yes|Y|YES) answ=YES;;
      n|no|N|NO)   answ=NO;;
      *) echo invalid answer
      answ=X
      ;;
    esac
  done
}

question() {
  echo -n "$2 [$1] "
  read answ
  if [ X$answ = X ]; then answ=$1; fi
}

F=$WRKDIR/.config
rm -f $F

cat <<EOF
Welcome to the Heroes of Might And Magic 3 installer.
You may now choose to install parts of the distribution on disk. 
If you choose not to install a part, I will make a link to the CDROM 
so you will have them in case you have your CD mounted while you play.
You must have your CDROM mounted right now.

EOF
question /cdrom "Where is your CD mounted?"
if [ ! -f $answ/Heroes_III_Tutorial.pdf ] ; then
    echo "Might and Magic III CD not found. Please mount the CD and retry."
    exit 1
fi
echo CD=$answ >> $F
echo "Do you want to install the Basis game packet?"
yesno YES "Without this you can't play without CD. (112 MB) "
echo BASIC=$answ >> $F
echo "Do you want to install the Graphic packet?"
yesno YES "Without this you can't play without CD. (14 MB)  "
echo GRAPHIC=$answ >> $F
yesno YES "Do you want to install the Scenarios (1 MB)      "
echo SCENARIO=$answ >> $F
yesno NO  "Do you want to install Music (64 MB)             "
echo MUSIC=$answ >> $F
yesno NO  "Do you want to install Videos (137 MB)           "
echo VIDEOS=$answ >> $F

. $F

cat ${PKGDIR}/files/pkg-plist.base > ${PLIST}

# Scenario files
if [ $SCENARIO = YES ]; then
        cat ${PKGDIR}/files/pkg-plist.scenario >> ${PLIST}
else
        echo ${GAMESUBDIR}/maps >> ${PLIST}
fi

# Neither sound nor Music, make the whole data tree a link
if [ $GRAPHIC = NO -a $MUSIC = NO ]; then
	echo ${GAMESUBDIR}/data/video >> ${PLIST}
else
	cat ${PKGDIR}/files/pkg-plist.video >> ${PLIST}
fi

# Videos
if [ $VIDEOS = YES ]; then
        cat ${PKGDIR}/files/pkg-plist.video >> ${PLIST}
fi



# Music
if [ $MUSIC = YES ]; then
	cat ${PKGDIR}/files/pkg-plist.music >> ${PLIST}
else
	echo ${GAMESUBDIR}/mp3 >> ${PLIST}	
fi

echo @dirrm ${GAMESUBDIR}/data >> ${PLIST}
echo @dirrm ${GAMESUBDIR} >> ${PLIST}

exit 0
