#!/bin/sh
# entity.tcl setup (c) 1998 - 2001 by Mixter <mixter@newyorkoffice.com>
eggname=./e

printf "\tentity 9.2 configuration setup by Mixter\n\nsearching for eggdrop... "
if test ! -r eggdrop ;then
printf "not found\n\nplease compile eggdrop AND the modules first\n"
printf "because this script removes unneccessary files like sources\n"
printf "\t\tentity9: trying eggdrop standard compilation...\n\n"
./configure ; make config && make
exit 1 ; fi

# hide me ? (remove default telnet banner and stealth banner)
cat language/core.english.lang | \
 grep -v "0x53e" | grep -v "0x540" > language/tmp && \
 printf "0x53e,\n0x540,\n" >> language/tmp && \
 mv -f language/tmp language/core.english.lang

cp src/mod/*.mod/language/* language

printf "ok\nsearching for entity.tcl... "
if test ! -r entity.tcl ;then printf "not found\n\n---STOP---\n";exit 1 ;fi
printf "found\nremoving unneeded files, hit enter to continue or type \"QUIT\": "
read fd ; if test ! -z $fd ; then printf "skipped.\n" ; else
rm -rf .*mod* C* E* F* I* M* N* R* T* ac* aux confi* 1>/dev/null 2>/dev/null
rm -rf di* doc eggdrop.* lo* lu* te* misc scr* src 1>/dev/null 2>/dev/null
touch motd
printf "...cleaned\n" ; fi ; printf "renaming eggdrop to \"$eggname\"... "
mv eggdrop $eggname
printf "5,15,25,35,45,55 * * * *   \"`pwd`/bchk\" >/dev/null 2>&1\n" >cron
printf "Bot nick: " ; read fd
if test -z $fd ; then echo error. ; exit 0 ; fi
c=conf.${fd}
echo "#!/bin/sh" > bchk ; echo cd \"`pwd`\" >> bchk
echo "if [ ! -f pid.* ] ; then" >> bchk
echo ./$c >> bchk ; echo "exit ; fi" >> bchk
echo botpid=\`cat pid.\*\` >> bchk
echo if \`kill -CHLD \$botpid \>/dev/null 2\>\&1\`\; then >> bchk
echo ./$c >> bchk ; echo "exit ; fi" >> bchk
echo "rm -f pid.*" >> bchk ; echo ./$c >> bchk
echo exit 0 >> bchk ; chmod 755 bchk
touch $c ; chmod 755 $c ; echo \#\!`pwd`/$eggname > $c
echo set nick1 \"$fd\" >> $c ; mv userfile .u.${fd}
printf "Bot ident ["`whoami`"]: " ; read fd
if test ! -z $fd ; then echo set username \"$fd\" >> $c ; fi
if test -z $fd ; then echo set username \"`whoami`\" >> $c ; fi
printf "Bot ircname [random]: " ; read fd
if test ! -z "$fd" ; then echo set realname \"$fd\" >> $c ; fi
printf "Bot owner [Mixter]: " ; read fd
if test ! -z $fd ; then echo set owner \"$fd\" >> $c ; fi
if test -z $fd ; then echo set owner \"Mixter\" >> $c ; fi
printf "Listening ports(all) [12345]: " ; read fd
if test ! -z $fd ; then echo set allport \"$fd\" >> $c ; fi
if test -z $fd ; then echo set allport \"12345\" >> $c ; fi
printf "Listening ports(users) [none]: " ; read fd
if test ! -z $fd ; then echo set useport \"$fd\" >> $c ; fi
printf "Listening ports(bots) [none]: " ; read fd
if test ! -z $fd ; then echo set botport \"$fd\" >> $c ; fi
printf "Bots channels [#bme]: " ; read fd
if test ! -z $fd ; then echo set botchans \"$fd\" >> $c ; fi
if test -z $fd ; then echo set botchans \"#bme\" >> $c ; fi
printf "IRC Network [EFNET]: " ; read fd
if test ! -z $fd ; then echo set network \"$fd\" >> $c ; fi
if test -z $fd ; then echo set network \"EFNET\" >> $c ; fi
printf "Use secure challenge authentication for owners (1/0)? " ; read fd
if test ! -z $fd ; then echo set challenging $fd >> $c ; fi
echo source entity.tcl >> $c
printf "done\ntype \"crontab cron\" to activate crontab\n"
printf "type \"./bchk\" or \"./$c\" to start the bot manually\n" ; exit 0
