From 55fdeef0e883f34e80dfca417a81ec57a31c8cda Mon Sep 17 00:00:00 2001 From: ahriman Date: Wed, 13 Mar 2019 08:49:32 +0000 Subject: refactor --- bin/motdrotate.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 bin/motdrotate.py (limited to 'bin/motdrotate.py') diff --git a/bin/motdrotate.py b/bin/motdrotate.py new file mode 100755 index 0000000..ceb8147 --- /dev/null +++ b/bin/motdrotate.py @@ -0,0 +1,41 @@ +#!/usr/local/bin/python3 + +import sys +import random + +############################################## +## Uses a skeleton motd plus a random quote ## +## to produce a motd with a nifty quote. ## +##------------------------------------------## +## Created by ahriman - ahriman@falte.red ## +## --> BSD 3-clause license applies ## +############################################## + +def pullfile(filename): + with open(filename, 'r') as filesrc: + filedata = filesrc.read() + return filedata + +def rotatemotd(motd): + motdmsgs = ['Abandon hope all ye who enter here', + '"In matters of life and death there is no cheating; there is only living and dying"', + '"New technology is not good or evil in and of itself. It\'s all about how people choose to use it."', + '"Technology is, of course, a double-edged sword. Fire can cook our food but also burn us."', + '"If we lose love and self-respect for each other, this is how we finally die."', + '"We live in a society exquisitely dependent on science and technology, in which hardly anyone knows anything about science and technology."', + '"Any sufficiently advanced technology is indistinguishable from magic."'] + motdchoice = random.choice(motdmsgs) + try: + with open("/etc/motd", "w") as etcmotd: + etcmotd.write(motd) + etcmotd.write(motdchoice) + etcmotd.write("\n") + etcmotd.write("\n") + except: + print("Unable to open /etc/motd for writing. Who are you?") + sys.exit(0) + +if __name__=="__main__": + motdskel = pullfile("/admin/misc/motd.txt") + rotatemotd(motdskel) + -- cgit 1.4.1-2-gfad0