Rework set-sysconf not to require Sys::Sysconf
Used a module not in the base Perl install; we fork to "logger" instead.
This commit is contained in:
parent
c9e493a243
commit
8ae45e43de
32
set-sysconf
32
set-sysconf
|
@ -3,7 +3,6 @@ use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use IO::File;
|
use IO::File;
|
||||||
use IO::Pipe;
|
use IO::Pipe;
|
||||||
use Sys::Syslog qw(:standard);
|
|
||||||
use feature 'switch';
|
use feature 'switch';
|
||||||
|
|
||||||
my ($filename, $fh, %conf);
|
my ($filename, $fh, %conf);
|
||||||
|
@ -11,29 +10,40 @@ my ($filename, $fh, %conf);
|
||||||
$filename = '/boot/firmware/sysconf.txt';
|
$filename = '/boot/firmware/sysconf.txt';
|
||||||
exit 0 unless -f $filename;
|
exit 0 unless -f $filename;
|
||||||
|
|
||||||
openlog('sysconf', 'ndelay', 'LOG_DAEMON');
|
logger('info', "Applying the system configuration settings in $filename");
|
||||||
syslog('info', 'Applying the system configuration settings in /boot/firmware');
|
|
||||||
END { closelog(); }
|
|
||||||
|
|
||||||
$fh = IO::File->new($filename, 'r');
|
$fh = IO::File->new($filename, 'r');
|
||||||
while (my $line = $fh->readline) {
|
while (my $line = $fh->getline) {
|
||||||
my ($key, $value);
|
my ($key, $value);
|
||||||
# Allow for comments, and properly ignore them
|
# Allow for comments, and properly ignore them
|
||||||
$line =~ s/#.+//;
|
$line =~ s/#.+//;
|
||||||
if ( ($key, $value) = ($line =~ m/^\s*([^=]+)\s*=\s*(.*)\s*$/)) {
|
if ( ($key, $value) = ($line =~ m/^\s*([^=]+)\s*=\s*(.*)\s*$/)) {
|
||||||
$key = lc($key);
|
$key = lc($key);
|
||||||
if (exists($conf{$key})) {
|
if (exists($conf{$key})) {
|
||||||
syslog('warn', "Repeated configuration key: $key. Overwriting with new value ($value)");
|
logger('warn',
|
||||||
|
"Repeated configuration key: $key. " .
|
||||||
|
"Overwriting with new value ($value)");
|
||||||
}
|
}
|
||||||
$conf{$key} = $value;
|
$conf{$key} = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (my $pass = $conf{root_pw}) {
|
if (my $pass = delete($conf{root_pw})) {
|
||||||
my $pipe = IO::Pipe->new();
|
my $pipe;
|
||||||
$pipe->writer('/bin/passwd root');
|
open($pipe, '|-', '/usr/sbin/chpasswd') or die $!;
|
||||||
print $pipe $pass;
|
print $pipe "root:$pass";
|
||||||
print $pipe $pass;
|
close($pipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scalar keys %conf) {
|
||||||
|
logger('warn', 'Unprocessed keys left in $filename: ' .
|
||||||
|
join(', ', sort keys %conf));
|
||||||
|
}
|
||||||
|
|
||||||
|
exit 0;
|
||||||
|
|
||||||
|
sub logger {
|
||||||
|
my ($prio, $msg) = @_;
|
||||||
|
system('/bin/logger', '-p', "daemon.$prio",
|
||||||
|
'-t', 'set-sysconf', $msg);
|
||||||
|
}
|
||||||
|
|
|
@ -16,4 +16,4 @@
|
||||||
|
|
||||||
# root_pw - Set a password for the root user (by default, it allows
|
# root_pw - Set a password for the root user (by default, it allows
|
||||||
# for a passwordless login)
|
# for a passwordless login)
|
||||||
#rootpw=FooBar
|
#root_pw=FooBar
|
||||||
|
|
Loading…
Reference in New Issue