File size: 2,103 Bytes
00db9c8
 
 
 
 
 
 
 
 
acaa7a8
 
 
 
 
 
 
 
 
00db9c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
acaa7a8
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
import os
import subprocess
import time
import shutil

print("==================================================")
print("🚀 Starting Cloudix Linux Desktop on Hugging Face")
print("==================================================")

# ZeroGPU initialization
try:
    import spaces
    @spaces.GPU
    def gpu_init():
        return "GPU ready"
except Exception as e:
    pass

os.environ["DISPLAY"] = ":1"

# 1. Start Xvfb (Virtual Screen Display)
print("[1/4] Starting Xvfb virtual display (:1)...")
subprocess.Popen(["Xvfb", ":1", "-screen", "0", "1280x720x24"])
time.sleep(1.5)

# 2. Start XFCE4 Desktop Session
print("[2/4] Starting XFCE4 Desktop Session...")
subprocess.Popen(["dbus-launch", "xfce4-session"])
time.sleep(2)

# 3. Start x11vnc server
print("[3/4] Starting x11vnc server on port 5900...")
subprocess.Popen([
    "x11vnc",
    "-display", ":1",
    "-nopw",
    "-listen", "127.0.0.1",
    "-xkb",
    "-forever",
    "-shared",
    "-noxdamage"
])
time.sleep(1.5)

# 4. Prepare noVNC directory & autoconnect index
novnc_dir = "/usr/share/novnc"
target_dir = "/tmp/novnc_web"

if os.path.exists(target_dir):
    shutil.rmtree(target_dir)

if os.path.exists(novnc_dir):
    shutil.copytree(novnc_dir, target_dir)
else:
    os.makedirs(target_dir, exist_ok=True)

vnc_html_path = os.path.join(target_dir, "vnc.html")
index_html_path = os.path.join(target_dir, "index.html")

if os.path.exists(vnc_html_path):
    with open(vnc_html_path, "r", encoding="utf-8") as f:
        content = f.read()
    content = content.replace("<head>", '<head><script>if (!window.location.search) { window.location.search = "?autoconnect=true&resize=remote"; }</script>')
    with open(index_html_path, "w", encoding="utf-8") as f:
        f.write(content)

print("[4/4] Starting WebSockify Gateway on port 7860...")
cmd = [
    "websockify",
    f"--web={target_dir}",
    "7860",
    "127.0.0.1:5900"
]

print("==================================================")
print("✅ Cloudix Linux Desktop Ready on Port 7860!")
print("==================================================")

subprocess.run(cmd)