🧹 issue() in `bbs.minishell` now shows a text file main
authorMalte Bublitz <malte@rolltreppe3.de>
Sat, 6 Dec 2025 17:41:30 +0000 (18:41 +0100)
committerMalte Bublitz <malte@rolltreppe3.de>
Sat, 6 Dec 2025 17:41:30 +0000 (18:41 +0100)
- This function mimics getty(8) showing `/etc/issue` before the login prompt,
  so the text shown should also be read from a text file
- The data directory we use has already been used in the previous commit,
  e727b78054fee90e6aa5700e56d88051425d0ff5, for `bbs.minishell`

bbs/data/issue [new file with mode: 0644]
bbs/minishell.py
bin/tardis-minishell

diff --git a/bbs/data/issue b/bbs/data/issue
new file mode 100644 (file)
index 0000000..b135d1a
--- /dev/null
@@ -0,0 +1,9 @@
+\e[H\e[2J\e[3J
+
+  ______   ___      ____    ____    ____  _____
+ /_  __/  /   |    / __ \  / __ \  /  _/ / ___/
+  / /    / /| |   / /_/ / / / / /  / /   \__ \ 
+ / /  _ / ___ |_ / _, _/ / /_/ / _/ / _ ___/ / 
+/_/  (_)_/  |_(_)_/ |_(_)_____(_)___/(_)____(_)
+                                               
+
index 782c2755915c191e1612dbfa7ed27b729863f61d..8dbf7941df52e0ac7d461aac65804ba6a396372e 100644 (file)
@@ -2,8 +2,8 @@
 # -*- coding: utf-8 -*-
 #
 # Minimal Shell
 # -*- coding: utf-8 -*-
 #
 # Minimal Shell
-#    Use whenever a user should be able to launch a shell,
-#    but not to execute commands.
+#      Use whenever a user should be able to launch a shell,
+#      but not to execute commands.
 #
 # Copyright (c) 2013-2015 Malte Bublitz.
 # All rights reserved.
 #
 # Copyright (c) 2013-2015 Malte Bublitz.
 # All rights reserved.
@@ -23,207 +23,197 @@ os.chdir(os.path.dirname(sys.argv[0]))
 import bbs.env
 import bbs.bofh
 
 import bbs.env
 import bbs.bofh
 
-def getuser():
-    return "doctorwho"
-    
-def issue():
-    # Escape codes for clearing the screen:
-    # ansi/vt100/vt220
-    #     \e[H\e[J
-    # xterm-256color
-    #     \e[3J\e[H\e[2J
-    # 
-    os.system("clear")
-    #print("")
-    #os.system("figlet -f slant T.A.R.D.I.S.")
-    #print("")
-    #print(chr(27)+"[H"+chr(27)+"[J", end="")
-    print("""
-  ______   ___      ____    ____    ____  _____
- /_  __/  /   |    / __ \  / __ \  /  _/ / ___/
-  / /    / /| |   / /_/ / / / / /  / /   \__ \ 
- / /  _ / ___ |_ / _, _/ / /_/ / _/ / _ ___/ / 
-/_/  (_)_/  |_(_)_/ |_(_)_____(_)___/(_)____(_)
-                                               
-""")
-    
+
+def issue(data_file = None):
+       if data_file is None:
+               data_file = os.path.join(
+                       os.path.dirname(__file__),
+                       "data",
+                       "issue"
+               )
+
+       with open(data_file, "r") as f:
+               print(f.read())
+
+
 def login(prompt1="login: ", prompt2="Password: ", clear_before = True):
 def login(prompt1="login: ", prompt2="Password: ", clear_before = True):
-    if clear_before:
-        #os.system("clear")
-        pass
-        
-    login_data = ["", ""]
-    while len(login_data[0]) < 2:
-        try:
-            login_data[0] = input(prompt1)
-        except EOFError:
-            print("^D")
-
-    login_data[1] = getpass.getpass(prompt2)
-    
-    return login_data
-
-def minishell(ps1="%w> "):
-    """
-    ps1 is used as the prompt, and %w will be replaced by the current working directory
-    """
-    env = bbs.env.BBSFakeUserEnv()
-    commands_allowed = (
-        "",
-        "exit",
-        "logout",
-        "help",
-        "whoami",
-        "id",
-        "hostname",
-        "pwd",
-        "ls", "dir",
-        "cat", "type",
-        "uname",
-        "clear",
-        "sry", "bofh",
-    )
-    command = ""
-    
-    # /etc/issue
-    issue()
-    
-    # Log in
-    try:
-        env.setUser(login(clear_before=False)[0])
-    except KeyboardInterrupt:
-        #sys.exit(0)
-        env.setUser("john.doe")
-    
-    env.setHideRealUname(True)
-    env.setNode("bbs.malte70.de")
-    if env.getUser() in ["doctor", "doctorwho", "doctor_who"]:
-        #env.setNode("torchwood.tardis.malte70.de")
-        env.setNode("bbs.torchwood-cardiff.torchwood.gov.uk")
-    
-    if "--lxc" in sys.argv[1:]:
-        env.setRunningInsideLXC(True)
-        
-    print("\nWelcome on "+env.getNode()+", "+env.getUser()+"!\n")
-    
-    if env.getRunningInsideLXC():
-        # Show an unneccessary cryptic message if running inside LXC
-        print("  [SYS$LOG]  Installing BBS-UX LXC services...\n")
-    
-    try:
-        while command != "exit":
-            #print(ps1, end="")
-            print(env.getPrompt(ps1), end="")
-            try:
-                command = input().lower()
-                
-            except KeyboardInterrupt:
-                print("")
-                continue
-            
-            # Split command from command_args    
-            command_args = " ".join(command.split(" ")[1:])
-            command = command.split(" ")[0]
-
-            if command == "logout" or command == "exit":
-                command = "exit"
-                
-            elif command == "help" and len(command_args) < 1:
-                print("""Help
+       if clear_before:
+               #os.system("clear")
+               pass
+
+       login_data = ["", ""]
+       while len(login_data[0]) < 2:
+               try:
+                       login_data[0] = input(prompt1)
+               except EOFError:
+                       print("^D")
+
+       login_data[1] = getpass.getpass(prompt2)
+
+       return login_data
+
+def minishell(ps1 = "%w> ", filesystem_json = None, issue_file = None):
+       """
+       Args:
+       ps1 is used as the prompt, and %w will be replaced by the current working directory
+       """
+       env = bbs.env.BBSFakeUserEnv(filesystem_json)
+       commands_allowed = (
+               "",
+               "exit",
+               "logout",
+               "help",
+               "whoami",
+               "id",
+               "hostname",
+               "pwd",
+               "ls", "dir",
+               "cat", "type",
+               "uname",
+               "clear",
+               "sry", "bofh",
+       )
+       command = ""
+
+       # /etc/issue
+       issue(issue_file)
+
+       # Log in
+       try:
+               env.setUser(login(clear_before=False)[0])
+       except KeyboardInterrupt:
+               #sys.exit(0)
+               env.setUser("john.doe")
+
+       env.setHideRealUname(True)
+       env.setNode("bbs.malte70.de")
+       if env.getUser() in ["doctor", "doctorwho", "doctor_who"]:
+               #env.setNode("torchwood.tardis.malte70.de")
+               env.setNode("bbs.torchwood-cardiff.torchwood.gov.uk")
+
+       if "--lxc" in sys.argv[1:]:
+               env.setRunningInsideLXC(True)
+
+       print("\nWelcome on "+env.getNode()+", "+env.getUser()+"!\n")
+
+       if env.getRunningInsideLXC():
+               # Show an unneccessary cryptic message if running inside LXC
+               print("  [SYS$LOG]  Installing BBS-UX LXC services...\n")
+
+       try:
+               while command != "exit":
+                       #print(ps1, end="")
+                       print(env.getPrompt(ps1), end="")
+                       try:
+                               command = input().lower()
+
+                       except KeyboardInterrupt:
+                               print("")
+                               continue
+
+                       # Split command from command_args       
+                       command_args = " ".join(command.split(" ")[1:])
+                       command = command.split(" ")[0]
+
+                       if command == "logout" or command == "exit":
+                               command = "exit"
+
+                       elif command == "help" and len(command_args) < 1:
+                               print("""Help
 Commands:
 Commands:
-    whoami
-    id
-    hostname
-    pwd
-    ls
-    cat
-    uname
-    clear
-    help
-    logout/exit
+       whoami
+       id
+       hostname
+       pwd
+       ls
+       cat
+       uname
+       clear
+       help
+       logout/exit
 """)
 """)
-                
-            elif command == "help" and len(command_args) > 1:
-                help_topic = command_args.split(" ")[0]
-                if help_topic == "sry":
-                    print("SRY\n\tEaster Egg. Just try it!")
-                elif help_topic == "two":
-                    print("TWO\n\tTime Wasting Option")
-                    print("\tDon't conflate TWO with TSO in the OS/360")
-                    print("\tfamily of mainframe systems!")
-                elif help_topic in ("shutdown", "poweroff", "halt"):
-                    print("shutdown/poweroff/halt")
-                    print("\tRunning them is interpreted as an act of violence")
-                    print("\tagainst the Dalek!")
-                else:
-                    print(help_topic)
-                    print("\tFAKENEWS!")
-                
-            elif command == "whoami":
-                if not env.getUser() in ["doctor", "doctorwho", "doctor_who"]:
-                    print(env.getUser())
-                else:
-                    #print("I am the Doctor!")
-                    print(env.getName())
-                    print("")
-                    print("I should behave politely, so maybe excuse for")
-                    print("future mistakes with \"sry\" (Yes, an easter egg!)")
-                    print("")
-                
-            elif command == "shutdown" or command == "poweroff" or command == "halt":
-                print("Exterminate!")
-                print("Exterminate!".upper())
-                sys.exit(0)
-                
-            elif command == "id":
-                print("uid=42(" + env.getUser() + ") gid=100(users) groups=42(" + env.getUser() + "),9999(telnet)")
-                
-            elif command == "hostname":
-                print(env.getNode())
-                
-            elif command == "pwd":
-                #print("/usr/home/"+getuser())
-                print(env.getCurrentDir(True))
-                
-            elif command == "ls" or command == "dir":
-                #print("A: TARDIS   ZIP : DALEK    EXE")
-                #print("A: CLARA    DOC : ASHILDR  GIF")
-                _dir = env.getDirListing()
-                for _entry in _dir:
-                    print(" " + env.getCurrentDir()[:2] + " " + _entry)
-                
-            elif command == "cat" or command == "type":
-                # DEBUG:
-                #print("CMD  = \"" + command + "\"")
-                #print("ARGS = \"" + command_args + "\"")
-
-                filename = command_args.upper()
-                print(env.getFileContents(filename))
-
-            elif command == "uname":
-                print(env.getUName())
-                
-            elif command == "clear":
-                # clear screen
-                ret_code = os.system("clear")
-            
-            elif command == "sry" or command == "bofh":
-                # BOFH excuse
-                print("<BOFH> "+bbs.bofh.get_excuse())
-            
-            elif len(command) == 2 and command[1] == ":":
-                # Change drive/working directory
-                env.setCurrentDir(command.upper())
-                
-            #elif not command in commands_allowed:
-            #    print("-minishell: "+command.split(" ")[0]+": Command not found.")
-            elif len(command) > 0:
-                print("TWO: "+command.split(" ")[0]+": Command not found.")
-            
-    except EOFError:
-        print("<EOF>")
-        
-    print("Good bye.")
+
+                       elif command == "help" and len(command_args) > 1:
+                               help_topic = command_args.split(" ")[0]
+                               if help_topic == "sry":
+                                       print("SRY\n\tEaster Egg. Just try it!")
+                               elif help_topic == "two":
+                                       print("TWO\n\tTime Wasting Option")
+                                       print("\tDon't conflate TWO with TSO in the OS/360")
+                                       print("\tfamily of mainframe systems!")
+                               elif help_topic in ("shutdown", "poweroff", "halt"):
+                                       print("shutdown/poweroff/halt")
+                                       print("\tRunning them is interpreted as an act of violence")
+                                       print("\tagainst the Dalek!")
+                               else:
+                                       print(help_topic)
+                                       print("\tFAKENEWS!")
+
+                       elif command == "whoami":
+                               if not env.getUser() in ["doctor", "doctorwho", "doctor_who"]:
+                                       print(env.getUser())
+                               else:
+                                       #print("I am the Doctor!")
+                                       print(env.getName())
+                                       print("")
+                                       print("I should behave politely, so maybe excuse for")
+                                       print("future mistakes with \"sry\" (Yes, an easter egg!)")
+                                       print("")
+
+                       elif command == "shutdown" or command == "poweroff" or command == "halt":
+                               print("Exterminate!")
+                               print("Exterminate!".upper())
+                               sys.exit(0)
+
+                       elif command == "id":
+                               print("uid=42(" + env.getUser() + ") gid=100(users) groups=42(" + env.getUser() + "),9999(telnet)")
+
+                       elif command == "hostname":
+                               print(env.getNode())
+
+                       elif command == "pwd":
+                               print(env.getCurrentDir(True))
+
+                       elif command == "ls" or command == "dir":
+                               _dir = env.getDirListing()
+                               for _entry in _dir:
+                                       print(" " + env.getCurrentDir()[:2] + " " + _entry)
+
+                       elif command == "cat" or command == "type":
+                               filename = command_args.upper()
+                               try:
+                                       print(env.getFileContents(filename))
+                               except FileNotFoundError:
+                                       full_filename = env.getCurrentDir() + filename
+                                       print("TWO: [ERROR] File not found: " + full_filename)
+
+                       elif command == "uname":
+                               print(env.getUName())
+
+                       elif command == "clear":
+                               # clear screen
+                               ret_code = os.system("clear")
+
+                       elif command == "sry" or command == "bofh":
+                               # BOFH excuse
+                               print("<BOFH> "+bbs.bofh.get_excuse())
+
+                       elif len(command) == 2 and command[1] == ":":
+                               # Change drive/working directory
+                               try:
+                                       env.setCurrentDir(command.upper())
+                               except FileNotFoundError:
+                                       print("TWO: [ERROR] Drive " + command.upper() + " does not exist!")
+
+                       elif len(command) > 0:
+                               print("TWO: "+command.split(" ")[0]+": Command not found.")
+
+       except EOFError:
+               print("<EOF>")
+
+       print("Good bye.")
+
 
 if __name__ == "__main__":
 
 if __name__ == "__main__":
-    minishell(ps1='%w> ')
+       minishell(ps1='%w> ')
+
index f0e1f88a8b1838897b903918a191afad37767393..11676ee6b360d65402b9376d935a639df1927568 100755 (executable)
@@ -1,8 +1,6 @@
 #!/bin/bash
 
 #!/bin/bash
 
-pwd
-
-#cd $(basename $0)/..
+cd $(dirname $0)/..
 
 
 python -m bbs.minishell
 
 
 python -m bbs.minishell