#!/bin/sh

#{{{}}}
#{{{  check for m4
if (m4 </dev/null)
then
#  {{{  intro
  echo "Hi, to configure MGR you will have to answer a few questions."
  echo
#  }}}
else
#  {{{  abort
  echo "Eeeek, you don't have /usr/bin/m4!"
  echo "You will have to install it first, bye."
  exit 1
#  }}}
fi
#}}}

#{{{  OS
#{{{  ask OS
echo '1) Linux 0.99.9'
echo "2) SunOS 4.1.2"
echo "3) HP-UX 8.07"
echo "4) Coherent 4.0.[01]*"
echo
echo -n "What OS do you use? "
read OS
echo
#}}}
case $OS in
#  {{{  linux
  1)
  M4=m4
  M4FLAGS="$M4FLAGS -Dlinux"
#  {{{  grafics card
  echo "1) Hercules grafics card"
  echo "2) VGA"
  echo
  echo -n "What grafics card do you use? "
  read CARD
  echo
  case $CARD in
    1) M4FLAGS="$M4FLAGS -Dhgc" ;;
    2) M4FLAGS="$M4FLAGS -Dvga" ;;
    *) echo "Invalid answer, bye :("; exit 1 ;;
  esac
#  }}}
#  {{{  mouse
  echo '0) serial Microsoft mouse'
  echo '1) Mouse Systems 3 byte (as used in Suns)'
  echo '2) serial Mouse Systems 5 byte (as often used in PCs)'
  echo '3) serial MMSeries mouse'
  echo '4) serial Logitech mouse'
  echo '5) PS/2 mouse'
  echo '6) Bus mouse'
  echo
  echo -n "What mouse do you use? "
  read MOUSE
  echo
  case $MOUSE in
    [0-6]) M4FLAGS="$M4FLAGS -DMOUSE=$MOUSE" ;;
    *) echo "Invalid answer, bye :("; exit 1 ;;
  esac
#  }}}
#  {{{  movie mgr
  echo "MOVIE MGR crashes the server, so only select it for debugging it."
  echo
  echo -n "Do you want to use MOVIE MGR (logging) functions? (y/n) "
  read MOVIE
  echo
  case $MOVIE in
    y) M4FLAGS="$M4FLAGS -Dmovie" ;;
    n) ;;
    *) echo "Invalid answer, bye :("; exit 1 ;;
  esac
#  }}}
  ;;
#  }}}
#  {{{  sunos
  2)
  M4=/usr/5bin/m4
  M4FLAGS="$M4FLAGS -Dsunos" ;;
#  }}}
#  {{{  hp-ux
  3)
  M4=m4
  M4FLAGS="$M4FLAGS -Dhpux" ;;
#  }}}
#  {{{  coherent
  4)
  M4=m4
  M4FLAGS="$M4FLAGS -Dcoherent"
#  {{{  graphics card
  echo "1) Hercules graphics card"
  echo "2) VGA 640x480"
  echo "3) SVGA 800x600"
  echo "4) SVGA 1024x768 (Trident SVGA only) - not tested"
  echo
  echo -n "What graphics card do you use? "
  read CARD
  echo
  case $CARD in
    1) M4FLAGS="$M4FLAGS -Dhgc" ;;
    2) M4FLAGS="$M4FLAGS -Dvga" ;;
    3) M4FLAGS="$M4FLAGS -Dsvga1" ;;
    4) M4FLAGS="$M4FLAGS -Dsvga2" ;;
    *) echo "Invalid answer, bye :("; exit 1 ;;
  esac
#  }}}
#  {{{  mouse
  echo '0) serial Microsoft mouse'
  echo '1) Mouse Systems 3 byte (as used in Suns)'
  echo '2) serial Mouse Systems 5 byte (as often used in PCs)'
  echo '3) serial MMSeries mouse'
  echo '4) serial Logitech mouse'
  echo '5) PS/2 mouse'
  echo
  echo -n "What mouse do you use? "
  read MOUSE
  echo
  case $MOUSE in
    [0-6]) M4FLAGS="$M4FLAGS -DMOUSE=$MOUSE" ;;
    *) echo "Invalid answer, bye :("; exit 1 ;;
  esac
#  }}}
#  {{{  movie mgr
  echo "MOVIE MGR crashes the server, so only select it for debugging it."
  echo
  echo -n "Do you want to use MOVIE MGR (logging) functions? (y/n) "
  read MOVIE
  echo
  case $MOVIE in
    y) M4FLAGS="$M4FLAGS -Dmovie" ;;
    n) ;;
    *) echo "Invalid answer, bye :("; exit 1 ;;
  esac
#  }}}
  ;;
#  }}}
#  {{{  *)
  *)
  echo "Invalid answer, bye :("; exit 1 ;;
#  }}}
esac
#}}}
#{{{  mgr home directory
#{{{  ask WHEREHOME
echo "1) /usr/mgr"
echo "2) "$HOME"/mgr"
echo
echo -n "Where shall MGR live (or type alternate path)? "
read WHEREHOME
echo
#}}}
case $WHEREHOME in
#  {{{  /usr/mgr
  1) M4FLAGS="$M4FLAGS -DWHEREHOME=/usr/mgr" ;;
#  }}}
#  {{{  $HOME/mgr
  2) M4FLAGS="$M4FLAGS -DWHEREHOME=$HOME/mgr" ;;
#  }}}
#  {{{  other choice
  *) M4FLAGS="$M4FLAGS -DWHEREHOME=$WHEREHOME" ;;
#  }}}
esac
#}}}
#{{{  examples
#{{{  ask EXAMPLES
echo "1) Install client programming examples"
echo "2) Don't install them"
echo
echo -n "Do you want the programming examples to be installed? "
read EXAMPLES
echo
#}}}
case $EXAMPLES in
#  {{{  /usr/mgr
  1) M4FLAGS="$M4FLAGS -DEXAMPLES=examples" ;;
#  }}}
#  {{{  $HOME/mgr
  2) M4FLAGS="$M4FLAGS -DEXAMPLES=" ;;
#  }}}
#  {{{  *)
  *)
  echo "Invalid answer, bye :("; exit 1 ;;
#  }}}
esac
#}}}
#{{{  groff font directory
#{{{  ask WHEREGROFFFONT
echo "1) /usr/groff/font"
echo "2) /usr/lib/groff/font"
echo "3) "$HOME"/groff/font"
echo "4) No groff installed"
echo
echo -n "Where is groff's font directory (or type alternate path)? "
read WHEREGROFFFONT
echo
#}}}
case $WHEREGROFFFONT in
#  {{{  /usr/groff/font
  1) M4FLAGS="$M4FLAGS -Dgropbm -DWHEREGROFFFONT=/usr/groff/font" ;;
#  }}}
#  {{{  /usr/lib/groff/font
  2) M4FLAGS="$M4FLAGS -Dgropbm -DWHEREGROFFFONT=/usr/lib/groff/font" ;;
#  }}}
#  {{{  $HOME/groff/font
  3) M4FLAGS="$M4FLAGS -Dgropbm -DWHEREGROFFFONT=$HOME/groff/font" ;;
#  }}}
#  {{{  nothing
  4) M4FLAGS="$M4FLAGS -DWHEREGROFFFONT=" ;;
#  }}}
#  {{{  other choice
  *) M4FLAGS="$M4FLAGS -Dgropbm -DWHEREGROFFFONT=$WHEREGROFFFONT" ;;
#  }}}
esac
#}}}
#{{{  tex font directory
#{{{  ask WHEREFONTDESC
echo "1) /usr/TeX/lib/tex/fontdesc"
echo "2) No TeX installed"
echo
echo -n "Where is TeX's fontdesc file (or type alternate name)? "
read WHEREFONTDESC
echo
#}}}
case $WHEREFONTDESC in
#  {{{  /usr/TeX/lib/fontdesc
  1) M4FLAGS="$M4FLAGS -Dtexmgr -DWHEREFONTDESC=/usr/TeX/lib/tex/fontdesc" ;;
#  }}}
#  {{{  nothing
  2) M4FLAGS="$M4FLAGS -DWHEREFONTDESC=" ;;
#  }}}
#  {{{  other choice
  *) M4FLAGS="$M4FLAGS -Dtexmgr -DWHEREFONTDESC=$WHEREFONTDESC" ;;
#  }}}
esac
#}}}

echo 'Ok, building Configfile ...'
$M4 $M4FLAGS < Configfile.m4 > Configfile

#{{{  tell people what to do now
echo "Ok, if you think you know what you are doing, then change the defaults in"
echo "Configfile now.  After, the following steps are neccessary:"
echo ""
echo "-  check if your termcap/terminfo database contains the entries found"
echo "   in src/misc."
echo "-  check that /dev/mouse is the device for or a link to your mouse."
echo "-  create MGR paths using 'make first'."
echo "-  run 'make depend' to update dependencies."
echo "-  run 'make install' to build and install everything."
echo ""
echo "In each directory, you can do 'make [depend|all|install|clean|clobber]',"
echo "in case you want to hack in the code."
echo ""
echo "Michael"
#}}}

exit 0
