summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Wolf <gwolf@gwolf.org>2019-07-19 00:54:47 -0300
committerGunnar Wolf <gwolf@gwolf.org>2019-07-19 00:54:47 -0300
commita14e98636655cba28df247fa35f25b9c636daf63 (patch)
tree647883c40164873e160a65386baa45eff453cc3e
parent478a8253cf7cfcaca3472ea0fab3b972efb0c90d (diff)
First sketch of a sysconfig-parser
-rw-r--r--set-sysconf39
-rw-r--r--set-sysconf.service9
2 files changed, 48 insertions, 0 deletions
diff --git a/set-sysconf b/set-sysconf
new file mode 100644
index 0000000..a27e800
--- /dev/null
+++ b/set-sysconf
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use IO::File;
+use IO::Pipe;
+use Sys::Syslog qw(:standard);
+use feature 'switch';
+
+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(); }
+
+$fh = IO::File->new($filename, 'r');
+while (my $line = $fh->readline) {
+ 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)");
+ }
+ $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;
+}
+
+
diff --git a/set-sysconf.service b/set-sysconf.service
new file mode 100644
index 0000000..4854ed9
--- /dev/null
+++ b/set-sysconf.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Set up system configuration
+
+[Service]
+Type=oneshot
+ExecStart=/usr/sbin/set-sysconf
+
+[Install]
+RequiredBy=basic.target