#!/usr/bin/perl -w
# Program to update system/SYSINFO.TXT
# Written by Martin Thomson for Daleken 1.12.
$file = '../data/SYSINFO.TXT';
$bak = '~';
print STDOUT "Checking configuration file: $file\n";
print STDOUT "Checking for the existence of ispell/aspell and fortune\n";
print STDOUT "Ensure your PATH variable is correctly set.\n";
print STDOUT "---\n";
rename( $file, $file . $bak );
open (SYSINFO, "<$file$bak")
or die "Can't open SYSINFO input file!";
open (OUTPUT, ">$file")
or die "Can't open SYSINFO output file!";
select (OUTPUT);
while(<SYSINFO>) {
# Strip comments and save them for later.
if( /(\s*#.*)$/ ) {
$comment = "$1";
} else {
$comment = "";
};
s/(\s*#.*)$//g;
SWITCH: {
/^Platform/ && do {
local $machine = "\"".`uname -s`."-".`uname -m`."\";";
$machine =~ s/\n//g;
s/^(Platform\s+)\".+\";$/$1.$machine/e;
last SWITCH;
};
/^Flags/ && do {
local $flags = "(verbose reboot";
if( system( "aspell --version >/dev/null 2>&1" ) == 0 ) {
print STDOUT "Found aspell.\n";
$flags .= " ispell";
} elsif( system( "ispell -v >/dev/null 2>&1" ) == 0 ) {
print STDOUT "Found ispell.\n";
$flags .= " ispell";
};
if( system( "fortune -s > /dev/null 2>&1" ) == 0 ) {
print STDOUT "Found fortune.\n";
$flags .= " fortunes";
};
$flags .= ");";
s/^(Flags\s+)\(.+\);$/$1.$flags/e;
};
};
# Strip end of lines from $_ then print the result, with appended comment
chop; # strip ending "\n"
print ($_,$comment,"\n");
};
close (SYSINFO);
close (OUTPUT);
select (STDOUT);
unlink($file . $bak);
exit;