/[cvs]/eggdrop1.4/scripts/autobotchk
ViewVC logotype

Annotation of /eggdrop1.4/scripts/autobotchk

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (hide annotations) (download)
Thu Jun 24 19:23:32 1999 UTC (20 years, 4 months ago) by segfault
Branch: MAIN
Changes since 1.1: +15 -12 lines
Ernst patches to fix bugs in autobotchk and userinfo1.0

1 segfault 1.1 #!/bin/sh
2     # ^-- little trick to restart using tclsh \
3     exec tclsh "$0" "$@"
4     #
5     # AutoBotchk, (C)1999 Jeff Fisher (guppy@eggheads.org)
6     #
7     # updates
8     # -------
9     # 03Feb99: wrote the first version and it worked
10     # 04Feb99: made it easier to use, how? ./autobotchk
11     # <config> will create the botchk and crontab
12     # automatically, no command line options now.
13     # 20Feb99: added a '-noemail' setting for [s]
14     # 21Feb99: added '-5' '-10' '-15' '-30' to allow people to
15     # use a diff time value then 10 minutes.
16 segfault 1.2 # 10May99: to be compatible, don't use */XX's, etc (Ernst)
17 segfault 1.1 #
18     # how to use
19     # ----------
20     # well, first you need to put the program into your Eggdrop
21     # directory (the one you run from hopefully). then you should
22     # probably type 'chmod u+x autobotchk' so the file permissions
23     # are set correctly. and finally, type './autobotchk <config>'
24     # replacing <config> with the name of your config file right?
25     #
26     # in 1.05z, because of [z], you can now specify the bot directory
27     # to use, for example, './autobotchk eggdrop.conf -dir /home/bot'
28     # this now allows you to run the program from any dir :P~
29     #
30     # other Stuff
31     # -----------
32     # [22:36] <cHr|s`> when you type ./autobotchk without any options, it should give you the menu
33     # [22:36] <cHr|s`> like the nukes do
34     # ^ -- he might be Urkel, but we love him anyways ..
35     # [18:10] <[z]> nope...came back weith can't crontab -l error
36     # ^ -- no one said this script was perfect, mmmm z's wife
37     # [19:27] <[z]> also guppy..would be nice if i could reference my bots directories ;)
38     # ^ -- just when I finished 1.05 :P
39     # [18:50] <[s]> how to set the autobotchk not to recieve e-mails about the cron ??
40     # [18:51] <slennox> add >/dev/null 2>&1 to the end of the crontab entry
41     # [18:52] <[s]> what crontab
42     # [18:52] <[s]> i have gupy's script
43     # [18:52] <[s]> autobotchk
44    
45     if {$argc == 0} {
46     puts "\nusage: $argv0 <eggdrop config> \[options\]"
47     puts " -dir (bot directory to use instead of \[pwd\])"
48     puts " -noemail (will make crontab not mail you)"
49     puts " -5 (5 minute checks)"
50     puts " -10 (10 minute checks)"
51     puts " -15 (15 minute checks)"
52     puts " -30 (30 minute checks)\n\n"
53     exit
54     } {
55     puts "\nAutoBotchk 1.06p1, (C)1999 Jeff Fisher (guppy@eggheads.org)"
56     puts "----------------------------------------------------------"
57    
58     set x [join [lindex [split $argv] 0]]
59     set q [lrange $argv 1 end]
60     set dir [pwd]
61     set delay 10
62     set email 1
63     for {set z 0} {$z < [llength $q]} {incr z} {
64     set opt [join [lindex $q $z]]
65     switch -- $opt {
66     -time -
67 segfault 1.2 -1 {set delay 1}
68 segfault 1.1 -5 {set delay 5}
69     -10 {set delay 10}
70     -15 {set delay 15}
71     -20 {set delay 20}
72     -30 {set delay 30}
73     -nomail -
74     -noemail {set email 0}
75     -dir {
76     set dir [string trimright [join [lindex $q [expr $z + 1]]] /]
77     if {[string match -* $dir]} {
78     puts " *** ERROR: you did not supply a directory name\n\n"
79     exit
80     }
81     if {![file isdirectory $dir]} {
82     puts " *** ERROR: the directory you supplied is not a directory\n\n"
83     exit
84     }
85     incr z
86     }
87     }
88     }
89 segfault 1.2 switch -- $delay {
90     30 { set minutes "0,30" }
91     15 { set minutes "0,15,30,45" }
92     5 { set minutes "0,5,10,15,20,25,30,35,40,45,50,55" }
93     1 { set minutes "*" }
94     default { set minutes "0,10,20,30,40,50" }
95     }
96 segfault 1.1 if {![file exists $dir/$x]} {
97     puts " *** ERROR: you supplied a non-existant filename\n\n"
98     exit
99     } elseif {![file isfile $dir/$x]} {
100     puts " *** ERROR: unknown filetype, config files should be text files\n\n"
101     exit
102     } elseif {![file readable $dir/$x]} {
103     puts " *** ERROR: unable to open the file, permission denied\n\n"
104     exit
105     } elseif {![file exists $dir/help] || ![file isdirectory $dir/help]} {
106     puts " *** ERROR: are you sure you are running from a bot directory?\n\n"
107     exit
108     } elseif {![file exists $dir/eggdrop]} {
109     puts " *** ERROR: are you sure you are running from a bot directory?\n\n"
110     exit
111     }
112     puts " *** Attempting to process '$x', be patient ..."
113    
114     set f [open $dir/$x r]
115     while {![eof $f]} {
116     set z [split [gets $f]]
117     if {[join [lindex $z 0]] != "set"} {continue}
118     switch -- [join [lindex $z 1]] {
119     nick -
120     userfile -
121     botnet-nick {
122     set [join [lindex $z 1]] [join [lindex $z 2]]
123     puts " !! scanned: [join $z]"
124     }
125     }
126     }
127     close $f
128     if {![info exists {botnet-nick}] && [info exists nick]} {
129     puts " !! setting \$botnet-nick to \$nick"
130     set botnet-nick $nick
131     }
132     if {![info exists {botnet-nick}] || ![info exists userfile]} {
133     puts " *** ERROR: could not find either \$userfile or \$botnet-nick"
134     puts " !! you sure its a valid Eggdrop config file?\n\n"
135     exit
136     }
137     if {[catch {open $dir/${botnet-nick}.botchk w} fd]} {
138     puts " *** ERROR: unable to open '${botnet-nick}.botchk' for writing"
139     puts " !! without this, this program is useless\n\n"
140     exit
141     }
142     puts $fd "#!/bin/sh\n#"
143     puts $fd "# Created on: [clock format [clock seconds] -format "%B %d, %Y @ %I:%M%p"]"
144     puts $fd "# Created by: AutoBotchk 1.05 (C)1999 Jeff Fisher\n#"
145     puts $fd "# (this is basically botchk from scripts/, credits to the author(s)\n#"
146     puts $fd "\n# Directory the Eggdrop runs from:"
147     puts $fd "botdir=\"$dir\""
148     puts $fd "\n# Name of our configuration file (including the binary):"
149     puts $fd "botscript=\"eggdrop $x\""
150     puts $fd "\n# Eggdrop's nickname (capitalization COUNTS):"
151     puts $fd "botname=\"${botnet-nick}\""
152     puts $fd "\n# Eggdrop's userfile (capitalization COUNTS):"
153     puts $fd "userfile=\"$userfile\""
154     puts $fd "\n########## Edit before here if you want, but you shouldn't need too ##########"
155     puts $fd "\ncd \$botdir"
156     puts $fd "if test -r pid.\$botname; then"
157     puts $fd " # there is a pid file -- is it current?"
158     puts $fd " botpid=`cat pid.\$botname`"
159     puts $fd " if `kill -CHLD \$botpid >/dev/null 2>&1`; then"
160     puts $fd " # it's still going"
161     puts $fd " # back out quietly"
162     puts $fd " exit 0"
163     puts $fd " fi"
164     puts $fd " echo \"\""
165     puts $fd " echo \"Stale pid.\$botname file (erasing it)\""
166     puts $fd " rm -f pid.\$botname"
167     puts $fd "fi"
168     puts $fd "echo \"\""
169     puts $fd "echo \"Couldn't find the bot running. Reloading it...\""
170     puts $fd "echo \"\""
171     puts $fd "# Check for userfile first"
172     puts $fd "if test -r \$userfile; then"
173     puts $fd " # It's there, load the bot"
174     puts $fd " ./\$botscript"
175     puts $fd " exit 0"
176     puts $fd "fi"
177     puts $fd "if test -r \$userfile~new; then"
178     puts $fd " # Bot f*@!ed up while saving the userfile last time. Move it over."
179     puts $fd " echo \"Userfile missing. Using last saved userfile...\""
180     puts $fd " mv \$userfile~new \$userfile"
181     puts $fd " ./\$botscript"
182     puts $fd " exit 0"
183     puts $fd "fi"
184     puts $fd "if test -r \$userfile~bak; then"
185     puts $fd " # Userfile is missing, use backup userfile."
186     puts $fd " echo \"Userfile missing. Using backup userfile...\""
187     puts $fd " cp \$userfile~bak \$userfile"
188     puts $fd " ./\$botscript"
189     puts $fd " exit 0"
190     puts $fd "fi"
191     puts $fd "# Well, nothing to work with..."
192     puts $fd "echo \"No userfile. Could not reload the bot..\""
193     puts $fd "exit 0"
194     close $fd
195     puts " *** Wrote '${botnet-nick}.botchk' successfully ([file size $dir/${botnet-nick}.botchk] bytes)"
196     if {[catch {exec chmod u+x $dir/${botnet-nick}.botchk} 0]} {
197     puts " *** ERROR: unable to 'chmod u+x' the output file\n\n"
198     exit
199     }
200     puts " !! chmod u+x completed"
201     puts " *** Crontab mode?? Heaven forbid I automated this ..."
202     set tmp "[pwd]/.autobotchk"
203     if {$delay != "10"} {puts " *** Using a time delay of $delay minutes."}
204     if {$email} {
205 segfault 1.2 set line "$minutes \* \* \* \* $dir/${botnet-nick}.botchk"
206 segfault 1.1 } {
207 segfault 1.2 set line "$minutes \* \* \* \* $dir/${botnet-nick}.botchk >\/dev\/null 2>&1"
208 segfault 1.1 puts " *** Making crontab line to NOT send e-mail."
209     }
210     if {[catch {exec crontab -l > $tmp} error ]} {
211 segfault 1.2 if {![string match "*no*cron*" [string tolower $error]] &&
212     ![string match "*can't open*" [string tolower $error]]} {
213 segfault 1.1 catch {exec rm -rf $tmp} 0
214     puts " *** ERROR: unable to get crontab listing"
215     puts " *** MSG: $error\n\n"
216     exit
217     }
218     }
219     set fd [open $tmp r]
220     while {![eof $fd]} {
221     set z [split [gets $fd]]
222     if {[string match "*$dir/${botnet-nick}.botch*" $z]} {
223     puts " !! ${botnet-nick}.botchk is already crontab'd, but why?\n\n"
224     exit
225     }
226     }
227     close $fd
228     set fd [open $tmp a]
229     puts $fd $line
230     puts " !! adding new crontab line to existing crontab"
231     close $fd
232     if {[catch {exec crontab $tmp} error]} {
233     puts " *** ERROR: unable to do 'crontab $tmp'"
234     puts " *** MSG: $error\n\n"
235     exit
236     }
237     catch {exec rm -rf $tmp} 0
238     puts " !! crontab reloaded\n\n"
239 segfault 1.2 puts " !! Use 'crontab -r' to remove all your crontab entries"
240     puts " !! 'crontab -l' to view the current crontabs"
241 segfault 1.1 exit
242     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23