add motd generator script
authorSofian Brabez <sbz@6dev.net>
Sun, 28 Apr 2019 19:03:00 +0000 (19:03 +0000)
committersbz <sbz@6dev.net>
Sun, 28 Apr 2019 19:03:00 +0000 (19:03 +0000)
motd.py [new file with mode: 0644]

diff --git a/motd.py b/motd.py
new file mode 100644 (file)
index 0000000..77691d2
--- /dev/null
+++ b/motd.py
@@ -0,0 +1,48 @@
+import os
+
+template="""%s
+ +--------------------------------------+           ,        ,
+ |        Welcome to %s           |          /(        )`
+ |                                      |          \ \___   / |
+ |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|          /- _  `-/  '
+ |                                      |         (/\/ \ \   /\\
+ |  kern.hostname: %.8s               |         / /   | `    \\
+ |    kern.ostype: %s              |         O O   ) /    |
+ | kern.osrelease: %s     |         `-^--'`<     '
+ |       hw.model: %.20s |        (_.)  _  )   /
+ |     hw.machine: %s                |         `.___/`    /
+ |        hw.ncpu: %s                    |           `-----' /
+ | dev.cpu.0.freq: %s                <----.     __ / __   \\
+ |     hw.physmem: %s         <----|====O)))==) \) /====
+ |           inet: %s        <----'    `--' `.__,' \\
+ |                                      |           |        |
+ |          admin: %s         |            \       /
+ |                                      |       ______( (_  / \______
+ |                                      |     ,'  ,-----'   |        \\
+ +--------------------------------------+     `--{__________)        \/
+"""
+
+def sysctl_get(oid_string):
+    result=""
+    try:
+        import freebsd
+        result=freebsd.sysctl('%s' % oid_string)
+    except:
+        result=os.popen('sysctl -n %s' % oid_string).read().strip()
+    finally:
+        return result
+
+uname = " ".join(" ".join(os.uname()[:4]).split(' ')[:13])
+fqdn = "6dev.net"
+admin = "%s@%s" % (os.environ['USER'], fqdn)
+inet = os.popen("ifconfig|grep 'inet .* broad*'").read().split()[1]
+
+oids = ["kern.hostname", "kern.osrelease", "kern.ostype", "hw.model", "hw.machine",
+"hw.ncpu", "dev.cpu.0.freq", "hw.physmem"]
+
+for oid in oids:
+    locals()[oid.replace('.','_')] = sysctl_get(oid)
+
+print(template % (uname, fqdn, kern_hostname.split('.')[0], kern_ostype, kern_osrelease, hw_model,
+        hw_machine, hw_ncpu, dev_cpu_0_freq, "%.1fGB" %
+        float(int(hw_physmem)/1000000000.0), inet, admin))