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

Contents of /eggdrop1.4/scripts/autobotchk

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


Revision 1.1 - (show annotations) (download)
Wed Jun 23 19:51:25 1999 UTC (20 years, 4 months ago) by segfault
Branch: MAIN
Branch point for: eggdev
Initial revision

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23