summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Wolf <gwolf@gwolf.org>2019-07-19 11:34:17 -0300
committerGunnar Wolf <gwolf@gwolf.org>2019-07-19 11:34:17 -0300
commit8ae45e43de6e138d755b713a8f3ca1d1311d0054 (patch)
treed8ce0c9bd840c9b7e887c1b8ab5e249af7b758fa
parentc9e493a243ca3ec9c1c12611620bb26e55e63cfc (diff)
Rework set-sysconf not to require Sys::Sysconf
Used a module not in the base Perl install; we fork to "logger" instead.
-rw-r--r--set-sysconf32
-rw-r--r--sysconf.txt2
2 files changed, 22 insertions, 12 deletions
diff --git a/set-sysconf b/set-sysconf
index a27e800..132d7b3 100644
--- a/set-sysconf
+++ b/set-sysconf
@@ -3,7 +3,6 @@ use strict;
use warnings;
use IO::File;
use IO::Pipe;
-use Sys::Syslog qw(:standard);
use feature 'switch';
my ($filename, $fh, %conf);
@@ -11,29 +10,40 @@ my ($filename, $fh, %conf);
$filename = '/boot/firmware/sysconf.txt';
exit 0 unless -f $filename;
-openlog('sysconf', 'ndelay', 'LOG_DAEMON');
-syslog('info', 'Applying the system configuration settings in /boot/firmware');
-END { closelog(); }
+logger('info', "Applying the system configuration settings in $filename");
$fh = IO::File->new($filename, 'r');
-while (my $line = $fh->readline) {
+while (my $line = $fh->getline) {
my ($key, $value);
# Allow for comments, and properly ignore them
$line =~ s/#.+//;
if ( ($key, $value) = ($line =~ m/^\s*([^=]+)\s*=\s*(.*)\s*$/)) {
$key = lc($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;
}
}
-if (my $pass = $conf{root_pw}) {
- my $pipe = IO::Pipe->new();
- $pipe->writer('/bin/passwd root');
- print $pipe $pass;
- print $pipe $pass;
+if (my $pass = delete($conf{root_pw})) {
+ my $pipe;
+ open($pipe, '|-', '/usr/sbin/chpasswd') or die $!;
+ print $pipe "root:$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);
+}
diff --git a/sysconf.txt b/sysconf.txt
index 89ca53f..c3dd255 100644
--- a/sysconf.txt
+++ b/sysconf.txt
@@ -16,4 +16,4 @@
# root_pw - Set a password for the root user (by default, it allows
# for a passwordless login)
-#rootpw=FooBar
+#root_pw=FooBar