clean_install_check.sh 6.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # clean_install_check.sh <vm> <app dir | .deb> - a first install of the prebuilt engine through we_manager the way a new user
  3. # does it: no engine under ~/.local/share/linux-wallpaperengine-kde and one of the system libraries the engine leaves to the
  4. # distribution removed (libvulkan: the engine needs it, Electron does not, so we_manager keeps running; nss would be the
  5. # realistic one but Electron needs it too, and libXxf86vm takes Electron down through Mesa on X11), so the "install missing libraries" step has to run. The
  6. # candidate's portable tarball is served by fake_github.py under every asset name we_manager may ask for. Checks: the library
  7. # is gone before, the install reports installed, the library is back, the engine's own library check finds nothing missing.
  8. # Needs the session running (sessenv) and we_manager on the VM (wem_check.sh / update_check.sh put it there).
  9. # ENGINE_TARBALL the candidate's portable tarball (required)
  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. [ -f "$ENGINE_TARBALL" ] || { echo "ENGINE_TARBALL is not set to the candidate's portable tarball"; exit 2; }
  18. remove_cmd=$(sshv '. /etc/os-release; case " $ID $ID_LIKE " in
  19. *" arch "*) echo "sudo pacman -Rdd --noconfirm vulkan-icd-loader" ;;
  20. *linuxmint*) echo "sudo apt-get -o DPkg::Lock::Timeout=180 remove -y libvulkan1" ;;
  21. *" ubuntu "*|*" debian "*) echo "sudo dpkg --remove --force-depends libvulkan1" ;;
  22. *" fedora "*) echo "sudo rpm -e --nodeps vulkan-loader" ;;
  23. *suse*) echo "sudo rpm -e --nodeps libvulkan1" ;;
  24. esac')
  25. # Ubuntu 24.04 gets the distribution build, whose own libraries (freeglut and the rest) are missing on a fresh install: nothing has to be
  26. # removed there, and removing libvulkan1 leaves apt with broken dependents (dpkg) or takes the GNOME session along (apt-get remove)
  27. victim=libvulkan.so.1
  28. if sshv '. /etc/os-release; [ "$ID" = ubuntu ] || [ "$ID" = linuxmint ] || case " $ID_LIKE " in *" ubuntu "*) true;; *) false;; esac'; then victim=libglut.so.3.12; remove_cmd="sudo apt-get remove -y libglut3.12"; fi
  29. if [ -z "$remove_cmd" ]; then echo "SKIP clean install: no way to remove a system library on this distribution"; exit 0; fi
  30. if sshv 'touch /usr/.lwe-rw 2>/dev/null && rm /usr/.lwe-rw' || sshv 'sudo touch /usr/.lwe-rw 2>/dev/null && sudo rm /usr/.lwe-rw'; then :; else
  31. echo "SKIP clean install: read-only system, libraries cannot be installed here"; exit 0
  32. fi
  33. work=$(mktemp -d)
  34. engine_tag=v98.0.$(date +%s)
  35. for variant in kde generic; do
  36. for distro in portable ubuntu-24.04 fedora-44; do cp "$ENGINE_TARBALL" "$work/linux-wallpaperengine-$variant-$distro-x86_64.tar.gz"; done
  37. done
  38. assets=$(ls "$work"/*.tar.gz | paste -sd,)
  39. mkdir -p "$work/certs"
  40. . "$HERE/fake_github_lib.sh"
  41. fgh_start "$vm" "$work" --release "WallpaperEngineLover/linux-wallpaperengine-kde=$engine_tag:$assets"
  42. trap 'kill $fake 2>/dev/null; rm -rf "$work"; sshv "pkill -f \"[w]e-manager\" 2>/dev/null; sudo sed -i \"/api.github.com/d\" /etc/hosts; true" >/dev/null 2>&1' EXIT
  43. sleep 3
  44. kill -0 $fake 2>/dev/null || { cat "$work/fake.log"; echo "fake_github did not start (port 443?)"; exit 2; }
  45. sshv 'mkdir -p ~/wem'
  46. if [ -d "$app" ]; then
  47. tar -C "$(dirname "$app")" -cf - "$(basename "$app")" | ssh -i "$HOME/.local/share/linuxvm/id_ed25519" -p "$(cat "$HOME/.local/share/linuxvm/vms/$vm/port")" \
  48. -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR lab@127.0.0.1 'mkdir -p ~/wem && tar -C ~/wem -xf -'
  49. fi
  50. "$HERE/linuxvm.sh" scp "$vm" "$work/certs/ca.pem" wem/fake-ca.pem
  51. "$HERE/linuxvm.sh" scp "$vm" "$HERE/cdp.py" wem/cdp.py
  52. sshv 'grep -q "api.github.com" /etc/hosts || echo "10.0.2.2 api.github.com" | sudo tee -a /etc/hosts >/dev/null
  53. sudo mkdir -p /etc/polkit-1/rules.d
  54. 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
  55. pkill -f "[w]e-manager" 2>/dev/null; for _ in $(seq 20); do pgrep -f "[w]e-manager" >/dev/null || break; sleep 1; done; rm -rf ~/.local/share/linux-wallpaperengine-kde; true'
  56. sleep 2
  57. if [[ $app == *.deb ]]; then
  58. "$HERE/linuxvm.sh" scp "$vm" "$app" wem/app.deb
  59. sshv 'sudo DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=300 install -y --allow-downgrades ./wem/app.deb >/tmp/wem-deb.log 2>&1'
  60. fi
  61. 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
  62. sshv ". ~/sessenv; export NODE_EXTRA_CA_CERTS=\$HOME/wem/fake-ca.pem; (setsid nohup $start --remote-debugging-port=9222 > ~/wem/app-clean.log 2>&1 </dev/null &); for _ in \$(seq 40); do grep -q 'DevTools listening' ~/wem/app-clean.log 2>/dev/null && break; sleep 1; done; sleep 8"
  63. [ "$(sshv 'pgrep -fc "[w]e-manager"')" -gt 0 ] || { fail "clean install: we_manager did not start: $(sshv 'tail -3 ~/wem/app-clean.log')"; exit 1; }
  64. sshv "$remove_cmd" > /tmp/lwe-clean-remove.log 2>&1
  65. if sshv "/sbin/ldconfig -p | grep -q \"$victim (libc6,x86-64)\""; then fail "clean install: $victim is still installed after '$remove_cmd'"; exit 1; fi
  66. pass "clean install: no engine and no $victim on the system"
  67. # installPrebuilt resolves with the engine status either way, the outcome comes as progress events
  68. expr='(async () => { const seen = []; const off = window.electronAPI.on.lweInstallProgress(p => seen.push(p.stage + ": " + p.message)); const status = await window.electronAPI.lwe.installPrebuilt(); off(); return { installed: status.installed, last: seen.slice(-3) }; })()'
  69. out=$(sshv ". ~/sessenv; cd ~/wem; NODE_EXTRA_CA_CERTS=\$HOME/wem/fake-ca.pem timeout 900 python3 cdp.py '$expr' 2>&1 | cut -c1-700")
  70. if echo "$out" | grep -q '"installed": true' && ! echo "$out" | grep -q 'error: '; then pass "clean install: we_manager installed the engine"
  71. else fail "clean install: the install failed: $out"; fi
  72. if [ "$victim" = libglut.so.3.12 ]; then echo "SKIP clean install: the test tarball bundles $victim, nothing has to be installed on the way"
  73. elif sshv "/sbin/ldconfig -p | grep -q \"$victim (libc6,x86-64)\""; then pass "clean install: the missing system library was installed on the way"
  74. else fail "clean install: $victim is still missing after the install"; fi
  75. engine=$(sshv 'find ~/.local/share/linux-wallpaperengine-kde -maxdepth 2 -name linux-wallpaperengine -type f | head -1')
  76. missing=$(sshv "$engine --check-libraries 2>&1 | grep -c 'not found'")
  77. if [ "$missing" = 0 ]; then pass "clean install: the engine finds all its libraries"; else fail "clean install: $missing libraries still not found"; fi
  78. 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; true'
  79. exit $status