#!/bin/ash
#
#
#
 if [ ! -e /usr/games/doom/doom1.wad ]; then
   echo "You need the game wad file to play Doom."
   read -p "Do you wish to download it now (y/n)?: " ANSWER
   ANSWER=y$ANSWER
   if [ $ANSWER = yy ]; then
     URL=http://www.libsdl.org/projects/doom/data/
     FILE=doom1.wad.gz
     rm -f /tmp/$FILE 2>/dev/null
     echo "Downloading:"
     wget $URL$FILE -P /tmp
     if [ ! -e /tmp/$FILE ]; then
       URL=http://dl.4mlinux.com/
       wget $URL$FILE -P /tmp
     fi
     if [ ! -e /tmp/$FILE ]; then
       echo "Error in downloading. Check your internet connection."
       if [ ! x$DISPLAY = x ]; then
         read
       fi
       exit
       else
       mv /tmp/$FILE /usr/games/doom/
       gunzip /usr/games/doom/$FILE
       if [ x$DISPLAY = x ]; then
         doom
       fi
     fi
   fi
   else
   cd /usr/games/doom
   GL=no
   if [ ! x$DISPLAY = x ]; then
     if [ ! -e /usr/share/X11/xorg.conf.d/20-driver2d.conf ]; then
       GL=yes
     fi
   fi
   if [ $GL = yes ]; then
     export LIBGL_DRIVERS_PATH=/usr/games/dri
     export LIBGL_ALWAYS_SOFTWARE=true
     ./prboom -vidmode gl -file doom1.wad
     else
     ./prboom -file doom1.wad
   fi
 fi
