-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSNK.py
172 lines (146 loc) · 5.99 KB
/
SNK.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import json
import os
import cmd
import requests
import subprocess
import sys
import time
from tabulate import tabulate
from lib import color as color, ascii as art, globalplaceholders as gph
from lib.scripts import plugman
from lib.loaders import PyLoader, LuaLoader, JSLoader
class SNK_Shell(cmd.Cmd):
intro = f"SwissNetKnife Shell\n(C) Werameli (TeamSNK). All rights reserved\n"
prompt = "SNK@localhost $>"
def do_help(self, arg):
print("TIP: You're cute'")
print("")
print("Available commands:")
print("pkgman - SNK's Package Manager")
print("plugman - SNK's Plugin Manager")
print("clear - clear terminal")
print("restart - restart SNK")
print("exit - quit SNK")
@staticmethod
def do_exit(arg):
subprocess.call(["clear"])
exit(0)
@staticmethod
def do_pkgman(arg):
match arg:
case "check":
versionfile = open(".version", "r")
version = versionfile.read()
versionfile.close()
repoversion = requests.get(
"https://raw.githubusercontent.com/Werameli/SwissNetKnife/master/.version").text
print(color.yellow)
print(f"Your version is {version}")
print(f"Latest version on repo is {repoversion}")
if version != repoversion and not "nightly-unfixed":
print("\nYou need to update!")
print(f"Your version {version} needs to be updated to {repoversion}")
print(f"Run 'pkgman update' to initialize update process")
print(color.green)
else:
print(color.green)
print("You're up to date!\n")
case "update":
updaterequest = input("Do you wish to start update process? (y/n) ")
if updaterequest.lower() == "y":
os.environ['LOADED'] = str(False)
subprocess.Popen(["python3", "updater.py"])
exit(0)
else:
pass
case _:
print("Available commands:")
print("check - check if there's a newer version of a script")
print("update - start update process if there's a newer version of a script\n")
@staticmethod
def do_plugman(arg):
global result
match arg:
case "install":
if plugman.ifrepoexists():
print("Reading repolist...")
plugman.readrepo()
pkg = input("Enter package name: ")
pkgsearch = plugman.searchinrepo(pkg)
if pkgsearch:
for result in pkgsearch:
print(f"\nFile found in repository: {result['repo_name']}")
install = input("\nProceed with installation? [Y/N] ")
if install.lower() == "y":
plugman.installation(result['file_url'])
else:
print("Installation aborted!")
else:
print("Repolist is empty! Consider adding repositories via 'plugman repoadd'")
case "list":
plugins_py = json.loads(os.getenv("LOADED_PLUGINS", "[]"))
plugins_js = json.loads(os.getenv("LOADED_JS_PLUGINS", "[]"))
plugins_lua = json.loads(os.getenv("LOADED_LUA_PLUGINS", "[]"))
all_plugins = plugins_py + plugins_js + plugins_lua
if all_plugins:
table_data = [
[p["name"], p["type"], p["version"], p["author"]]
for p in all_plugins
]
print("\nLoaded Plugins:")
print(tabulate(table_data,
headers=["Name", "Type", "Version", "Author"],
tablefmt="grid"))
print()
else:
print("\nNo plugins loaded.\n")
case "repoadd":
reponame = input("Insert repository name: ")
repourl = input("Insert repository URL:")
plugman.add_repository(reponame, repourl)
case _:
print("Available commands:")
print("install - install various plugins")
print("list - shows a list of all loaded plugins")
print("repoadd - add plugin repositories to the repolist\n")
@staticmethod
def do_restart(arg):
print("Restarting...")
time.sleep(2)
os.environ['LOADED'] = str(False)
subprocess.Popen(["python3", "loader.py"])
exit(0)
@staticmethod
def do_clear(arg):
subprocess.call(["clear"])
def default(self, arg):
print(f"{color.red}Unknown command. Type 'help' for a list of available commands")
print(color.green)
if __name__ == '__main__':
shell = SNK_Shell()
subprocess.call(["clear"])
if os.getenv("LOADED") == "True":
pass
else:
print("Illegal Launch! Can't launch script without loader")
print("Launch loader.py to proceed with script launching!")
exit(120)
print("Initializing plugins...\n")
time.sleep(2)
skip_py = "--skip-py" in sys.argv
skip_lua = "--skip-lua" in sys.argv
skip_js = "--skip-js" in sys.argv
if not skip_py:
PyLoader.pyinit(shell)
if not skip_lua:
LuaLoader.luainit(shell)
if not skip_js:
JSLoader.jsinit(shell)
subprocess.call(["clear"])
art.borderstripe()
art.menuart()
art.borderstripe()
print("\nUltimate lightweight scriptholder for all your scripts")
print(f"Release: Ver. {gph.version}")
print("")
shell.cmdloop()