/[fai]/trunk/share/Fai.pm
ViewVC logotype

Contents of /trunk/share/Fai.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1639 - (show annotations) (download)
Tue Feb 4 16:35:40 2003 UTC (10 years, 4 months ago) by lange
File size: 3582 byte(s)
call disk-info to get size of all disks
1 #! /usr/bin/perl
2
3 # $Id$
4 #*********************************************************************
5 #
6 # Fai.pm -- subroutines used by /fai/class/S*.pl scripts
7 #
8 # This script is part of FAI (Fully Automatic Installation)
9 # Copyright (c) 1999-2001 by Thomas Lange, Universitaet zu Koeln
10 #
11 #*********************************************************************
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; see the file COPYING. If not, write to the
24 # Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 # MA 02111-1307, USA.
26 #*********************************************************************
27
28 $hostname = $ENV{'HOSTNAME'};
29
30 # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 sub read_all_info () {
32 read_disk_info;
33 read_memory_info;
34 read_kernel_messages;
35 }
36 # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 sub classes {
38
39 # print a list of classes
40 my @strings = @_;
41 foreach (@strings) {
42 print "$_\n";
43 }
44 }
45 # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46 sub class {
47
48 # print a list of classes and exit
49 classes(@_);
50 exit;
51 }
52 # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53 sub testsize {
54
55 # test if value is within a range
56 # return 1 if size within range
57
58 my ($value,$lower,$upper) = @_;
59 return 1 if ($lower < $value && $value <= $upper);
60 return 0;
61 }
62 # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 sub read_disk_info {
64
65 # disk_info set variables containing the information
66
67 my ($size,$bytes_per_block,$diskandsize);
68 $bytes_per_block= 1024; # should be constant for /proc/partitions; must be proofed!
69
70 #
71 $diskandsize = `disk-info`;
72 while ($diskandsize=~ /(\S+)\s+(\d+)/g) {
73 my ($device,$blocks) = ($1,$2);
74 $numdisks++;
75 push @devicelist,$device;
76 $blocks{$device} = $blocks;
77 $size = $blocks{$device} * $bytes_per_block / (1024*1024) ;
78 $sum_disk_size += $size;
79 $disksize{$device} = $size;
80 }
81 }
82 # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83 sub disksize {
84
85 my ($disk,$lower,$upper) = @_;
86 testsize($disksize{$disk},$lower,$upper);
87 }
88 # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89 sub read_memory_info {
90
91 $size = -s "/proc/kcore";
92 $size -=4*1024; # man 5 proc says that kcore is phys. mem + 4KB
93 $size /=(1024*1024); # return RAM in MB
94 }
95
96 sub memsize {
97
98 my ($lower,$upper) = @_;
99 testsize($ramsize,$lower,$upper);
100 }
101 # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102 sub read_kernel_messages {
103
104 open (DMESG, "dmesg|");
105 @dmesg =<DMESG>;
106 close DMESG;
107
108 # /var/log/messages* are not available during first installation
109 return if -f "/tmp/FAI_INSTALLATION_IN_PROGRESS";
110 open (LOGS,"gzip -dcf /var/log/messages*|");
111 @messages =<LOGS>;
112 close LOGS;
113 }
114 # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
115 sub read_ethernet_info {
116
117 read_kernel_messages();
118
119 # return map { m!\beth\d+:(.+)!} (@dmesg,@messages);
120 # some driver don't print eth0:
121 # so now we use:
122
123 return (@dmesg,@messages);
124 }
125 # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126 1;

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5