-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
154 lines (111 loc) · 2.93 KB
/
main.py
File metadata and controls
154 lines (111 loc) · 2.93 KB
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
import os
def cls():
os.system("clear")
cls()
print("Installing...")
os.system("pip install docker flask textual pyloaders > /dev/null")
print("Installed")
print("Importing...")
import docker, time, webbrowser, subprocess, threading
from flask import Flask, render_template
from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, Button, Label
from loaders import BarLoader
print("Imported")
print("Create server")
app = Flask(__name__)
serverthread = threading.Thread(
target=lambda: app.run(host="0.0.0.0", port=6969, debug=False, use_reloader=False)
)
serverthread.daemon = True
print("Server created")
print("Create Textual App")
class WebDesktop(App):
CSS = """
Screen {
align: center middle;
}
.bigbtn {
margin: 1;
align: center middle;
width: 69
}
.smallbtn {
width: 1;
}
"""
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "open":
webbrowser.open("http://localhost:6969")
def compose(self) -> ComposeResult:
yield Label("WebDesktop is running")
yield Button("Open", id="open", variant="success", classes="bigbtn")
print("Created Textual App")
print("Init docker")
client = docker.from_env()
cls()
print("Pull container")
print("This may take a while")
loader = BarLoader(complete_text="Pulled container")
loader.start()
client.images.pull("lscr.io/linuxserver/webtop:ubuntu-kde")
loader.stop()
def stopContainer():
try:
client.containers.list()[0].stop()
except:
pass
try:
client.containers.list()[0].remove()
except:
pass
client.containers.prune()
def startContainer():
client.containers.run(
"lscr.io/linuxserver/webtop:ubuntu-kde",
detach=True,
name="webdesktop",
security_opt=["seccomp:unconfined"],
environment=[
"PUID=1000",
"PGID=1000",
"TZ=Etc/UTC",
"SUBFOLDER=/",
"TITLE=WebDesktop",
],
volumes=["/workspace/WebDesktop/files:/config"],
ports={"3000": "3000"},
)
def resetContainer():
os.system("sudo rm -rf files")
print("Starting container")
@app.route("/")
def index():
return render_template("index.html")
@app.route("/restart")
def restart():
stopContainer()
startContainer()
return ":)"
@app.route("/reset")
def reset():
stopContainer()
resetContainer()
startContainer()
return ":)"
@app.route("/installappstore")
def appstore():
client.containers.list()[0].exec_run(
"/config/.local/bin/proot-apps install gui", user="abc"
)
client.containers.list()[0].exec_run(
"/config/.local/bin/proot-apps run gui", user="abc"
)
return ":)"
if __name__ == "__main__":
# resetContainer()
stopContainer()
startContainer()
serverthread.start()
txapp = WebDesktop()
txapp.run()