flatpak_check.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. # flatpak_check.sh <vm> <bundle.flatpak | installed> [screen] - the Flatpak build of we_manager in a VM's desktop session:
  3. # installs the bundle (unless "installed"), starts it with DevTools (cdp.py reaches it, the sandbox shares the network),
  4. # scans the library, launches a scene and a web wallpaper through it, checks stop and kill all leave nothing behind and
  5. # the autostart entry starts the Flatpak. Needs flatpak and the 25.08 runtime + Electron BaseApp on the VM, and the
  6. # session running (sessenv). One PASS|FAIL line per check.
  7. HERE=$(cd "$(dirname "$0")" && pwd)
  8. vm=$1 bundle=$2 screen=${3:-Virtual-1}
  9. app=io.github.WallpaperEngineLover.we_manager
  10. sshv() { "$HERE/linuxvm.sh" ssh "$vm" "$@" </dev/null; }
  11. status=0
  12. pass() { echo "PASS $1"; }
  13. fail() { echo "FAIL $1"; status=1; }
  14. cdp() { sshv ". ~/sessenv; cd ~/wem; timeout ${CDP_TIMEOUT:-90} python3 cdp.py \"$1\" 2>&1 | cut -c1-500"; }
  15. # gone: waits up to 20 s for the engines and web helpers to end, a stop in a Flatpak goes through flatpak-spawn
  16. gone() { for _ in $(seq 20); do [ "$(left)" = "0 0" ] && return 0; sleep 1; done; return 1; }
  17. left() { sshv 'echo $(pgrep -fc "/[l]inux-wallpaperengine(\.bin)? ") $(pgrep -fc "[w]eb-helper")'; }
  18. sshv 'mkdir -p ~/wem'
  19. "$HERE/linuxvm.sh" scp "$vm" "$HERE/cdp.py" wem/cdp.py
  20. if [ "$bundle" != installed ]; then
  21. "$HERE/linuxvm.sh" scp "$vm" "$bundle" wem/app.flatpak
  22. sshv "flatpak --user remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo; flatpak --user install -y --noninteractive --reinstall ~/wem/app.flatpak >/tmp/fp-install.log 2>&1" && pass "the bundle installs" || fail "bundle install: $(sshv 'tail -3 /tmp/fp-install.log')"
  23. fi
  24. sshv 'pkill -f "[w]e-manager" 2>/dev/null; true'
  25. sshv 'mkdir -p ~/.steam/steam/steamapps/common/wallpaper_engine ~/.steam/steam/steamapps/workshop/content/431960
  26. ln -sfn ~/lwe/assets ~/.steam/steam/steamapps/common/wallpaper_engine/assets
  27. cd ~/.steam/steam/steamapps/workshop/content/431960; for id in 1120596121 1078208425; do [ -L $id ] && rm $id; [ -d $id ] || cp -al ~/lwe/wp-$id $id; done'
  28. sshv ". ~/sessenv; (setsid nohup flatpak run $app --remote-debugging-port=9222 > ~/wem/fp-app.log 2>&1 </dev/null &); sleep 30"
  29. [ "$(sshv 'pgrep -fc "[w]e-manager"')" -gt 0 ] && pass "the Flatpak starts" || { fail "the Flatpak did not start: $(sshv 'tail -3 ~/wem/fp-app.log')"; exit 1; }
  30. out=$(cdp 'window.electronAPI.lwe.prebuiltTarget()'); echo " prebuilt target: $out" | cut -c1-200
  31. out=$(cdp 'window.electronAPI.lwe.status ? window.electronAPI.lwe.status() : window.electronAPI.lwe.getStatus()')
  32. echo "$out" | grep -q '"installed": true' && pass "the bundled engine is found: $(echo "$out" | grep -o '"path": "[^"]*"')" || fail "no engine inside the Flatpak: $out"
  33. out=$(cdp 'window.electronAPI.lwe.listScreens()')
  34. echo "$out" | grep -q "$screen" && pass "screens found through the host: $out" || fail "screen $screen not found: $out"
  35. cdp 'window.electronAPI.library.scan()' > /dev/null
  36. home=$(sshv 'echo $HOME')/.steam/steam/steamapps/workshop/content/431960
  37. for id in 1120596121 1078208425; do
  38. out=$(cdp "window.electronAPI.lwe.launch('$home/$id', {screen: '$screen'})"); sleep 35
  39. engines=$(sshv 'pgrep -fc "/[l]inux-wallpaperengine(\.bin)? "')
  40. if echo "$out" | grep -q '"running": true' && [ "$engines" -gt 0 ]; then pass "$id launched from the Flatpak ($engines engine processes)"; else fail "$id did not launch: $out"; fi
  41. cdp 'window.electronAPI.lwe.stop()' >/dev/null
  42. gone && pass "$id: stop leaves nothing behind" || fail "$id: after stop engines/helpers: $(left)"
  43. done
  44. cdp "window.electronAPI.lwe.launch('$home/1078208425', {screen: '$screen'})" >/dev/null; sleep 30
  45. cdp 'window.electronAPI.lwe.killAll()' >/dev/null
  46. gone && pass "kill all leaves nothing behind" || fail "after kill all engines/helpers: $(left)"
  47. cdp 'window.electronAPI.config.setAutostart(true, true, null)' >/dev/null
  48. entry=$(sshv 'grep "^Exec=" ~/.config/autostart/*.desktop 2>/dev/null')
  49. echo "$entry" | grep -q "flatpak run" && pass "autostart starts the Flatpak: $entry" || fail "autostart entry does not start the Flatpak: $entry"
  50. sshv 'pkill -f "[w]e-manager" 2>/dev/null; true'
  51. exit $status