#!/bin/sh
# Simple shell script to simplify necessary additions to files
if test ! -r eggdrop; then
  echo ""
  echo "You don't seem to be in the eggdrop directory."
  echo -n "Do you still wish to proceed (y/N)? "
  read yn
  if test "$yn" = "Y"; then
    yn="y"
  fi
  if test "$yn" != "y"; then
    exit 1
  fi
fi

echo ""
echo "Setting up MadHack's Tewlz, version 2.7 by MadHack <madhack@pobox.com>"
echo ""
echo ""
echo "You may like to start this script when your bot starts up."
echo -n "    Would you like to set this up (Y/n)? "
read yn
if test "$yn" = ""; then
  yn="y"
fi
if test "$yn" = "Y"; then
  yn="y"
fi
if test "$yn" = "y"; then
  echo ""
  echo "Please enter the name of the config file that this will run from:"
  echo -n "    "
  read config
  if test ! -w $config; then
    echo ""
    echo "Error: the file $config does not exist or you do not have write"
    echo "permission on it. Please run again and specify a valid, writable"
    echo "file."
    echo ""
    exit 1
  else
    echo ""
    echo "Adding source to '$config' . . ."
    echo "source scripts/madhack.tcl" >>$config
  fi
else
  echo ""
  echo "Skipping modification of config file. . ."
fi
echo ""
echo "You may also add the new commands to the main help file."
echo -n "    Do you wish to do this (Y/n)? "
read yn
if test "$yn" = ""; then
  yn="y"
fi
if test "$yn" = "Y"; then
  yn="y"
fi
if test "$yn" = "y"; then
  echo -n "    Are you upgrading from Tewlz 2.5 (y/N)? "
  read yn
  if test "$yn" = "Y"; then
    yn="y"
  fi
  if test "$yn" = "y"; then
    echo ""
    echo "Adding new Tewlz 2.7 commands to help . . ."
    echo "%[  +permchan    -permchan    permlist     permset%]" >>help/dcc.help
    echo "%[  tewlz%]" >>help/dcc.help
  else
    if test "$yn" = "n"; then
      echo ""
      echo "Adding new information to help file . . ."
      echo "%(These commands added by MadHack's Tewlz:%)" >>help/dcc.help
      echo "%(  time         date         gmt%)" >>help/dcc.help
      echo "%[  +chan        -chan        chchan       anounce%]" >>help/dcc.help
      echo "%[  +permchan    -permchan    permlist     permset%]" >>help/dcc.help
      echo "%[  isolate      merge        tewlz%]" >>help/dcc.help
    fi
  fi
else
  echo ""
  echo "Skipping help file additions . . ."
fi
echo ""
echo ""
echo "Selected modifications are now complete."
echo ""
