add motd generator script
[freebsd-maintainer-scripts/.git] / motd.py
CommitLineData
b2d0d87b
SB
1import os
2
3template="""%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
25def 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
35uname = " ".join(" ".join(os.uname()[:4]).split(' ')[:13])
36fqdn = "6dev.net"
37admin = "%s@%s" % (os.environ['USER'], fqdn)
38inet = os.popen("ifconfig|grep 'inet .* broad*'").read().split()[1]
39
40oids = ["kern.hostname", "kern.osrelease", "kern.ostype", "hw.model", "hw.machine",
41"hw.ncpu", "dev.cpu.0.freq", "hw.physmem"]
42
43for oid in oids:
44 locals()[oid.replace('.','_')] = sysctl_get(oid)
45
46print(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))