Files
PyJail/install.py
2024-11-22 19:36:13 +01:00

88 lines
2.8 KiB
Python

"""
Install script for the Python jailer.
Version: 0.2.0-alpha1
"""
import os
import shutil
with open("./kverinfo.txt", "r") as f:
kver = f.read()
f.close()
with open("./verinfo.txt", "r") as f:
ver = f.read()
f.close()
print("Welcome to the PyJail install wizard.")
print(f"You are about to install version {ver} with manager {kver}")
y_n_question = input("Do you want to install PyJail? [Y/n] ")
if y_n_question.lower() == "n":
print("Installation cancelled!")
input("Press <Enter> to exit ")
exit(-1)
print("Preparing installation...")
os.mkdir(os.getcwd() + "/vfs")
shutil.move("./main.py", "./vfs/main.py")
shutil.move("./runner.py", "./main.py")
shutil.move("./sh.py", "./vfs/sh.py")
shutil.move("./ledit.py", "./vfs/ledit.py")
os.chdir(os.getcwd() + "/vfs")
print("Gathering info...")
usrname = input("Please enter your username: [usr1] ")
if usrname == "":
usrname = "usr1"
setup_posix = input("Do you wish to setup a mostly-POSIX compliant environment? [y/N] ")
if setup_posix.lower() == "y":
print("Creating directories...")
with open("./bin", "a+") as f:
f.write("symlnk /usr/bin/")
f.close()
with open("./sbin", "a+") as f:
f.write("symlnk /usr/sbin/")
f.close()
with open("./lib", "a+") as f:
f.write("symlnk /usr/lib/")
f.close()
with open("./lib64", "a+") as f:
f.write("symlnk /usr/lib64/")
f.close()
with open("./usr/bin/sh.py", "a+") as f:
f.write("symlnk /usr/bin/shell.py")
f.close()
os.mkdir("./sys")
os.mkdir("./usr")
os.mkdir("./proc")
os.mkdir(f"./home/{usrname}")
os.mkdir("./usr/bin/")
os.mkdir("./usr/sbin/")
os.mkdir("./usr/lib/")
os.mkdir("./usr/lib64/")
print("Copying files...")
shutil.move("./main.py", "./sys/jail_mgr.py")
shutil.move("./sh.py", "./bin/shell.py")
shutil.move("./ledit.py", "./bin/ledit.py")
print("Creating system configuration files...")
with open("./sys/usr.conf", "a+") as f:
f.write(usrname)
f.close()
with open("./sys/procinfo", "a+") as f:
f.write("proc: vfs(/proc/)\nkernel: vfs(/proc/kcore)")
f.close()
with open("./proc/kcore", "a+") as f:
f.write("/sys/jail_mgr.py")
f.close()
else:
print("Creating directories...")
os.mkdir("./bin")
os.mkdir("./sys")
os.mkdir("./usr")
os.mkdir("./proc")
os.mkdir(f"./home/{usrname}")
os.mkdir("./sys/krnl/")
print("Copying files...")
shutil.move("./main.py", "./sys/jail_mgr.py")
shutil.move("./sh.py", "./bin/shell.py")
shutil.move("./ledit.py", "./bin/ledit.py")
print("Creating system configuration files...")
with open("./sys/usr.conf", "a+") as f:
f.write(usrname)
f.close()
print("Install completed! Run ./main.py to start the kernel!")
input("Press <Enter> to exit! ")