File size: 2,535 Bytes
4550bff
9a8c002
 
 
4550bff
 
 
 
9a8c002
 
4550bff
 
9a8c002
4550bff
 
9a8c002
4550bff
 
 
9a8c002
4550bff
 
 
 
 
9a8c002
 
 
 
 
 
 
 
 
 
4550bff
 
9a8c002
4550bff
 
9a8c002
 
 
 
 
 
 
 
 
4550bff
9a8c002
 
 
 
 
 
4550bff
 
 
 
9a8c002
4550bff
 
 
 
 
 
9a8c002
4550bff
 
 
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
#!/bin/bash
# WickBot startup script — sequential entrypoint for HF Spaces Docker SDK.
# This is an alternative to supervisord; use it by setting the Space's
# Docker CMD to ["bash", "scripts/start.sh"] instead of supervisord.
set -euo pipefail

echo "=== WickBot startup ==="

# Match DISPLAY from Dockerfile / supervisord
export DISPLAY=":99"
sleep 7

# --- Persistent /data volume setup ---
mkdir -p /data/logs /data/sessions /data/training /data/backups

# Remove stale log locks from previous container crash
rm -f /data/logs/bot.log.* 2>/dev/null || true
rm -f /data/logs/bot.log 2>/dev/null || true

# Seed default config if none exists in /data
if [ ! -f /data/config.json ] && [ -f /app/config.default.json ]; then
    cp /app/config.default.json /data/config.json
    echo "Created default config.json in /data"
fi

# Seed runtime config overrides from deploy config (one-way merge)
if [ -f /app/data/config.deploy.json ] && [ ! -f /data/config.json ]; then
    cp /app/data/config.deploy.json /data/config.json
    echo "Seeded config.deploy.json as /data/config.json"
fi

# Sync /data/sessions → Wine's C:\sessions_local so the Telegram bot
# (running under Wine if it were the Windows Python) can find them.
# Our bot actually runs as Linux Python, but we keep both sides in sync.
mkdir -p /app/sessions_local
if [ -d /data/sessions ] && [ "$(ls -A /data/sessions 2>/dev/null)" ]; then
    cp -rf /data/sessions/* /app/sessions_local/ 2>/dev/null || true
    echo "Restored sessions from /data → /app/sessions_local/"
fi

export SESSION_DIR="C:/sessions_local"
export DB_PATH="Z:/app/data/automator.db"
export CONFIG_PATH="Z:/data/config.json"
export LOG_DIR="Z:/app/logs"
export MT5_SYMBOL_SUFFIX="m"

# --- Launch MT5 terminal ---
# Workdir is /app, so Wine maps it to Z:\app. mt5_terminal/ → Z:\app\mt5_terminal\
# /portable keeps all MT5 data inside mt5_terminal/ instead of Wine's fake C:\ drive.
echo "Launching MT5 terminal under Wine..."
if [ -f "mt5_terminal/terminal64.exe" ]; then
    wine mt5_terminal/terminal64.exe /portable > /data/logs/wine_terminal.log 2>&1 &
else
    echo "ERROR: mt5_terminal/terminal64.exe not found — did you run scripts/upload_to_hf.py --mt5?"
    exit 1
fi

echo "Waiting 15s for MT5 to initialize..."
sleep 15

# --- Launch mt5linux RPyC server ---
echo "Starting mt5linux server..."
wine python -m mt5linux --host 0.0.0.0 --port 18812 &

echo "Waiting 10s for mt5linux server..."
sleep 10

# --- Launch the bot ---
echo "Starting WickBot..."
cd /app
exec uv run main.py