summaryrefslogtreecommitdiff
path: root/machine-update-beta
diff options
context:
space:
mode:
Diffstat (limited to 'machine-update-beta')
-rwxr-xr-xmachine-update-beta253
1 files changed, 96 insertions, 157 deletions
diff --git a/machine-update-beta b/machine-update-beta
index 6a4db3e..8c1770f 100755
--- a/machine-update-beta
+++ b/machine-update-beta
@@ -14,23 +14,13 @@
use strict;
use POSIX;
-our $VERSION = '0.20';
-our $CVS_VERSION = '$Revision: 1.1 $ $Date: 2005-03-11 16:57:22 $ $Author: jonas $';
+our $VERSION = '0.25';
+our $CVS_VERSION = '$Revision: 1.2 $ $Date: 2006-02-06 18:54:04 $ $Author: jonas $';
our $IsInTestHarness;
-use vars qw(%values %oldvalues $errordata $debugdata); # data that is sent
+use vars qw(%values %oldvalues $errordata $debugdata %files); # data that is sent
use vars qw($progname %option);
use vars qw(%is_sys_account %is_user %is_account);
-# Some variables are for internal use, and never prompted for in
-# the loop of askquestions
-our %dontask = ('uniqueid' => 1, # Internal use
- 'manual' => 1,
- 'method' => 1,
- 'owner' => 1, # These 2 are always prompted for
- 'key' => 1,
- 'uptime' => 1, # We think we know how to get these
- );
-
# stuff that controls defaults for passwdscan & accounts subroutines
my ($UID_MIN, $UID_MAX, $got_defs) = (100, 65533, '');
@@ -46,8 +36,6 @@ return 1 if($IsInTestHarness);
if ($option{ask}) {
&askquestions;
-} else {
- &copymanuals;
}
&writefile;
@@ -59,6 +47,16 @@ if ($option{ask}) {
sub preparation {
die "No HOME environment variable\n" if (!$ENV{HOME});
die "No home diretory\n" if ! -d $ENV{HOME};
+ # Kill some internationalization
+ $ENV{LANG} = 'C';
+ delete $ENV{LC_CTYPE};
+ delete $ENV{LC_NUMERIC};
+ delete $ENV{LC_NAME};
+ delete $ENV{LC_TIME};
+ delete $ENV{LC_MESSAGES};
+ delete $ENV{LC_COLLATE};
+ delete $ENV{LC_MONETARY};
+
my $infodir = "$ENV{HOME}/.linuxcounter";
if (! -d $infodir) {
mkdir($infodir, 0766) || die "Unable to make $infodir\n";
@@ -120,30 +118,6 @@ sub askquestions {
print "Here you can specify some info that the script can't know for itself\n";
$values{owner} = askone("Your Linux Counter reg#, if any", $values{owner});
$values{key} = askone("Your machine's counter reg#, if any", $values{key});
- print "Here is what the program has found:\n";
- for my $key (keys(%values)) {
- if (!$dontask{$key}) {
- printf "%-10s%1s: %s\n", $key, $dontask{$key}?"*":" ", $values{$key};
- }
- }
- my $domore = &askone('Do you want to override some of the found values?', 'no');
- if ($domore =~ /^Y/i) {
- my $manual;
- for my $key (keys(%values)) {
- next if $dontask{$key};
- my $value = &askone($key, $oldvalues{$key}, $values{$key});
- if ($values{$key} eq $value) { # go to automatic
- &Debug("auto value: $key\n");
- } else {
- &Debug("still manual value: $key\n");
- $manual .= " $key";
- }
- $values{$key} = $value;
- }
- $values{manual} = $manual;
- } else {
- delete $values{manual};
- }
}
# }}}
@@ -152,18 +126,11 @@ sub askquestions {
sub askone {
my $prompt = shift;
my $default = shift;
- my $probed = shift;
print $prompt;
- if (!defined($default) && defined($probed)) {
- $default = $probed;
- }
if (defined($default)) {
print " [$default]";
}
- if (defined($probed) && $probed ne $default) {
- print "(program found $probed)";
- }
print ':';
my $ans = <STDIN>;
@@ -176,21 +143,6 @@ sub askone {
}
# }}}
-# {{{ copymanuals
-#
-sub copymanuals {
- my %keeps;
- if ($values{manual}) {
- %keeps = map {$_ => 1} split(' ', $values{manual});
- }
-
- &Debug('Keeping '.join(' ', keys(%keeps))."\n");
- for my $key (keys(%keeps)) {
- $values{$key} = $oldvalues{$key};
- }
-}
-# }}}
-
# {{{ readfile
#
@@ -201,8 +153,13 @@ sub readfile {
chop;
s/#.*//;
if (/^(\S+): *(.+)/) {
- &Debug("Read $1: $2\n");
- $values{$1} = $2;
+ my $key = $1;
+ my $value = $2;
+ if ($1 !~ /^(owner|key|uniqueid)$/) {
+ next;
+ }
+ &Debug("Read $key: $value\n");
+ $values{$key} = $value;
} else {
print STDERR "Unparsed info line: $_ - discarded\n";
}
@@ -258,6 +215,14 @@ EOF
if length($values{$val}) > 0;
}
print MAIL "//END\n";
+ # Attach files
+ for my $file (keys(%files)) {
+ print MAIL "//FILE $file\n";
+ print MAIL $files{$file};
+ print MAIL "//EOF\n";
+ }
+
+
# Attach possible other info
if ($errordata) {
print MAIL "----- Problem info gathered during probing -----\n";
@@ -298,31 +263,25 @@ sub checkconfig {
# Note - there are numerous problems with df, including:
# - early versions don't support the -l option
# - at least some include SAMBA filesystems in the -l option
- open (TMP,"df -l -x shm |"); # exclude shmfs, its 50% of RAM (mostly)
- my $HD = 0;
- while (<TMP>) {
- my @line = split(/\s+/);
- ($line[0] =~ /\/dev/) && ($HD += $line[1]);
- }
- &Debug("$HD kbytes of disk found\n");
- $HD /= 1024;
- $values{disk} = sprintf("%d", $HD);
+ # 1: Snarf a df -T
+ my $dfbin = &xbin("df");
+ $files{"df -T"} = `$dfbin -T -x nfs`;
+
$values{accounts} = &accounts;
$values{users} = &active_users;
my $uptime = &xbin('uptime');
if($uptime) {
$uptime = `$uptime`;
- # get the uptime string here (could be more elegant, but so it is
- # robust against various localizations)
- if ($uptime =~ /^\s+[^\s]+\s+[^\s]+\s+([^,]+), /) {
- $values{uptime} = $1;
- } else {
- &ErrorInfo("Can't parse uptime output: $uptime\n");
- }
- if ($option{info}) {
- &DebugInfo("***** Uptime output *****\n$uptime");
- }
+ $values{uptime_1} = $uptime; # preserve raw version
+ $values{uptime_1} =~ s/\n.*//;
+ }
+ my $lastprog = xbin('last');
+ if ($lastprog && -r "/var/run/utmp") {
+ $values{uptime_2} = `$lastprog -xf /var/run/utmp runlevel`;
+ $values{uptime_2} =~ s/\n.*$//s;
+ } else {
+ DebugInfo("Can't do last to find uptime");
}
# Not sure this is a Right Thing...so not saving it for the moment
# This section based on a patch from Mark-Jason Dominus <mjd@plover.com>
@@ -346,83 +305,23 @@ sub checkconfig {
if (!$values{mailer}) {
if ( -d '/var/qmail') {
$values{mailer} = 'qmail';
- } elsif ( -f '/etc/sendmail.cf') {
+ } elsif ( -f '/etc/sendmail.cf' || -f '/etc/mail/sendmail.cf') {
+ # TMDG claims recent Fedora Core has it in /etc/mail/sendmail.cf
$values{mailer} = 'sendmail';
} elsif ( -d '/etc/postfix') {
$values{mailer} = 'postfix';
}
}
- # forget about /proc/kcore: It's not reliable above 960MB. It also doesn't show
- # real memory, because some may be eaten by graphics
- # forget also about the "free" command: We don't want to be dependant on that
- $values{memory} = int(&getval_from_file('/proc/meminfo',1,1) / (1024*1024));
- # But actually: Shouldn't we return the total of virtual memory here? Seems to
- # be relevant to me - RJ -
-
- &cpuinfo;
-}
-
-# }}}
-
-# {{{ cpuinfo
-
-#
-sub cpuinfo {
- my $cpufile = '/proc/cpuinfo'; # Linux: Place to get info on CPU
- my %interesting = (# 2.0 and 2.2 kernels
- 'bogomips' => '+bogomips',
- 'processor' => '1+processors',
- 'vendor_id' => 'cpu_vendor',
- # 2.0 kernels
- 'cpu' => 'cpu_only',
- 'model' => 'cpu_model',
- 'model name' => 'cpu_model_name',
- # 2.2 kernels
- 'cpu MHz' => 'cpu_mhz',
- 'cpu family' => 'cpu_family',
- # from an Alpha processor
- 'cycle frequency [Hz]' => 'cpu_hz',
- 'BogoMIPS' => '+bogomips',
- 'cpu model' => 'cpu_model',
- 'system type' => 'cpu_system_type',
- 'cpus detected' => 'processors',
- # from a PowerMAC
- 'machine' => 'cpu_machine',
- 'clock' => 'cpu_clock',
- 'motherboard' => 'cpu_motherboard',
- # from an UltraSparc
- 'BogoMips' => '+bogomips',
- 'ncpus active' => 'processors',
- );
-
- # Zero out the accumulative values
- $values{bogomips} = 0;
- $values{processors} = 0;
- if (open (TMP,"<$cpufile")) {
- &DebugInfo("**** Contents of $cpufile ****\n");
- while (<TMP>) {
- &DebugInfo($_); # Save /proc/cpuinfo to debugdata if -d
- chop;
- # A bizarre selection of names are "interesting".
- # Make a data-driven pick routine
- if (/^(\S+[^:]+\S)\s+: /) {
- my $name = $1;
- my $value = $';
- if ($interesting{$name}) {
- if ($interesting{$name} =~ /^\+/) {
- $values{$'} += $value;
- } elsif ($interesting{$name} =~ /^1\+/) {
- $values{$'}++;
- } else {
- $values{$interesting{$name}} = $value;
- }
- }
- }
- }
- } else {
- &ErrorInfo("Could not open $cpufile\n");
- }
+ $values{kcoresize} = -s "/proc/kcore";
+ addonefileforsending("/proc/meminfo");
+ addonefileforsending("/proc/cpuinfo");
+ addonefileforsending("/proc/version");
+ # info on what devices are in use on the system
+ addonefileforsending("/proc/pci");
+ addonefileforsending("/proc/bus/usb/devices");
+ # Both Mandrake and Red Hat use this file....
+ addonefileforsending("/etc/redhat-release");
}
# }}}
@@ -572,7 +471,7 @@ sub installcrontab {
my $hour = int(rand(24));
my $min = int(rand(60));
my $day = int(rand(7)); # Weekday. This version runs once a week.
- my $cron;
+ my $cron = "";
warn "Installing start of script into your crontab\n";
if (open(CRON, "crontab -l |")) {
@@ -691,7 +590,7 @@ EoF
sub xbin {
my $bin = shift; # get name of binary to execute
- $bin = `which $bin`; # determine binarys full path
+ $bin = `which $bin 2>/dev/null`; # determine binarys full path
chomp $bin;
return $bin if(-x $bin); # if there and executable: all is well - return it
@@ -730,6 +629,21 @@ sub getval_from_file {
# }}}
+sub addonefileforsending {
+ my $file = shift;
+ my @file;
+
+ if (!(-r $file)) {
+ &DebugErr("File $file not readable\n");
+ return '';
+ }
+ sysopen(FH,$file, O_RDONLY);
+ @file = <FH>; # read whole file to array
+ close FH;
+ $files{$file} = join('', @file);
+
+}
+
# {{{ Debug print debug information if flag is set
#
@@ -782,7 +696,7 @@ SWITCHES:
-c = install crontab entry
-u = uninstall crontab entry
-h = print usage information and exit
-If called interactively, will ask some questions and store the
+If called with the "-i" option, will ask some questions and store the
answers in $ENV{HOME}/.linuxcounter/$host
EoF
@@ -799,7 +713,7 @@ sub license {
Linux Counter Machine Update version $VERSION
- Copyright (C) 1999 Harald Tveit Alvestrand
+ Copyright (C) 1999-2005 Harald Tveit Alvestrand
2003 PetaMem Group (www.petamem.com)
This program is free software; you can redistribute it and/or modify
@@ -1113,5 +1027,30 @@ EoF
# - Memory size detection now robst and >960MB capable
# - slightly better randomness
#
+
+# Changelog 0.21
+# - added attaching of files
+# - added fetching of uptime_1 and uptime_2
+#
+# Changelog 0.22
+# - removed "manual" copying of entries
+# - added suppressing error messages from "xbin" calling "which"
+# - suppressed NFS from "df -T" listing
+#
+# Changelog 0.23
+# - added sending /proc/pci
+# - removed client-side parsing of DF output and uptime
+#
+# Changelog 0.24
+# - added sending /proc/version (inspired by klive)
+# - changed fetching of old data from "all" to "needed"
+# - removed CPU-parsing code
+# - fixed warning (harmless) from crontab creation
+# - added sending /proc/bus/usb/devices
+#
+# Changelog 0.25
+# - added sending size of /proc/kcore
+# - removed computation of memory client-side
+#
#vim:ts=8:sw=4:sts=4