diff --git a/Dockerfile b/Dockerfile index 9447371..c4fad47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,12 @@ RUN apt update && apt install -y \ pev \ sudo \ vim \ + xdotool \ + supervisor \ + x11vnc \ + novnc \ + xvfb \ + fluxbox \ && apt-get autoremove -y \ && apt-get clean \ && rm -fr /tmp/* diff --git a/container_root/bin/wechat-monitor b/container_root/bin/wechat-monitor new file mode 100755 index 0000000..83321f3 --- /dev/null +++ b/container_root/bin/wechat-monitor @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# ref: https://github.com/ChisBread/wechat-box/blob/master/root/bin/wechat-monitor +function errmonitor() { + while : + do + for i in `xdotool search --onlyvisible --class WeChat.exe` + do + NAME=`xdotool getwindowname $i` + echo "window name: $NAME" + if [ "$NAME" == "" ] || [ "$NAME" == "微信电脑版更新" ]; then + xdotool windowunmap $i + fi + done + for i in `xdotool search --onlyvisible --class wine` + do + NAME=`xdotool getwindowname $i` + echo "window name: $NAME" + if [ "$NAME" == "程序错误" ]; then + xdotool windowkill $i + fi + done + sleep 2 + done +} +errmonitor diff --git a/container_root/entrypoint.sh b/container_root/entrypoint.sh index 784d7f6..aeada1b 100755 --- a/container_root/entrypoint.sh +++ b/container_root/entrypoint.sh @@ -28,7 +28,32 @@ function setupFontDpi () { /f \ > /dev/null 2>&1 } - +function startVNC () { + VNC_DISPLAY_WIDTH=${VNC_DISPLAY_WIDTH:-1280} + VNC_DISPLAY_HEIGHT=${VNC_DISPLAY_HEIGHT:-720} + # VNC_DISPLAY for multi xserver + VNC_DISPLAY=${VNC_DISPLAY:-${DISPLAY:-:0}} + NOVNC_PORT=${NOVNC_PORT:-8080} + # TODO: + # use xf86 instead of xvfb + # https://bugs.chromium.org/p/chromium/issues/detail?id=596125 + # https://github.com/freedesktop/xorg-xf86-video-dummy + [ ! -f /etc/supervisord.d/xvfb.conf ] \ + && mv /etc/supervisord.d/xvfb.conf.disable /etc/supervisord.d/xvfb.conf \ + && mv /etc/supervisord.d/wechat-monitor.conf.disable /etc/supervisord.d/wechat-monitor.conf + [ -d /tmp/.X11-unix ] \ + && mv /etc/supervisord.d/xvfb.conf /etc/supervisord.d/xvfb.conf.disable \ + && mv /etc/supervisord.d/wechat-monitor.conf /etc/supervisord.d/wechat-monitor.conf.disable + echo "[DoChat] VNCServer Starting..." + exec sudo -E bash -c \ + "DISPLAY=${VNC_DISPLAY} NOVNC_PORT=${NOVNC_PORT} \ + VNC_DISPLAY_WIDTH=${VNC_DISPLAY_WIDTH} VNC_DISPLAY_HEIGHT=${VNC_DISPLAY_HEIGHT} \ + supervisord -c /etc/supervisord.conf -l /var/log/supervisord.log" & + while true; do + [ -d /tmp/.X11-unix ] && break + sleep 1 + done +} # # WeChat # @@ -39,7 +64,15 @@ function startWechat () { /dochat/patch-hosts.sh /dochat/disable-upgrade.sh - + VNC_SERVER=${VNC_SERVER:-no} + [ ! -d /tmp/.X11-unix ] \ + && echo "[DoChat] Headless mode. Dummy DISPLAY=${DISPLAY:-:0}" \ + && export DISPLAY=${DISPLAY:-:0} + case $VNC_SERVER in + true|yes|y|1) + startVNC + ;; + esac if [ -n "$DOCHAT_DEBUG" ]; then unset WINEDEBUG wine reg query 'HKEY_CURRENT_USER\Software\Tencent\WeChat' || echo 'Register for Wechat not found ?' diff --git a/container_root/etc/supervisord.conf b/container_root/etc/supervisord.conf new file mode 100644 index 0000000..64a1fb8 --- /dev/null +++ b/container_root/etc/supervisord.conf @@ -0,0 +1,5 @@ +[supervisord] +nodaemon=true + +[include] +files = /etc/supervisord.d/*.conf diff --git a/container_root/etc/supervisord.d/fluxbox.conf b/container_root/etc/supervisord.d/fluxbox.conf new file mode 100644 index 0000000..96793ad --- /dev/null +++ b/container_root/etc/supervisord.d/fluxbox.conf @@ -0,0 +1,3 @@ +[program:fluxbox] +command=fluxbox +autorestart=true diff --git a/container_root/etc/supervisord.d/websockify.conf b/container_root/etc/supervisord.d/websockify.conf new file mode 100644 index 0000000..aae8288 --- /dev/null +++ b/container_root/etc/supervisord.d/websockify.conf @@ -0,0 +1,3 @@ +[program:websockify] +command=websockify --web /usr/share/novnc %(ENV_NOVNC_PORT)s localhost:5900 +autorestart=true diff --git a/container_root/etc/supervisord.d/wechat-monitor.conf b/container_root/etc/supervisord.d/wechat-monitor.conf new file mode 100644 index 0000000..1f903a5 --- /dev/null +++ b/container_root/etc/supervisord.d/wechat-monitor.conf @@ -0,0 +1,3 @@ +[program:wechat-monitor] +command=wechat-monitor +autorestart=true \ No newline at end of file diff --git a/container_root/etc/supervisord.d/x11vnc.conf b/container_root/etc/supervisord.d/x11vnc.conf new file mode 100644 index 0000000..2fff49a --- /dev/null +++ b/container_root/etc/supervisord.d/x11vnc.conf @@ -0,0 +1,3 @@ +[program:x11vnc] +command=x11vnc -forever -shared +autorestart=true diff --git a/container_root/etc/supervisord.d/xvfb.conf b/container_root/etc/supervisord.d/xvfb.conf new file mode 100644 index 0000000..1e18e7f --- /dev/null +++ b/container_root/etc/supervisord.d/xvfb.conf @@ -0,0 +1,3 @@ +[program:xvfb] +command=Xvfb %(ENV_DISPLAY)s -screen 0 "%(ENV_VNC_DISPLAY_WIDTH)s"x"%(ENV_VNC_DISPLAY_HEIGHT)s"x24 -listen tcp -ac +autorestart=true