jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [setup.pl] - Blame information for rev 13

 

Line No. Rev Author Line
11simandl#!/usr/bin/env perl
2 
3# $Id: setup.pl,v 1.51 2004/08/17 08:13:55 bernisys Exp $
4 
5# include PERL libraries
6use strict;
7use warnings;
8use diagnostics;
9 
10use FindBin;
11use lib $FindBin::RealBin;
12use Cwd;
13 
14# include HotSaNIC libraries
15use lib "./lib";
16use HotSaNICparser;
17use HotSaNICshellio;
18use HotSaNIClog;
19 
20HotSaNIClog::set_modulename("setup");
21 
22$|=1;
23 
24(my $VERSION = '$Revision: 1.51 $') =~ s/.*(\d+\.\d+).*/$1/;
25(my $IDENTIFIER = '$Id: setup.pl,v 1.51 2004/08/17 08:13:55 bernisys Exp $') =~ s/.*,v (.*) \$/$1/;
26 
27my $ALLYES;
28 
29my $THISDIR=Cwd::cwd();
30my $args=lc join "",@ARGV;
31 
32if ( index($args,"y") >=0 ) { $ALLYES="y"; } else { $ALLYES=""; }
33if ( index($args,"?") >=0 ) {
34 print "Usage:
35 
36 setup.pl [m[y]][s][g][?]
37 
38 when run without switches, the default value of \"msg\" will be used.
39 
40 m configure modules individually
41 
42 y (in combination with \"m\")
43 configure all modules
44 automatically answers \"Yes\" when asked if module shall be
45 used or displayed. This has nothing to do with the modules'
46 own configuration, it just affects the main setup behaviour.
47 
48 s generate main settings
49 note: if you want to add or remove modules using the \"m\" switch,
50 the \"s\" switch has also to be set to modify the main
51 settings accordingly. In this case the \"y\" swich will
52 automatically activate all available modules!
53 
54 g generate \"rrdgraph\" start/stop scipt
55 
56 ? display this help text.\n\n";
57 exit;
58 }
59 
60if ( (index ($args,"g")<0) && (index ($args,"s")<0) && (index ($args,"m")<0) ) { $args=$args."gsm"; }
61 
62my $RUN="";
63my $SHOW="";
64 
65if ( ! -e "var" ) { mkdir "var",0755; }
66if ( ! -e "var/settings" ) { mkdir "var/settings",0755; }
67if ( ! -e "var/log" ) { mkdir "var/log",0755; }
68if ( ! -e "var/run" ) { mkdir "var/run",0755; }
69if ( ! -e "var/modules" ) { mkdir "var/modules",0755; }
70 
71if ( index($args,"m") >=0 ) { configure_modules(); }
72if ( index($args,"s") >=0 ) { configure_main(); }
73if ( index($args,"g") >=0 ) { write_rrdgraph_script(); }
74 
75if ( -e "settings.new" ) {
76 HotSaNICparser::backup_file("settings");
77 system "mv -f settings.new settings";
78 }
79system "ln -sf ../../settings var/settings/main";
80 
81# build array with all settings files in the "modules" dir
82#
83my @allsettings;
84require File::Find;
85$File::Find::name=""; # suppress stupid warning...
86File::Find::find( {wanted => sub { /^settings\z/s && push @allsettings,$File::Find::name; } }, 'modules');
87 
88for my $item (@allsettings) {
89 chomp $item;
90 my $name;
91 ($name=$item) =~ s/ules\/(.*)\/.*/_$1/g;
92 system "ln -sf ../../$item var/settings/$name\n";
93 }
94 
95print "\nNow adapt all settings files to satisfy your needs.\nThey are all linked to the directory <HotSaNIC_installdir>/var/settings .\n\n";
96exit 0;
97 
98 
99 
100sub write_rrdgraph_script {
101 
102 print "\nWriting start/stop script \"rrdgraph\" ...";
103 
104 open OUT,">rrdgraph";
105 if ( -e "/bin/bash" ) { print OUT "#!/bin/bash\n"; } else { print OUT "#!/usr/bin/env sh\n"; }
106 print OUT "### BEGIN INIT INFO
107# chkconfig: 12345 55 45
108# provides: HotSaNIC
109# Provides: HotSaNIC
110# Default-Start: 2 3 5
111# Default-Stop: 0 1 6
112# description: HotSaNIC system statistics
113# Description: HotSaNIC system statistics
114### END INIT INFO
115 
116cd \"$THISDIR\"
117 
118. ./settings
119 
120case \$1 in
121 start)
122 echo \"Starting rrdtimer...\"
123 ./rrdtimer.pl Dp
124 ;;
125 stop)
126 echo \"Stopping rrdtimer...\"
127 if [ -e \"\$PIDFILE\" ]; then
128 PID=`cat \"\$PIDFILE\"`
129 for nn in \$PID ; do kill \$nn; done
130 else
131 echo \"pid-file not found, rrdtimer not running?!\"
132 fi
133 ./clearall CLEAR_COUNTERS
134 ;;
135 status)
136 if [ -e \$PIDFILE ]; then
137 echo \"main process on PID \`cat \$PIDFILE\` (according to PID-file)\"
138 else
139 echo \"pid-file not found, rrdtimer not running?!\"
140 fi
141 ;;
142 restart)
143 ./rrdgraph stop
144 ./rrdgraph start
145 ;;
146 start_msg|stop_msg)
147 echo \"HotSaNIC system statistics\"
148 ;;
149 *)
150 echo \"usage: rrdgraph [start|stop|status|restart]\"
151 ;;
152 esac
153";
154 close OUT;
155 chmod 0755,"rrdgraph";
156 
157 print" Ok.\n";
158 }
159 
160 
161sub configure_modules {
162 
163 print "Configuring modules:\n";
164 
165 my @mods=HotSaNICparser::scan_for_modules( "./modules", "*" );
166 my @run;
167 my @show;
168 foreach my $dir (@mods) {
169 if ( ($dir eq ".") || ($dir eq "..") || ($dir eq "CVS") ) { next; }
170 my $modname=uc $dir;
171 my $input=$ALLYES;
172 if ($input eq "") {
173 print "\n\nModule found: $modname\n\nDescription:\n";
174 if ( -e "modules/$dir/.description") {
175 open FILE,"modules/$dir/.description";
176 while (<FILE>) { print " $_"; }
177 close FILE;
178 }
179 else { print "(not available)"; }
180 $input=HotSaNICshellio::askyesno("Do you want to use this module","y");
181 }
182 
183 if ($input eq "y") {
184 push @run,lc $modname;
185 $input=$ALLYES;
186 if ($input eq "") {
187 $input=HotSaNICshellio::askyesno("Do you want to show this module's graphs on the webpage","y");
188 }
189 if ($input eq "y") { push @show,lc $modname; }
190 }
191 print "\n----------------------------------------\n";
192 }
193 foreach my $dir (@run) {
194 print "\nsetting up $dir ...\n";
195 if (-e "modules/$dir/setup.pl") { system "cd modules/$dir; ./setup.pl; cd .."; }
196 else { system "cd modules/$dir; ./setup; cd .."; }
197 }
198 $RUN=join " ",@run;
199 $SHOW=join " ",@show;
200 print" Ok.\n";
201 }
202 
203 
204 
205sub configure_main {
206 
207 print "Writing main settings ...\n";
208 
209 my $convertpath;
210 my %VARS;
211 
212 my $file=".settings.default";
213 my $newfile="settings";
214 if ( -e "settings" ) {
215 $newfile="settings.new";
216 my @CONF=HotSaNICparser::read_settings(".");
217 foreach (@CONF) {
218 my ($var,$val)=HotSaNICparser::parse_line($_);
219 $VARS{$var}=$val;
220 }
221 }
222 open FILE,$file;
223 open NEWFILE,">$newfile";
224 
225 while (<FILE>) {
226 chomp;
227 
228 my ($var,$value,$comment)=HotSaNICparser::parse_line($_);
229 
230 if (defined $VARS{$var}) { $value=$VARS{$var}; }
231 if ($var eq "RUN") { if ($RUN ne "") { ($value=$RUN) =~ s/^ *//; } }
232 if ($var eq "SHOW") { if ($SHOW ne "") { ($value=$SHOW) =~ s/^ *//; } }
233 
234 if ( ($value eq "" ) || (lc $value eq "not configured") ) {
235 
236 if ($var eq "DAEMONDIR") {
237 print " checking path to \"rrdtimer.pl\" (current: '$value')\n";
238 if ( -e "$THISDIR/rrdtimer.pl" ) { $value=$THISDIR; }
239 }
240 
241 if ($var eq "BINPATH") {
242 print " checking path to \"rrdtool\" (current: '$value')\n";
243 my @found=HotSaNICparser::locate_files("bin\/rrdtool");
244 if (@found) {
245 foreach my $nn (@found) { $nn=~ s/\/rrdtool$//g; }
246 $value=HotSaNICshellio::choose($value,"rrdtool could not be found. If you already installed it, please edit the settings file.",@found);
247 }
248 }
249 
250 if ($var eq "CONVERTMETHOD") {
251 print " guessing convert method...\n";
252 print " checking for Image::Magick perl module...";
253 eval {
254 require Image::Magick;
255 };
256 if ( $@ ) {
257 print " not found\n";
258 }
259 else {
260 print " found\n";
261 $value="I::M";
262 }
263 
264 print " checking path to \"convert\" from ImageMagick (current: '$value')\n";
265 my @found=HotSaNICparser::locate_files("bin\/convert|grep convert\$");
266 if (@found) {
267 $convertpath=HotSaNICshellio::choose($value,"convert could not be found. If ImageMagick package is already installed, please edit the settings file.",@found);
268 $value="ImgMgck" if ( $value ne "I::M" );
269 }
270 else { $convertpath="not configured"; }
271 if (-f $convertpath) { $convertpath =~ s/\/\w+$//g; }
272 $value="HTML" if ( $value eq "not configured" );
273 }
274 
275 if ($var eq "CONVERTPATH") {
276 if (-x $convertpath) { $convertpath =~ s/\/\w+$//g; }
277 $value=$convertpath;
278 }
279 
280 if ($var eq "SNMPWALK") {
281 print " checking path to \"snmpwalk\" (current: '$value')\n";
282 my @found=HotSaNICparser::locate_files("bin\/snmpwalk");
283 if (@found) {
284 $value=HotSaNICshellio::choose($value,"snmpwalk could not be found. If you already installed it, please edit the settings file.",@found);
285 }
286 }
287 
288 if ($var eq "SNMPGET") {
289 print " checking path to \"snmpget\" (current: '$value')\n";
290 my @found=grep /snmpget$/,HotSaNICparser::locate_files("bin\/snmpget");
291 if (@found) {
292 $value=HotSaNICshellio::choose($value,"snmpget could not be found. If you already installed it, please edit the settings file.",@found);
293 }
294 }
295 
296 if ($var eq "SNMPBULKWALK") {
297 print " checking path to \"snmpbulkwalk\" (current: '$value')\n";
298 my @found=grep /snmpbulkwalk$/,HotSaNICparser::locate_files("bin\/snmpbulkwalk");
299 if (@found) {
300 $value=HotSaNICshellio::choose($value,"snmpbulkwalk could not be found. If you already installed it, please edit the settings file.", @found);
301 }
302 }
303 }
304 
305 if ($var ne "") { print NEWFILE "$var=\"$value\""; print "$var=\"$value\"\n"; }
306 if ($comment ne "") { $comment="" if $comment eq " "; print NEWFILE "#$comment"; }
307 print NEWFILE "\n";
308 
309# if ( ($value ne " ") && ($var !~ /^#/) ) { print "$var=\"$value\"\n"; }
310# } else { $var=""; }
311# if ($value ne " ") { print NEWFILE "$var=\"$value\"\n"; }
312# else { print NEWFILE $var,"\n"; }
313 }
314 close FILE;
315 close NEWFILE;
316 
317 print"\n --- Main settings generated. ---\n";
318 }
319 

Powered by WebSVN 2.2.1