update_check.sh 6.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # update_check.sh <vm> <app dir | .deb> - we_manager's update flow in a VM's desktop session against fake_github.py on
  3. # this host: an app release (the candidate's .deb with a newer Version) and an engine release (the portable tarball under
  4. # a newer tag). Checks that both updates are offered, the engine update installs, and for a .deb install that the app
  5. # update downloads, installs through polkit (a rule for the lab user stands in for the dialog) and the package version
  6. # changes. Other install kinds (an unpacked AppImage, Flatpak) are expected to only get the notice. Needs the session
  7. # running (sessenv) and the candidate's we_manager unpacked/installed the way wem_check.sh does.
  8. # APP_DEB .deb to serve as the new app release (default: the one next to the app dir's dist folder)
  9. # ENGINE_TARBALL portable engine tarball to serve (default ~/.local/share/distro-rootfs/out/linux-wallpaperengine-kde-portable-x86_64.tar.gz)
  10. HERE=$(cd "$(dirname "$0")" && pwd)
  11. vm=$1 app=$2
  12. sshv() { "$HERE/linuxvm.sh" ssh "$vm" "$@" </dev/null; }
  13. status=0
  14. pass() { echo "PASS $1"; }
  15. fail() { echo "FAIL $1"; status=1; }
  16. cdp() { sshv ". ~/sessenv; cd ~/wem; NODE_EXTRA_CA_CERTS= timeout ${CDP_TIMEOUT:-90} python3 cdp.py \"$1\" 2>&1 | cut -c1-${2:-700}"; }
  17. work=$(mktemp -d)
  18. engine_tag=v99.0.$(date +%s) # newer than whatever engine the VM has, a golden disk may hold an earlier run's
  19. deb=${APP_DEB:-}
  20. if [ -z "$deb" ]; then
  21. for candidate in "$(dirname "$app")"/*.deb "$(dirname "$app")"/../*.deb; do [ -f "$candidate" ] && deb=$candidate && break; done
  22. fi
  23. engine=${ENGINE_TARBALL:-$HOME/.local/share/distro-rootfs/out/linux-wallpaperengine-kde-portable-x86_64.tar.gz}
  24. app_release=()
  25. if [ -f "$deb" ]; then
  26. python3 "$HERE/bump_deb.py" "$deb" "$work/we-manager_0.9.9_amd64.deb" 0.9.9
  27. app_release=(--release "WallpaperEngineLover/we_manager=v0.9.9:$work/we-manager_0.9.9_amd64.deb")
  28. else
  29. echo "SKIP app update: no .deb to serve as the new app release (APP_DEB), only the engine update is checked"
  30. fi
  31. cp "$engine" "$work/linux-wallpaperengine-kde-portable-x86_64.tar.gz"
  32. cp "$engine" "$work/linux-wallpaperengine-generic-portable-x86_64.tar.gz"
  33. mkdir -p "$work/certs"
  34. . "$HERE/fake_github_lib.sh"
  35. fgh_start "$vm" "$work" \
  36. "${app_release[@]}" \
  37. --release "WallpaperEngineLover/linux-wallpaperengine-kde=$engine_tag:$work/linux-wallpaperengine-kde-portable-x86_64.tar.gz,$work/linux-wallpaperengine-generic-portable-x86_64.tar.gz"
  38. trap 'kill $fake 2>/dev/null; rm -rf "$work"' EXIT
  39. sleep 3
  40. kill -0 $fake 2>/dev/null || { cat "$work/fake.log"; echo "fake_github did not start (port 443?)"; exit 2; }
  41. sshv 'mkdir -p ~/wem'
  42. if [ -d "$app" ] && ! sshv "test -x ~/wem/$(basename "$app")/we-manager"; then # the app is not on the VM yet: copy it like wem_check.sh
  43. tar -C "$(dirname "$app")" -cf - "$(basename "$app")" | ssh -i "$HOME/.local/share/linuxvm/id_ed25519" -p "$(cat "$HOME/.local/share/linuxvm/vms/$vm/port")" \
  44. -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR lab@127.0.0.1 'mkdir -p ~/wem && tar -C ~/wem -xf -'
  45. fi
  46. "$HERE/linuxvm.sh" scp "$vm" "$work/certs/ca.pem" wem/fake-ca.pem
  47. "$HERE/linuxvm.sh" scp "$vm" "$HERE/cdp.py" wem/cdp.py
  48. sshv 'grep -q "api.github.com" /etc/hosts || echo "10.0.2.2 api.github.com" | sudo tee -a /etc/hosts >/dev/null
  49. sudo mkdir -p /etc/polkit-1/rules.d
  50. printf "polkit.addRule(function(action, subject) { if (subject.user == \"lab\") return polkit.Result.YES; });\n" | sudo tee /etc/polkit-1/rules.d/49-lab-test.rules >/dev/null
  51. pkill -f "[w]e-manager" 2>/dev/null; for _ in $(seq 20); do pgrep -f "[w]e-manager" >/dev/null || break; sleep 1; done; true'
  52. sleep 2
  53. if [[ $app == *.deb ]]; then
  54. "$HERE/linuxvm.sh" scp "$vm" "$app" wem/app.deb
  55. sshv 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-downgrades ./wem/app.deb >/tmp/wem-deb.log 2>&1'
  56. fi
  57. if [[ $app == *.deb ]]; then start="${WEM_LAUNCH:-} we-manager ${WEM_FLAGS:-}"; else start="${WEM_LAUNCH:-} ~/wem/$(basename "$app")/we-manager --no-sandbox ${WEM_FLAGS:-}"; fi
  58. sshv ". ~/sessenv; export NODE_EXTRA_CA_CERTS=\$HOME/wem/fake-ca.pem; (setsid nohup $start --remote-debugging-port=9222 > ~/wem/app-update.log 2>&1 </dev/null &); for _ in \$(seq 40); do grep -q 'DevTools listening' ~/wem/app-update.log 2>/dev/null && break; sleep 1; done; sleep 8"
  59. [ "$(sshv 'pgrep -fc "[w]e-manager"')" -gt 0 ] && pass "we_manager starts" || { fail "we_manager did not start: $(sshv 'tail -3 ~/wem/app-update.log')"; exit 1; }
  60. out=$(cdp 'window.electronAPI.updates.setChecks({app: true, engine: true})' 1500)
  61. out=$(cdp 'window.electronAPI.updates.check()' 2500); echo " $out" | tr '\n' ' ' | cut -c1-600; echo
  62. kind=$(echo "$out" | grep -o '"appInstall": "[^"]*"' | cut -d'"' -f4)
  63. if [ -f "$deb" ]; then
  64. echo "$out" | grep -q '"version": "0.9.9"\|"version": "v0.9.9"' && pass "app update 0.9.9 offered (install kind $kind)" || fail "app update not offered"
  65. fi
  66. if echo "$out" | grep -q "$engine_tag"; then pass "engine update $engine_tag offered"
  67. elif echo "$out" | grep -q '"engineInstall": null'; then echo "SKIP engine update offer: no engine installed through we_manager on this VM yet"
  68. else fail "engine update not offered"; fi
  69. if [ "$kind" = deb ]; then
  70. out=$(cdp 'window.electronAPI.updates.installApp()' 1500); sleep 20
  71. version=$(sshv 'dpkg-query -W -f="\${Version}" we-manager 2>/dev/null')
  72. [ "$version" = 0.9.9 ] && pass "the .deb update installed (we-manager $version)" || fail "after installApp the package is $version: $out"
  73. else
  74. echo "SKIP app install: install kind '$kind' only gets the notice"
  75. fi
  76. # the app restarts after its own .deb update, a loaded guest takes a while before the debugging port answers again
  77. for _ in $(seq 30); do [ "$(cdp '1 + 1' 20)" = 2 ] && break; sleep 3; done
  78. # an app that restarts after its own update can drop the first call (empty answer), ask again
  79. for _ in 1 2 3; do
  80. out=$(sshv ". ~/sessenv; cd ~/wem; timeout 400 python3 cdp.py 'window.electronAPI.lwe.installPrebuilt()' 2>&1 | cut -c1-300")
  81. [ -n "$out" ] && break
  82. sleep 20
  83. done
  84. if echo "$out" | grep -q '"installed": true'; then pass "engine update installed through the prebuilt install: $(echo "$out" | grep -o '"version": "[^"]*"')"; else fail "engine update failed: $out"; fi
  85. grep -c "GET" "$work/fake.log" | xargs -I{} echo " {} requests reached the fake api.github.com"
  86. sshv 'pkill -f "[w]e-manager" 2>/dev/null; for _ in $(seq 20); do pgrep -f "[w]e-manager" >/dev/null || break; sleep 1; done; sudo rm -f /etc/polkit-1/rules.d/49-lab-test.rules; sudo sed -i "/api.github.com/d" /etc/hosts; true'
  87. exit $status