Skip to content

Commit 37d4688

Browse files
committed
Add diagnostic script and interactive shells, expand .NET SDK integration for Wine
1 parent 3608d6b commit 37d4688

File tree

6 files changed

+163
-31
lines changed

6 files changed

+163
-31
lines changed

mtgo/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ RUN useradd -u $WINE_UID -d /home/wine -m -s /bin/bash $WINE_USER
3030
USER wine
3131
ENV WINEPREFIX=/home/wine/.wine
3232
ENV WINEARCH=win64
33+
ENV WINEDEBUG=-all
34+
ENV DOTNET_ROOT=C:\\dotnet
3335
WORKDIR /home/wine
3436

3537
# Copy scripts

mtgo/scripts/check-env.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
# check-env.sh: Diagnostic script for MTGO headless environment
3+
4+
echo "=== System Information ==="
5+
uname -a
6+
id
7+
echo "DISPLAY=$DISPLAY"
8+
9+
echo ""
10+
echo "=== X Server Status ==="
11+
if pgrep Xvfb > /dev/null; then
12+
echo "[PASS] Xvfb is running."
13+
ps aux | grep Xvfb | grep -v grep
14+
else
15+
echo "[FAIL] Xvfb is NOT running."
16+
fi
17+
18+
if [ -S /tmp/.X11-unix/X${DISPLAY#:} ]; then
19+
echo "[PASS] X11 socket found at /tmp/.X11-unix/X${DISPLAY#:}"
20+
else
21+
echo "[FAIL] X11 socket NOT found for display $DISPLAY"
22+
fi
23+
24+
if command -v xdpyinfo > /dev/null; then
25+
if xdpyinfo -display "$DISPLAY" > /dev/null 2>&1; then
26+
echo "[PASS] xdpyinfo successfully connected to display $DISPLAY"
27+
else
28+
echo "[FAIL] xdpyinfo FAILED to connect to display $DISPLAY"
29+
fi
30+
else
31+
echo "[SKIP] xdpyinfo not installed."
32+
fi
33+
34+
echo ""
35+
echo "=== Wine Status ==="
36+
wine --version
37+
echo "WINEPREFIX=$WINEPREFIX"
38+
if [ -d "$WINEPREFIX" ]; then
39+
echo "[PASS] Wine prefix directory exists."
40+
else
41+
echo "[FAIL] Wine prefix directory NOT found."
42+
fi
43+
44+
echo ""
45+
echo "=== MTGO Installation Status ==="
46+
MTGO_EXE=$(find "$WINEPREFIX/drive_c/users/wine/AppData/Local/Apps/2.0" -name "MTGO.exe" 2>/dev/null | head -n 1)
47+
if [ -n "$MTGO_EXE" ]; then
48+
echo "[PASS] MTGO.exe found at: $MTGO_EXE"
49+
else
50+
echo "[INFO] MTGO.exe NOT found in Wine prefix (expected if tests haven't run)."
51+
fi
52+
53+
APPREF_PATH="/home/wine/.wine/drive_c/users/wine/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Daybreak Game Company LLC/Magic The Gathering Online .appref-ms"
54+
if [ -f "$APPREF_PATH" ]; then
55+
echo "[PASS] MTGO .appref-ms found."
56+
else
57+
echo "[INFO] MTGO .appref-ms NOT found (expected if tests haven't run)."
58+
fi
59+
60+
echo ""
61+
echo "=== Network Status ==="
62+
ip addr show | grep 'inet '
63+
# Check if we can reach Daybreak's patch server
64+
if curl -sI http://mtgo.patch.daybreakgames.com/patch/mtg/live/client/MTGO.application > /dev/null; then
65+
echo "[PASS] Daybreak patch server is reachable."
66+
else
67+
echo "[FAIL] Daybreak patch server is NOT reachable."
68+
fi

mtgo/scripts/xvfb-entrypoint.sh

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22
set -e
33

4+
# Disable Wine logging and set .NET runtime path
5+
export WINEDEBUG=-all
6+
export DOTNET_ROOT=C:\\dotnet
7+
48
# Configuration
59
X_DISPLAY=${DISPLAY:-:99}
610
RESOLUTION=${RESOLUTION:-1280x1024x24}
@@ -11,7 +15,11 @@ if [ "$X_DISPLAY" = ":99" ]; then
1115
rm -f /tmp/.X${X_DISPLAY#:}*
1216

1317
echo "Starting Xvfb on display $X_DISPLAY with resolution $RESOLUTION"
14-
Xvfb $X_DISPLAY -screen 0 $RESOLUTION &
18+
if [ "$DEBUG" = "true" ]; then
19+
Xvfb $X_DISPLAY -screen 0 $RESOLUTION > /tmp/xvfb.log 2>&1 &
20+
else
21+
Xvfb $X_DISPLAY -screen 0 $RESOLUTION &
22+
fi
1523
XVFB_PID=$!
1624

1725
# Wait for Xvfb to start
@@ -26,7 +34,11 @@ if [ "$X_DISPLAY" = ":99" ]; then
2634
# Start VNC if requested
2735
if [ "$START_VNC" = "true" ]; then
2836
echo "Starting x11vnc..."
29-
x11vnc -display $X_DISPLAY -forever -shared -nopw -bg -xkb -rfbport 5900
37+
if [ "$DEBUG" = "true" ]; then
38+
x11vnc -display $X_DISPLAY -forever -shared -nopw -bg -xkb -rfbport 5900 > /tmp/x11vnc.log 2>&1
39+
else
40+
x11vnc -display $X_DISPLAY -forever -shared -nopw -bg -xkb -rfbport 5900
41+
fi
3042
fi
3143

3244
# Enable Wine Virtual Desktop for better window management if requested (default: true for headless)
@@ -37,18 +49,21 @@ if [ "$X_DISPLAY" = ":99" ]; then
3749
wine reg add "HKEY_CURRENT_USER\\Software\\Wine\\Explorer\\Desktops" /v "Default" /t REG_SZ /d "${RESOLUTION%x*}" /f >/dev/null 2>&1
3850
fi
3951

52+
# Disable automatic winedbg on crash to prevent orphan processes
53+
wine reg add "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug" /v "Auto" /t REG_SZ /d "0" /f >/dev/null 2>&1
54+
4055
# Trap signals for cleanup
4156
trap "kill $XVFB_PID" SIGINT SIGTERM
4257

43-
# Auto-install MTGO if missing (default: true)
44-
AUTO_INSTALL_MTGO=${AUTO_INSTALL_MTGO:-true}
45-
if [ "$AUTO_INSTALL_MTGO" = "true" ]; then
46-
MTGO_EXE=$(find "$WINEPREFIX/drive_c/users/wine/AppData/Local/Apps/2.0" -name "MTGO.exe" | head -n 1)
47-
if [ -z "$MTGO_EXE" ]; then
48-
echo "MTGO not found. Starting automatic installation..."
49-
install-mtgo.sh
50-
fi
51-
fi
58+
# # Auto-install MTGO if missing (default: true)
59+
# AUTO_INSTALL_MTGO=${AUTO_INSTALL_MTGO:-true}
60+
# if [ "$AUTO_INSTALL_MTGO" = "true" ]; then
61+
# MTGO_EXE=$(find "$WINEPREFIX/drive_c/users/wine/AppData/Local/Apps/2.0" -name "MTGO.exe" | head -n 1)
62+
# if [ -z "$MTGO_EXE" ]; then
63+
# echo "MTGO not found. Starting automatic installation..."
64+
# install-mtgo.sh
65+
# fi
66+
# fi
5267
fi
5368

5469
# Execute the passed command

mtgosdk/Dockerfile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ FROM ${BASE_IMAGE}
33

44
USER root
55

6-
# Install .NET SDK 10.0 (Preview) to Linux environment
7-
RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh \
8-
&& chmod +x ./dotnet-install.sh \
9-
&& ./dotnet-install.sh --channel 10.0 --quality preview --install-dir /usr/share/dotnet \
6+
# Install .NET SDK 10.0 (Preview) to Linux and Wine environments
7+
RUN wget https://dot.net/v1/dotnet-install.sh -O /tmp/dotnet-install.sh \
8+
&& chmod +x /tmp/dotnet-install.sh \
9+
&& /tmp/dotnet-install.sh --channel 10.0 --quality preview --install-dir /usr/share/dotnet \
1010
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
11-
&& rm dotnet-install.sh
11+
&& wget https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.100-rc.2.25502.107/dotnet-sdk-10.0.100-rc.2.25502.107-win-x64.zip -O /tmp/dotnet-win.zip \
12+
&& mkdir -p /home/wine/.wine/drive_c/dotnet \
13+
&& unzip /tmp/dotnet-win.zip -d /home/wine/.wine/drive_c/dotnet \
14+
&& chown -R wine:wine /home/wine/.wine/drive_c/dotnet \
15+
&& rm /tmp/dotnet-install.sh /tmp/dotnet-win.zip
1216

1317
# Update dotnet workload
1418
RUN dotnet workload config --update-mode workload-set \
@@ -20,9 +24,10 @@ RUN dotnet workload config --update-mode workload-set \
2024
COPY scripts/ /opt/scripts/
2125
RUN chmod +x /opt/scripts/*.sh
2226

23-
# Create the wine-run wrapper
27+
# Create the wine-run and wine-shell wrappers
2428
RUN echo '#!/bin/bash\n/opt/scripts/wine-run.sh "$@"' > /usr/local/bin/wine-run \
25-
&& chmod +x /usr/local/bin/wine-run
29+
&& echo '#!/bin/bash\n/opt/scripts/wine-shell.sh "$@"' > /usr/local/bin/wine-shell \
30+
&& chmod +x /usr/local/bin/wine-run /usr/local/bin/wine-shell
2631

2732
USER wine
2833
WORKDIR /workspace

mtgosdk/scripts/wine-run.sh

100755100644
Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
# wine-run: Build using Linux SDK and run using Wine
23

3-
PROJECT="$1"
4-
[ "$#" -ge 1 ] && shift
5-
OUTPUT_DIR="${1:-./dist/win-x64}"
6-
[ "$#" -ge 1 ] && shift
4+
export WINEDEBUG=${WINEDEBUG:--all}
5+
export DOTNET_ROOT=C:\\dotnet
76

8-
dotnet restore
9-
dotnet publish "$PROJECT" --self-contained \
10-
-r win-x64 -p:RestoreLockedMode=false \
11-
-o "$OUTPUT_DIR"
7+
echo "--- Environment: DISPLAY=$DISPLAY, WINEDEBUG=$WINEDEBUG ---"
128

13-
if [ ! -f "$OUTPUT_DIR/$PROJECT.exe" ]; then
14-
echo "No $PROJECT.exe found in $OUTPUT_DIR"
15-
exit 1
9+
PROJECT_OR_SLN="$1"
10+
shift || true
11+
12+
if [ -z "$PROJECT_OR_SLN" ]; then
13+
PROJECT_OR_SLN="."
14+
fi
15+
16+
echo "--- Building $PROJECT_OR_SLN (win-x64, Framework-Dependent) ---"
17+
dotnet build "$PROJECT_OR_SLN"
18+
19+
# Search for the executable in the most common output paths
20+
if [ -d "bin" ]; then
21+
EXE_PATH=$(find bin -name "*.exe" | grep "win-x64" | head -n 1)
1622
fi
1723

18-
wine "$OUTPUT_DIR/$PROJECT.exe" "$@"
24+
if [ -z "$EXE_PATH" ]; then
25+
if [ -f "$PROJECT_OR_SLN" ]; then
26+
BASE_DIR=$(dirname "$PROJECT_OR_SLN")
27+
if [ -d "$BASE_DIR/bin" ]; then
28+
EXE_PATH=$(find "$BASE_DIR/bin" -name "*.exe" | grep "win-x64" | head -n 1)
29+
fi
30+
fi
31+
fi
32+
33+
if [ -f "$EXE_PATH" ]; then
34+
echo "--- Running $EXE_PATH via Wine ---"
35+
wine "$EXE_PATH" "$@"
36+
else
37+
echo "Error: Could not find win-x64 executable for $PROJECT_OR_SLN"
38+
exit 1
39+
fi

mtgosdk/scripts/wine-shell.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# wine-shell: A bash subshell with Wine-aware aliases
3+
4+
SHELL_RC=$(mktemp)
5+
cat > "$SHELL_RC" <<'BASHRC'
6+
source /etc/bash.bashrc
7+
source ~/.bashrc
8+
export WINEDEBUG=-all
9+
export DOTNET_ROOT=C:\\dotnet
10+
alias run='wine-run'
11+
alias wine-dotnet='wine C:\\dotnet\\dotnet.exe'
12+
echo "----------------------------------------------------"
13+
echo " Wine Shell Initialized"
14+
echo " 'dotnet build' -> Produces win-x64 binaries (Framework-Dependent)"
15+
echo " 'run' -> Runs 'wine-run' (Build + Wine Run)"
16+
echo " 'wine-dotnet' -> Runs the native Windows .NET SDK in Wine"
17+
echo "----------------------------------------------------"
18+
BASHRC
19+
20+
/bin/bash --rcfile "$SHELL_RC" -i
21+
rm "$SHELL_RC"

0 commit comments

Comments
 (0)