---
# System prepended metadata

title: custom_startup.sh

---

#!/usr/bin/env bash
chmod +x /app/notify.sh

mkdir -p /home/kasm-user/.config/oxwu/
cp /tmp/settings.json /home/kasm-user/.config/oxwu/settings.json
sed -i "s/\"townID\":.*/\"townID\": $OXWU_TOWN_ID,/g" /home/kasm-user/.config/oxwu/settings.json
sed -i "s/\"alertIntensity\":.*/\"alertIntensity\": $OXWU_ALERT_INTENSITY,/g" /home/kasm-user/.config/oxwu/settings.json

/Applications/oxwu-linux-x86_64.AppImage --no-sandbox &

# 移動滑鼠游標
screen_resolution=$(xrandr | grep -oP '\d{3,4}x\d{3,4}' | head -n 1)
xdotool mousemove $(echo $screen_resolution | cut -d 'x' -f 1) $(echo $screen_resolution | cut -d 'x' -f 2)

# 顯示一個時鐘
if [ "$OXWU_XCLOCK" = true ] ; then
    sleep 10
    /usr/bin/xclock -digital \
        -fg "#222222" \
        -bg "#CECECE" \
        -face "文泉驛正黑:style=Bold" \
        -strftime "%Y-%m-%d %H:%M:%S ${OXWU_TOWN_NAME}" \
        -update 1 &

    sleep 1
    # 把時鐘移到左上角
    XCLOCK_WIN_ID=`VNC=:0 wmctrl -l | grep xclock | awk '{print $1}'`
    VNC=:0 wmctrl -i -r ${XCLOCK_WIN_ID} -b add,above
    VNC=:0 wmctrl -i -r ${XCLOCK_WIN_ID} -e 0,40,0,-1,-1
fi

# 串流畫面
if [ "$OXWU_RTMP_URL" = "" ]
then
    echo "無串流網址不啟動串流"
else
    echo "啟動畫面串流…"
    ffmpeg \
        -framerate 30 \
        -video_size 1008x726 \
        -f x11grab \
        -i :1 \
        -f pulse \
        -i default \
        -c:v libx264 \
        -b:v 5000k \
        -maxrate 5000k \
        -bufsize 10000k \
        -g 60 \
        -vf format=yuv420p \
        -c:a aac \
        -b:a 128k \
        -f flv \
        ${OXWU_RTMP_URL}