1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | |
3 | | | # $Id: setup.pl,v 1.8 2004/07/12 07:50:15 bernisys Exp $ |
4 | | | |
5 | | | # include PERL libraries |
6 | | | use strict; |
7 | | | use warnings; |
8 | | | use diagnostics; |
9 | | | |
10 | | | # include HotSaNIC libraries |
11 | | | use lib "../../lib"; |
12 | | | use lib "./platform"; |
13 | | | use HotSaNICparser; |
14 | | | use HotSaNICshellio; |
15 | | | use HotSaNIClog; |
16 | | | use common; |
17 | | | |
18 | | | $|=1; |
19 | | | |
20 | | | (my $VERSION = '$Revision: 1.8 $') =~ s/.*(\d+\.\d+).*/$1/; |
21 | | | (my $IDENTIFIER = '$Id: setup.pl,v 1.8 2004/07/12 07:50:15 bernisys Exp $') =~ s/.*,v (.*) \$/$1/; |
22 | | | |
23 | | | my $MODNAME=HotSaNICparser::get_module_name(); |
24 | | | my %MODCONF=HotSaNICmod::common::configure(); |
25 | | | my $OUTFILE="settings.new"; |
26 | | | if ( ! -e "settings" ) { $OUTFILE="settings"; } |
27 | | | open OUTFILE,">$OUTFILE" || die "could not open ".HotSaNICparser::get_module_name()." settings file for writing.\n"; |
28 | | | |
29 | | | if (! @{$MODCONF{DRIVE}}) { @{$MODCONF{DRIVE}}=get_drives(); } |
30 | | | if (@{$MODCONF{DRIVE}}) { $MODCONF{DRIVE}="DRIVE=\"".join("\"\nDRIVE=\"",@{$MODCONF{DRIVE}})."\""; } |
31 | | | else { $MODCONF{DRIVE}=""; } |
32 | | | |
33 | | | print OUTFILE "# SHORT DESCRIPTION |
34 | | | # |
35 | | | # You may configure partitions you would like to monitor. |
36 | | | # multiple lines are of course allowed. |
37 | | | # |
38 | | | # for a local drive enter: |
39 | | | # DRIVE=<device>,<description> |
40 | | | # |
41 | | | # for a remote (e.g. NFS or SNMP) drive enter: |
42 | | | # DRIVE=<server>:<path>,<description> |
43 | | | # DRIVE=SNMP:<host>:<community>:<device>,<description> |
44 | | | # |
45 | | | # Note: Make sure you have no '_' in host or community |
46 | | | # when using SNMP. |
47 | | | # |
48 | | | $MODCONF{DRIVE} |
49 | | | "; |
50 | | | |
51 | | | close OUTFILE; |
52 | | | |
53 | | | if ($OUTFILE eq "settings.new") { |
54 | | | HotSaNICparser::backup_file("settings"); |
55 | | | rename "settings.new","settings"; |
56 | | | } |
57 | | | |
58 | | | print "Please check the settings file and adapt it to satisfy your needs.\n"; |
59 | | | |
60 | | | sub get_drives { |
61 | | | my @drives=(); |
62 | | | open RESULT,"df -a|"; |
63 | | | $_=<RESULT>; #strip header line |
64 | | | my $lastfs=""; |
65 | | | while (<RESULT>) { |
66 | | | chomp; |
67 | | | my($fs,$size,undef,undef,$mp1,$mountpoint)=split; |
68 | | | if (!defined $mountpoint) { |
69 | | | if (!defined $mp1) { $lastfs=$fs; next; } |
70 | | | else { $size=$fs; $fs=$lastfs; $mountpoint=$mp1; } |
71 | | | } |
72 | | | if ( ($fs ne "none") and ($size > 0) ) { |
73 | | | $mountpoint ="root filesystem" if $mountpoint eq "/"; |
74 | | | my $result=HotSaNICshellio::askyesno("Use \"$fs\", mounted on \"$mountpoint\"","n"); |
75 | | | push @drives,"$fs,$mountpoint" if $result eq "y"; |
76 | | | } |
77 | | | } |
78 | | | close RESULT; |
79 | | | return @drives; |
80 | | | } |
81 | | | |