Add edge files.
This commit is contained in:
40
sh.py
40
sh.py
@@ -1,44 +1,60 @@
|
||||
"""
|
||||
The shell for PyNVOS
|
||||
Version: 0.1.0-main1
|
||||
Version: 0.2.0.0400
|
||||
"""
|
||||
import importlib
|
||||
import os
|
||||
import cmd
|
||||
import shutil
|
||||
|
||||
# from ..sys.krnl import Kernel
|
||||
print(__name__)
|
||||
class shell(cmd.Cmd):
|
||||
intro = "Shell started, PyNVOS 0.1.1-main1"
|
||||
prompt = "shell-0.1.0$ "
|
||||
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
|
||||
krnl = importlib.import_module(".jail_mgr", "vfs.sys")
|
||||
kernel = krnl.Kernel()
|
||||
print(str(kernel) + " " + str(type(kernel)))
|
||||
|
||||
def do_cd(self, args):
|
||||
"""Changes directory"""
|
||||
args = shell.kernel.fs(args)
|
||||
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(shell.kernel.fs("/bin"))
|
||||
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.kernel.run_program(f"/bin/{args}.py")
|
||||
shell.jailmgr.run_program(f"/bin/{args}.py")
|
||||
else:
|
||||
shell.kernel.run_program(args)
|
||||
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", None, "PKG", f"{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", None, "PKG", f"{pkg}")
|
||||
shutil.copy(self.jailmgr.fs(f"/usr/netsock/cache/{pkg}.py"), self.jailmgr.fs(f"/usr/bin/"))
|
||||
|
||||
def postloop(self):
|
||||
pass
|
||||
|
||||
@@ -46,6 +62,6 @@ class shell(cmd.Cmd):
|
||||
if __name__ == '<run_path>':
|
||||
shell().cmdloop()
|
||||
if __name__ == '__main__':
|
||||
print("The shell can't be ran as a standalone program and must be ran in conjunction with the kernel.")
|
||||
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)
|
||||
exit(-1)
|
||||
|
Reference in New Issue
Block a user