-
-
Notifications
You must be signed in to change notification settings - Fork 833
Expand file tree
/
Copy pathentry.sh
More file actions
73 lines (60 loc) · 1.96 KB
/
entry.sh
File metadata and controls
73 lines (60 loc) · 1.96 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
#!/bin/bash
cleanup() {
echo "Received signal, shutting down gracefully..."
if [ -n "$VM_PID" ]; then
kill -TERM "$VM_PID" 2>/dev/null
wait "$VM_PID" 2>/dev/null
fi
exit 0
}
# Install trap for signals
trap cleanup SIGTERM SIGINT SIGHUP SIGQUIT
# Overlay mode: /golden mounted read-only, /storage starts empty
if [ -d "/golden" ] && [ -z "$(ls -A /storage 2>/dev/null)" ]; then
echo "Overlay mode detected, setting up copy-on-write..."
if cp -al /golden/. /storage/ 2>/dev/null; then
echo "Overlay setup complete (hard links)."
else
echo "Hard links not supported, falling back to full copy..."
cp -a /golden/. /storage/
echo "Overlay setup complete (full copy)."
fi
fi
# Start the VM in the background
echo "Starting Ubuntu VM..."
/usr/bin/tini -s /run/entry.sh &
VM_PID=$!
echo "Live stream accessible at localhost:8006"
echo "Waiting for Ubuntu to boot and Cua computer-server to start..."
VM_IP=""
while true; do
# Wait for VM and get the IP
if [ -z "$VM_IP" ]; then
VM_IP=$(ps aux | grep dnsmasq | grep -oP '(?<=--dhcp-range=)[0-9.]+' | head -1)
if [ -n "$VM_IP" ]; then
echo "Detected VM IP: $VM_IP"
else
echo "Waiting for VM to start..."
sleep 5
continue
fi
fi
# Check if server is ready
response=$(curl --write-out '%{http_code}' --silent --output /dev/null $VM_IP:5000/status)
if [ "${response:-0}" -eq 200 ]; then
break
fi
echo "Waiting for Cua computer-server to be ready. This might take a while..."
sleep 5
done
echo "VM is up and running, and the Cua Computer Server is ready!"
echo "Computer server accessible at localhost:5000"
# Detect initial setup by presence of custom ISO
CUSTOM_ISO=$(find / -maxdepth 1 -type f -iname "*.iso" -print -quit 2>/dev/null || true)
if [ -n "$CUSTOM_ISO" ]; then
echo "Preparation complete. Shutting down gracefully..."
cleanup
fi
# Keep container alive for golden image boots
echo "Container running. Press Ctrl+C to stop."
tail -f /dev/null