add motd generator script
[freebsd-maintainer-scripts/.git] / motd.py
1 import os
2
3 template="""%s
4  +--------------------------------------+           ,        ,
5  |        Welcome to %s           |          /(        )`
6  |                                      |          \ \___   / |
7  |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|          /- _  `-/  '
8  |                                      |         (/\/ \ \   /\\
9  |  kern.hostname: %.8s               |         / /   | `    \\
10  |    kern.ostype: %s              |         O O   ) /    |
11  | kern.osrelease: %s     |         `-^--'`<     '
12  |       hw.model: %.20s |        (_.)  _  )   /
13  |     hw.machine: %s                |         `.___/`    /
14  |        hw.ncpu: %s                    |           `-----' /
15  | dev.cpu.0.freq: %s                <----.     __ / __   \\
16  |     hw.physmem: %s         <----|====O)))==) \) /====
17  |           inet: %s        <----'    `--' `.__,' \\
18  |                                      |           |        |
19  |          admin: %s         |            \       /
20  |                                      |       ______( (_  / \______
21  |                                      |     ,'  ,-----'   |        \\
22  +--------------------------------------+     `--{__________)        \/
23 """
24
25 def sysctl_get(oid_string):
26     result=""
27     try:
28         import freebsd
29         result=freebsd.sysctl('%s' % oid_string)
30     except:
31         result=os.popen('sysctl -n %s' % oid_string).read().strip()
32     finally:
33         return result
34
35 uname = " ".join(" ".join(os.uname()[:4]).split(' ')[:13])
36 fqdn = "6dev.net"
37 admin = "%s@%s" % (os.environ['USER'], fqdn)
38 inet = os.popen("ifconfig|grep 'inet .* broad*'").read().split()[1]
39
40 oids = ["kern.hostname", "kern.osrelease", "kern.ostype", "hw.model", "hw.machine",
41 "hw.ncpu", "dev.cpu.0.freq", "hw.physmem"]
42
43 for oid in oids:
44     locals()[oid.replace('.','_')] = sysctl_get(oid)
45
46 print(template % (uname, fqdn, kern_hostname.split('.')[0], kern_ostype, kern_osrelease, hw_model,
47         hw_machine, hw_ncpu, dev_cpu_0_freq, "%.1fGB" %
48         float(int(hw_physmem)/1000000000.0), inet, admin))