""" The shell for PyNVOS Version: 0.2.0.0399 """ import importlib import os import cmd import shutil # from ..sys.krnl import Kernel print(__name__) class shell(cmd.Cmd): jail_mgr = importlib.import_module(".jail_mgr", "vfs.sys") jailmgr = jail_mgr.PyJail() kver = jailmgr.kver() intro = f"Shell started, PyNVOS {kver}" prompt = "shell-0.2$ " file = None def do_cd(self, args): """Changes directory""" args = shell.jailmgr.fs(args) os.chdir(args) def do_exec(self, args): """Allows you to execute a file""" # Apps in /bin should be allowed to launch without first adding /bin/ or ./, just the name of the executable # So for ledit it should be just 'ledit' and not /bin/ledit.py or ./ledit.py bins_in_bin = os.listdir(self.jailmgr.fs("/bin")) apps_strip = [] for apps in bins_in_bin: if apps.endswith(".py"): apps_strip.append(apps.strip(".py")) if args in apps_strip: shell.jailmgr.run_program(f"/bin/{args}.py") else: shell.jailmgr.run_program(args) def do_ls(self, none): """Lists the content of a directory""" os.listdir(os.getcwd()) def do_pkg(self, pkg): """Downloads packages over the internet.""" self.jailmgr.netsock(f"https://pkg.novacow.ch/repo/{kver}/meta/{pkg}.pmd", 443, "PKG", "") shutil.copy(self.jailmgr.fs(f"/usr/netsock/cache/{pkg}.pmd"), self.jailmgr.fs(f"/usr/pkg/metacache/")) with open(self.jailmgr.fs(f"/usr/pkgs/metacache/{pkg}.pmd"), "r") as f: package_meta = f.read() f.close() print(package_meta) y_n_confirmation = input("Do you want to install this package? [y/N] ") if y_n_confirmation.lower() != "y": print("Aborted.") return self.jailmgr.netsock(f"https://pkg.novacow.ch/repo/{kver}/main/static/binary/{pkg}.py", 443, "PKG", "") shutil.copy(self.jailmgr.fs(f"/usr/netsock/cache/{pkg}.py"), self.jailmgr.fs(f"/usr/bin/")) def postloop(self): pass if __name__ == '': shell().cmdloop() if __name__ == '__main__': print("The shell can't be ran as a standalone program and must be ran in conjunction with the jail manager.") input("Press Enter to continue...") exit(-1)