#/bin/sh
#\
exec tclsh "$0" "$@"

#########################################################
##### egg-autoconf 0.1 by dw!#eggdrop@undernet      #####
#
# For eggdrop1.3.24i and will prolly work with the next to
# desc : a litle util to make it easyer to cfig eggdrop
# usage: ./egg-autoconf
#
# If you have trouble running this litle app first
# try chmod 700 egg-autoconf then if it still dont
# start try replacing the 3 top lines with
# #!/path/to/tclsh
#
# v0.1 16/3-99 - prowling the jungle looking fer bugs
# v0.2 xx/x-xx - ?
#########################################################
##### Remember kiddies ripping other ppls work and  #####
##### releasing them again in a zip is plain lame   #####
#########################################################

puts -nonewline "Checking Tcl version... "
flush stdout
set tclver [info tclversion]
if {$tclver < 8} {
puts "found Tcl ${tclver}...old shit like this wont work sorry."
exit
} else {
puts "found ${tclver}([info patchlevel]), good lets continue!"
}

catch {exec pwd} pwd

set dir [lindex [split $pwd /] end]
if {[llength [split $dir .]] > 1} {
puts "You didn't read INSTALL properly.."
puts "If you had you wouldn't try to run the bot from $pwd \n"
puts {This is how you install the bot..(asuming 1.3.24i)
1) tar zxvf eggdrop1.3.24i.tar.gz
2) cd eggdrop1.3.24i
3) ./configure
4) make
5) make install
6) cp eggdrop.conf.dist ~/eggdrop
7) cd ~/eggdrop
8) either cp eggdrop.conf.dist <botname>.conf and edit it or
   put egg-autoconf in ~/eggdrop and ./egg-autoconf
9) start the bot.. first time ./eggdrop -m botname.conf
   after that ./eggdrop botname.conf
10) fix crontab (read scripts/botchk or get autobotchk)}
exit
}
puts "Gathering info needed to create config file..\n"
if {[info exists env(USER)]} {
set username [string tolower $env(USER)]
puts "USER...found! username set/ident to... $username"
} else {
set username "eggdrop"
puts "USER....not found! username/ident set to... $username"
puts "....edit the conf file to change that later if you want.\n"
}
set i 2
if {[file exists ${username}.conf]} {
while {$i != 0} {
if {![file exists ${username}${i}.conf]} {
set username "${username}${i}"; set i 0
} else {
incr i
 }
} 
puts "Old config file found naming this... ${username}.conf"
} else {
puts "Naming this config file... ${username}.conf"
}
puts "The bot needs a free port to listen on..."
##lets write a random nr.gen. function just for fun
proc dwrand {min max} {
return [expr int((rand() * ($max-$min))+$min)]
}
set pf 1
while {$pf} {
set port [dwrand 3000 65000]
puts -nonewline "Trying port ${port}... "
flush stdout
catch {socket 127.0.0.1 $port} conn
if {[llength $conn] > 1} {
puts "Success! Port seems to be avaible will use this."
set pf 0
} else {
puts "Faild! Port in use trying another."
close $conn
 }
}
puts "\n##############################################"
puts " Eggdrop dont like chars like: \{ \} \[ \] \\"
puts " escape them using \\ like this \\\[nick\\\]"
puts {  (it has nothing to do of the coding of this 
   tcl its how eggdrop reads the conf file)}
puts "##############################################"
puts "\n--- And some questions --\n"
puts "where can the bot admin be reached.."
puts -nonewline "e-mail \t:"
flush stdout
set admin [gets stdin] 
puts -nonewline "\nbotnick\t:"
flush stdout
set nick [gets stdin]
puts "(use this nick if the primary nick isn't avaible)"
puts -nonewline "altnick\t:"
flush stdout
set altnick [gets stdin]
puts ""
puts {[0/1/2/3/4] What is your network? 0 = Efnet, 1 = IRCnet, 2 = Undernet,
# 3 = Dalnet, 4 = Others }
puts -nonewline "nettype\t:"
flush stdout
set nettype [gets stdin]
puts "\nIRC servers add them like irc.server.net:6667 irc.server2.net:6669 ..."
puts -nonewline "ircsrvs\t:"
flush stdout
set servers [gets stdin]
puts "\nChannel to add bot in (use .+chan to add more later)"
puts -nonewline "channel\t:"
flush stdout
set channel [gets stdin]
puts ""
puts -nonewline "writing config file... "
flush stdout

set fid [open ${username}.conf w+]
puts $fid "#!${pwd}/eggdrop"
puts $fid {
####################################
# generated using egg-autoconf 0.1 #
####################################
# look in eggdrop.conf.dist for
# help on every choise
####################################
}
puts $fid "set username \"$username\""
puts $fid "set admin \"Lamer <email: $admin>\""
puts $fid {set network "I.used.egg-autoconf.to.make.this.conf.file"
set timezone "GMT"
#set my-hostname "virtual.host.com"
#set my-ip "99.99.0.0"
set max-logs 5
logfile jmkco * "eggdrop.log"
set log-time 1
set keep-all-logs 0
set switch-logfiles-at 100
set console "jmkcobxs"
}
puts $fid "set userfile \"${username}.user\""

puts $fid {set sort-users 0
set help-path "help/"
set temp-path "/tmp"
set motd "motd"
#set botnet-nick "LlamaBot"}

puts $fid "listen $port all"

puts $fid {set protect-telnet 1
set dcc-sanitycheck 0
set ident-timeout 30
#listen 3333 bots
#listen 4444 users
set require-p 1
set open-telnets 0
set connect-timeout 15
set dcc-flood-thr 3
set telnet-flood 5:60
set resolve-timeout 15
#set firewall "proxy:178"
#set firewall "!sun-barr.ebay:3666"
#set nat-ip "127.0.0.1"
#set reserved-port 9076
set ignore-time 10
set debug-output 0
set hourly-updates 00
##
# The next two lines is a good idea to edit
set notify-newusers ""
set owner ""
##
set default-flags "h"
set whois-fields "url birthday"
set remote-boots 2
set share-unlinks 1
set die-on-sighup 0
set die-on-sigterm 0
#unbind dcc n tcl *dcc:tcl
#unbind dcc n set *dcc:set
set must-be-owner 1
unbind dcc n simul *dcc:simul
set max-dcc 50
set enable-simul 1
set allow-dk-cmds 0
set mod-path "modules/"
loadmodule channels}

puts $fid "set chanfile \"${username}.chan\""

puts $fid {set ban-time 130
set exempt-time 0
set invite-time 0
set share-greet 0
set use-info 1}

puts $fid "channel add $channel \{"
puts $fid {  chanmode "+nt-k"
  idle-kick 0
  need-op { }
  need-invite { }
  need-key { }
  need-unban { }
  need-limit { }
  flood-chan 10:30
  flood-deop 3:10
  flood-kick 3:10
  flood-join 5:60
  flood-ctcp 6:30 }
puts $fid "  \}"

puts $fid "channel set $channel -clearbans +enforcebans +dynamicbans"
puts $fid "channel set $channel +userbans -autoop -bitch +greet"
puts $fid "channel set $channel +protectops -statuslog -stopnethack"
puts $fid "channel set $channel -revenge +autovoice -secret"
puts $fid "channel set $channel -shared +cycle +dontkickops"

puts $fid {
loadmodule server

# [0/1/2/3/4] What is your network? 0 = Efnet, 1 = IRCnet, 2 = Undernet,  
# 3 = Dalnet, 4 = Others }
puts $fid "set net-type $nettype"

puts $fid "set nick \"$nick\""
puts $fid "set altnick \"$altnick\""
puts $fid {set realname "la da di la di da"
set init-server { putserv "MODE $botnick +iw-s" }
}
puts $fid "set servers \{"
foreach srv $servers {
puts $fid "$srv"
}
puts $fid "\}"
puts $fid {
set keep-nick 1
set strict-host 0
set quiet-reject 1
set lowercase-ctcp 0
set answer-ctcp 3

set flood-msg 10:40
set flood-ctcp 4:40

set never-give-up 1
set strict-servernames 0
set default-port 6667
set server-cycle-wait 65
set server-timeout 20
set servlimit 0
set check-stoned 1

set use-console-r 0
set serverror-quit 1
set max-queue-msg 300
set trigger-on-ignore 0

#set use-silence 1
#set check-mode-r 1

loadmodule ctcp
loadmodule irc

set bounce-bans 1
set bounce-modes 0
set max-bans 20
set max-modes 30
set allow-desync 0
set kick-bogus 0
set ban-bogus 0
set kick-fun 0
set ban-fun 0
set learn-users 0
set wait-split 900
set wait-info 40
set mode-buf-length 200
#unbind msg - hello *msg:hello
#bind msg - myword *msg:hello
#unbind msg - ident *msg:ident
#unbind msg - addhost *msg:addhost
set no-chanrec-info 0

##### IRC MODULE - net-type 1 specific features (IRCnet) ####

set bounce-exempts 0
set bounce-invites 0
set max-exempts 0
set max-invites 0

##### IRC MODULE - net-type 4 specific features (other networks) #####

#    0 = kick all nicks at once in one command
#    X = kick X users at a time
#set kick-method 1
#set modes-per-line 3
#set use-354 0

loadmodule transfer

set max-dloads 3
set dcc-block 0
set copy-to-tmp 1
set xfer-timeout 25

#loadmodule share
#set allow-resync 0
#set resync-time 900
#set private-owner 0
#set private-global 0
#set private-globals "mnot"
#set private-user 0

#loadmodule filesys }
puts $fid "set files-path \"${pwd}/filesys\""
puts $fid "set incoming-path \"${pwd}/filesys/incoming\""
puts $fid {set upload-to-pwd 0
set filedb-path ""
set max-file-users 20
set max-filesize 1024

loadmodule notes }
puts $fid "set notefile \"${username}.notes\""
puts $fid {set max-notes 50
set note-life 60
set allow-fwd 1
set notify-users 1

loadmodule console
set console-autosave 0
set force-channel 0
set info-party 1

#loadmodule woobie

#get bseen instead thats the best seen script around
#loadmodule seen

checkmodule blowfish
loadmodule assoc

#####  SCRIPTS  #####
source scripts/alltools.tcl
source scripts/action.fix.tcl
source scripts/userinfo1.0.tcl
loadhelp userinfo.help

### add your other tcl scripts under this line ###

}
close $fid
catch {exec chmod 700 ./${username}.conf}
puts "Done!\n"
puts "First time start the bot using: ./eggdrop -m ${username}.conf"
puts "after that ./${username}.conf should work.\n"
puts "If you want to telnet the bot it listens to port $port\n"
puts "\t\tThats it hope you liked it. (dw)"