From 6af4c947e9a0d34b2814b8f0b3e5deae1ae880d0 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Wed, 21 Feb 2018 15:12:42 +0100 Subject: [PATCH 1/2] Put `mkmotd.pl` under version control ``` $ ls -l --full-time /usr/sbin/mkmotd.pl /etc/systemd/system/motd.service -rw-r--r-- 1 root system 142 2013-04-18 15:59:36.000000000 +0200 /etc/systemd/system/motd.service -rwxr-xr-x 1 root system 4964 2018-02-21 15:06:46.000000000 +0100 /usr/sbin/mkmotd.pl ``` --- install.sh | 2 + mkmotd/mkmotd.pl | 197 ++++++++++++++++++++++++++++++++++++++++++++ mkmotd/motd.service | 11 +++ 3 files changed, 210 insertions(+) create mode 100755 mkmotd/mkmotd.pl create mode 100644 mkmotd/motd.service diff --git a/install.sh b/install.sh index 1cb0795..dc9fb73 100755 --- a/install.sh +++ b/install.sh @@ -82,6 +82,8 @@ install_exec make-automaps/make-automaps "$DESTDIR$usr_sbindir/make-aut install_data misc_systemd_units/automount.service "$DESTDIR$systemdunitdir/automount.service" install_data misc_systemd_units/gdm.service "$DESTDIR$systemdunitdir/gdm.service" install_data misc_systemd_units/lazy-umount-nfs.service "$DESTDIR$systemdunitdir/lazy-umount-nfs.service" +install_exec mkmotd/mkmotd.pl "$DESTDIR$usr_sbindir/mkmotd.pl" +install_data mkmotd/motd.service "$DESTDIR$systemdunitdir/motd.service" install_exec mxgrub/mxgrub "$DESTDIR$usr_sbindir/mxgrub" install_exec mxnetctl/mxnetctl "$DESTDIR$usr_sbindir/mxnetctl" install_exec mxrouter/mxrouterctl "$DESTDIR$usr_sbindir/mxrouterctl" diff --git a/mkmotd/mkmotd.pl b/mkmotd/mkmotd.pl new file mode 100755 index 0000000..83bfbb3 --- /dev/null +++ b/mkmotd/mkmotd.pl @@ -0,0 +1,197 @@ +#! /usr/bin/perl +use strict; +use warnings; + +# +# Mutter: /project/admin/linux/mkmotd.pl +# + +if ($ARGV[0] and $ARGV[0] eq 'u') { + print `cp -v /project/admin/linux/mkmotd.pl /usr/sbin`; + print "update done.\n"; + exit; +} + + +my ($os_release)=`/bin/os-release`;chomp($os_release); + +our $TEMPLATE; + +if ($os_release eq 'mariux_x86_64' || $os_release eq 'mariux_i686') { + $TEMPLATE=<<'EOF'; + + # # ### # # %HOST% + ## ## ## ##### # # # # # + # # # # # # # # # # # # # cpu %NCPU%x %CPU% + # # # # # # # # # # # ram %MEM% + # # ###### ##### # # # # # arch %ARCH% / %BITS%-bit + # # # # # # # # # # # glibc %GLIBC% + # # # # # # ### #### # # kernel %KERNEL% + + beyond the return of the next followed generation + + http://twiki.molgen.mpg.de/twiki/bin/view/Edv/MarIuXNews + +EOF +} elsif ($os_release eq 'mariux64') { + $TEMPLATE=<<'EOF'; + + # # ### # # %HOST% + ## ## ## ##### # # # # # system %SYSTEM% + # # # # # # # # # # # # # cpu %NCPU%x %CPU% + # # # # # # # # # # # 64 ram %MEM% + # # ###### ##### # # # # # arch %ARCH% / %BITS%-bit + # # # # # # # # # # # glibc %GLIBC% + # # # # # # ### #### # # kernel %KERNEL% + +EOF + +$TEMPLATE.=" / to bee or not to bee / "; + +if ( -d '/node/tags' ) { + $_=`ls /node/tags`;s/\n/ /g; + $TEMPLATE.="tags: $_"; +} + +$TEMPLATE.="\n"; + +} else { + die "$os_release : unknown os_release\n"; +} + +sub readstr { + my $f = shift; + if ( -e $f ) { + open I,'<',$f or die "cannot readstr $f: $!"; + my $str = ; + chomp ($str); + close I; + return $str; + } + return undef; +} + +sub policy { # policy('theinternet') --> ('zeile1,'zeile2',....) + my ($hostname)=@_; + + open IN,'<','/etc/mxpolicy' or return (); + while () { + if (/^\S/ && /\b$hostname\b/) { + my @out; + while () { + /^\S/ and last; + /\s+\*\s*(.+)/ and push @out,$1; + if (/\s+\`\s*(.+)/) { + my $x = `$1`;chomp($x); + push @out,split(/\n/,$x); + } + } + return @out; + } + } + return (); +} + + +my %T; + +my @un = split(/ /,`uname -a`); +chomp(@un); +$_=$un[1];s/\.molgen\.mpg\.de//; +$T{HOST} = $_; +$T{KERNEL} = "$un[2] $un[3]"; +$T{BITS} = 32; # default (may change sometime...) +$T{ARCH} = 'i686'; +if ($T{KERNEL} =~ /x86_64|mx64/) { + $T{BITS} = 64; + $T{ARCH} = 'x86_64'; +} + +$_ = `/lib/libc.so.6`; +/version (\d\S+)[\.,]/; +$T{GLIBC} = $1; + +my @pc=`cat /proc/cpuinfo`; +my $mn='unknown CPU'; +$T{NCPU} = grep {/model name/ and $mn = $_; /processor/} @pc; +$mn =~ s/\(.*?\)|xeon|Virtual|Athlon|model name\s*:|six.core|quad.core|dual.core|intel|Processor|cpu|core//ig; +$mn =~ s/\s(E\d\-)\s/$1/; +$mn =~ s/\s\d\s\@/ \@/; +$mn =~ s/version\s+/v/g; +$mn =~ s/\s+/ /g; +$mn =~ s/^\s+|\s+$//g; +$T{CPU} = $mn; + +$T{SYSTEM}=''; +{ + my $sys = ''; + +# for i in /sys/devices/virtual/dmi/id/*_{name,vendor,version}; do echo -en "$i\t"; cat $i; done +# for i in /sys/devices/virtual/dmi/id/{product_{name,version},sys_vendor}; do echo -en "$i\t"; cat $i; done + +# /sys/devices/virtual/dmi/id + + my $pn = readstr('/sys/devices/virtual/dmi/id/product_name'); + if ($pn =~ m/All Series|empty/) { + $pn = undef; + $pn = readstr('/sys/devices/virtual/dmi/id/board_name'); + } +# $pn =~ s/(TYAN Transport )//i; + + my $mf = readstr('/sys/devices/virtual/dmi/id/sys_vendor'); + if ($mf =~ m/(empty|NVIDIA)/) { + $mf = readstr('/sys/devices/virtual/dmi/id/board_vendor'); + } + $mf =~ s/( Inc.| Computer Corporation)//; + + my $vn = readstr('/sys/devices/virtual/dmi/id/product_version'); + if ($vn =~ m/empty/) { + $vn = undef; + } + + if ( defined($pn) and $pn eq 'CK8 ') { + $mf = $vn; + $pn = ''; + } + ($pn ne '') and $pn = " $pn"; + $T{SYSTEM} = "$mf$pn"; + $T{SYSTEM} =~ s/_/ /g; + $T{SYSTEM} =~ s{( Transport| Tower|Hewlett-Packard |/S2932-E/S2932-SI| Thunder| Computer Corp|Technology Co., Ltd. )}{}i; +} + +my %BC = ( + 'bugblatterbeastoftraal' => 'TYAN VX50 B4985', + 'crap03' => 'TYAN GT20-B2925/B2925-E', + 'keineahnung' => 'FUJITSU ESPRIMO P756', + 'furunkel' => 'HP Z200 Workstation', +); +if (exists($BC{$T{HOST}}) and $BC{$T{HOST}} ne $T{SYSTEM}) { + system("banner WRONG"); + die "$BC{$T{HOST}} ne $T{SYSTEM}"; +} +my @mem = `cat /proc/meminfo`; +my $mem = '??'; +for (@mem) { + if (/MemTotal:\s+(\d+)/) { + my $mm = $1; + if ( int($mm / 1024 / 1000 ) >= 1 ) { + $mem = (int($mm / 1024 / 100)/10) + 0; + $mem .= ' GB'; + } + elsif ( int($mm / 1000 ) >= 1 ) { + $mem = (int($mm / 100)/10) + 0; + $mem .= ' MB'; + } + else { + $mem = "$mm kB"; + } + last; + } +} +$T{MEM} = $mem; + + +$TEMPLATE=~s/%(\S+?)%/$T{$1}||$1/eg; +open O, '>','/etc/motd' or die "/etc/motd: $!\n"; +print O $TEMPLATE, (join("\n",map (" ** $_ **",policy($T{HOST})))||" ** **"),"\n\n"; +close O; diff --git a/mkmotd/motd.service b/mkmotd/motd.service new file mode 100644 index 0000000..2d574a6 --- /dev/null +++ b/mkmotd/motd.service @@ -0,0 +1,11 @@ +[Unit] +Description=Make motd + +[Service] +Type=oneshot +ExecStart=/usr/sbin/mkmotd.pl +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target + From e1f7a5e70a3d6a971d4903ff0206fb38dc8d37ac Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Wed, 21 Feb 2018 15:14:02 +0100 Subject: [PATCH 2/2] mkmotd: Strip trailing spaces --- mkmotd/mkmotd.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mkmotd/mkmotd.pl b/mkmotd/mkmotd.pl index 83bfbb3..e35bfa6 100755 --- a/mkmotd/mkmotd.pl +++ b/mkmotd/mkmotd.pl @@ -73,7 +73,7 @@ sub readstr { sub policy { # policy('theinternet') --> ('zeile1,'zeile2',....) my ($hostname)=@_; - + open IN,'<','/etc/mxpolicy' or return (); while () { if (/^\S/ && /\b$hostname\b/) { @@ -84,7 +84,7 @@ sub policy { # policy('theinternet') --> ('zeile1,'zeile2',....) if (/\s+\`\s*(.+)/) { my $x = `$1`;chomp($x); push @out,split(/\n/,$x); - } + } } return @out; } @@ -125,12 +125,12 @@ sub policy { # policy('theinternet') --> ('zeile1,'zeile2',....) $T{SYSTEM}=''; { my $sys = ''; - + # for i in /sys/devices/virtual/dmi/id/*_{name,vendor,version}; do echo -en "$i\t"; cat $i; done # for i in /sys/devices/virtual/dmi/id/{product_{name,version},sys_vendor}; do echo -en "$i\t"; cat $i; done # /sys/devices/virtual/dmi/id - + my $pn = readstr('/sys/devices/virtual/dmi/id/product_name'); if ($pn =~ m/All Series|empty/) { $pn = undef;