autostart_check.sh 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # autostart_check.sh <vm> <app dir | installed> [screen] - the autostart of we_manager across a real reboot: makes a
  3. # one wallpaper playlist through the running we_manager (DevTools, like wem_check.sh), sets it as the autostart playlist, reboots the VM and waits
  4. # for the session. we_manager and the engine with its wallpaper must be running again afterwards. the engine has to be installed
  5. # (wem_check.sh does it); LOGIN_PASSWORD types a password at a greeter without autologin; we_manager is started with --remote-debugging-port=9222 unless it already runs that way.
  6. HERE=$(cd "$(dirname "$0")" && pwd)
  7. vm=$1 screen=${3:-Virtual-1}
  8. sshv() { "$HERE/linuxvm.sh" ssh "$vm" "$@" </dev/null; }
  9. status=0
  10. pass() { echo "PASS $1"; }
  11. fail() { echo "FAIL $1"; status=1; }
  12. cdp() { sshv ". ~/sessenv; cd ~/wem; timeout ${CDP_TIMEOUT:-90} python3 cdp.py \"$1\" 2>&1 | cut -c1-500"; }
  13. if ! cdp 'window.electronAPI.lwe.listScreens()' | grep -q "$screen"; then
  14. sshv 'pkill -f "[w]e-manager"; true'; sleep 3
  15. if [[ $2 == installed ]]; then start="${WEM_LAUNCH:-} we-manager ${WEM_FLAGS:-}"; else start="${WEM_LAUNCH:-} ~/wem/$(basename "$2")/we-manager --no-sandbox ${WEM_FLAGS:-}"; fi
  16. sshv ". ~/sessenv; (setsid nohup $start --remote-debugging-port=9222 > ~/wem/app-auto.log 2>&1 </dev/null &); sleep 25"
  17. fi
  18. sshv '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' # the scan skips symlinked folders
  19. cdp 'window.electronAPI.library.scan()' >/dev/null
  20. # an autostarted we_manager only brings wallpapers back through its autostart playlist (or a playlist that was playing)
  21. out=$(cdp "(async () => { const p = await window.electronAPI.playlist.create('autostart-test'); await window.electronAPI.playlist.addItems(p.id, ['1120596121']); await window.electronAPI.config.setAutostart(true, true, p.id); return p.id })()")
  22. if echo "$out" | grep -q 'Traceback\|rror'; then fail "playlist for the autostart: $out"; else pass "autostart playlist made: $out"; fi
  23. entry=$(sshv 'grep "^Exec=" ~/.config/autostart/we-manager.desktop 2>/dev/null')
  24. [ -n "$entry" ] && pass "autostart entry: $entry" || { fail "no autostart entry"; exit 1; }
  25. [ -n "$WEM_FLAGS" ] && sshv "sed -i \"s|^\\(Exec=.*\\)\$|\\1 $WEM_FLAGS|\" ~/.config/autostart/we-manager.desktop" # COSMIC in the VM needs --disable-gpu-compositing
  26. sleep 5
  27. sshv 'sync; sudo systemctl reboot' >/dev/null 2>&1
  28. sleep 20
  29. up=0
  30. logged_in=0
  31. for _ in $(seq 90); do
  32. # a greeter without autologin (COSMIC): type the password once the VM answers
  33. if [ -n "$LOGIN_PASSWORD" ] && [ $logged_in = 0 ] && sshv 'true' 2>/dev/null; then
  34. sleep 25; "$HERE/linuxvm.sh" type "$vm" "$LOGIN_PASSWORD"; "$HERE/linuxvm.sh" keys "$vm" ret; logged_in=1
  35. fi
  36. sshv 'true' 2>/dev/null && sshv 'bash ~/lwe/sessenv.sh' >/dev/null 2>&1 && { up=1; break; }
  37. sleep 4
  38. done
  39. [ $up = 1 ] && pass "the VM is back with its desktop session" || { fail "no desktop session after the reboot"; exit 1; }
  40. for _ in $(seq 40); do
  41. [ "$(sshv 'pgrep -fc "[w]e-manager"')" -gt 0 ] && break
  42. sleep 3
  43. done
  44. [ "$(sshv 'pgrep -fc "[w]e-manager"')" -gt 0 ] && pass "we_manager started by the session" || fail "we_manager did not come back: $(sshv 'ls ~/.config/autostart')"
  45. for _ in $(seq 40); do
  46. [ "$(sshv 'pgrep -fc "/[l]inux-wallpaperengine(\.bin)? "')" -gt 0 ] && break
  47. sleep 3
  48. done
  49. engines=$(sshv 'pgrep -fa "/[l]inux-wallpaperengine(\.bin)? " | head -1 | cut -c1-200')
  50. [ -n "$engines" ] && pass "the engine came back: $engines" || fail "no engine after the reboot"
  51. sleep 15
  52. tmp=$(mktemp -d)
  53. "$HERE/linuxvm.sh" shot "$vm" "$tmp/after.png" && echo " screenshot of the desktop after the reboot: $tmp/after.png"
  54. exit $status