Skip to content

Commit 043dc2f

Browse files
AlienResidentsdparrish
authored andcommitted
adding /etc/os-release for os detection, at least for debian, arch, and raspberry pi
added ipv6 support for motd messages, and logging messages
1 parent ea81179 commit 043dc2f

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

steps/970-motd

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/perl -w
22
# vim:tw=100 sw=2 expandtab ft=perl
3+
use POSIX qw( ttyname );
4+
use Socket qw( getaddrinfo getnameinfo );
5+
36
=head1 NAME
47
58
970-motd
@@ -44,15 +47,17 @@ validate_config {
4447

4548
my $text = `uname -a`;
4649

47-
my($host, $port) = ($ENV{SSH_CLIENT} || "console", "");
48-
if ($host =~ /(?:::ffff:)?(\d+\.\d+\.\d+\.\d+)\s+(\d+)\s+\d+/) {
49-
$host = $1 || "127.0.0.1";
50-
$port = $2 || 0;
51-
my $x = `host $host` || "";
52-
$host = $1 if $x =~ /domain name pointer (.*)\./;
50+
51+
my($src, $srcport, $sshport) = split(/\s/, $ENV{SSH_CLIENT}) if $ENV{SSH_CLIENT};
52+
$src ||= POSIX::ttyname(1);
53+
# $src will be blank if coming from cron.
54+
$src ||= "cron";
55+
if ($src =~ /(?:::ffff:)?(\d+\.\d+\.\d+\.\d+)\s+(\d+)\s+\d+/) {
56+
my ($error, @src_info) = getaddrinfo($src, 0);
57+
($error, $src) = getnameinfo($src_info[0]->{addr});
5358
}
5459

55-
$text .= "\nUpdated by rollout at ". localtime(time). " from $host\n\n".
56-
join("\n", flatten_list(c("$hostname/motd")));
60+
$text .= "\nUpdated by rollout at ". localtime(time). " from $src";
61+
$text .= "\n\n". join("\n", flatten_list(c("$hostname/motd")));
5762

5863
text_install("/etc/motd", $text);

steps/999-complete

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/perl -w
22
# vim:tw=100 sw=2 expandtab ft=perl
3+
use POSIX qw( ttyname );
4+
use Socket qw( getaddrinfo getnameinfo );
5+
36
=head1 NAME
47
58
999-complete
@@ -54,19 +57,20 @@ if (!$safe_mode) {
5457
my $fn = c("$hostname/rollout/logfile");
5558
if ($fn && (my $fh = new IO::File ">>$fn"))
5659
{
57-
my($host, $port) = ($ENV{SSH_CLIENT} || "console", "");
58-
if ($host =~ /(?:::ffff:)?(\d+\.\d+\.\d+\.\d+)\s+(\d+)\s+\d+/) {
59-
$host = $1 || "127.0.0.1";
60-
$port = $2 || 0;
61-
my $x = `host $host` || "";
62-
$host = $1 if $x =~ /domain name pointer (.*)\./;
60+
my($src, $srcport, $sshport) = split(/\s/, $ENV{SSH_CLIENT}) if $ENV{SSH_CLIENT};
61+
$src ||= POSIX::ttyname(1);
62+
# $src will be blank if coming from cron.
63+
$src ||= "cron";
64+
if ($src =~ /(?:::ffff:)?(\d+\.\d+\.\d+\.\d+)\s+(\d+)\s+\d+/) {
65+
my ($error, @src_info) = getaddrinfo($src, 0);
66+
($error, $src) = getnameinfo($src_info[0]->{addr});
6367
}
6468

6569
print $fh "-------------------------------------------------\n";
6670
print $fh "START: ". localtime($start_time). "\n";
6771
print $fh "DURATION: $duration\n";
6872
print $fh "COMMENT: $rollout_comment\n";
69-
print $fh "FROM: $host $port\n";
73+
print $fh "FROM: $src\n";
7074
print $fh "HOSTNAME: $hostname\n";
7175
print $fh "\n$log\n";
7276
print $fh "\n";

0 commit comments

Comments
 (0)