From a3c2afc3fa5d6e3e2f78c25cbf7aa349a3b2e489 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Mon, 28 Mar 2022 20:09:34 -0500 Subject: [PATCH] Install Playwright to control Firefox [Playwright] is a cross-browser automation framework, intended for automating browser-based GUI application tests. It also works as a general remote-control tool for automating basically anything having to do with a browser. Playwright requires a special Firefox binary that it manages itself. To avoid downloading and installing Playwright and Firefox, and thus storing them in memory, we need them to be already available in the rootfs image. Since I want the control software to be updated easily, without rebooting the machine, I decided to separate it into its own project, [Voonex]. A short shell script to install/update and run it is launched by the systemd user instance. [Playwright]: https://playwright.dev/ [Voonex]: https://git.pyrocufflink.blue/dustin/voonex --- ci/Dockerfile | 1 + mkrootfs.sh | 16 +++++++++++++++- overlay/etc/systemd/system/xinit@.service | 2 +- overlay/etc/systemd/user/basementhud.service | 7 +++++++ overlay/etc/systemd/user/firefox.service | 9 --------- overlay/etc/systemd/user/graphical.target | 4 ---- .../user/graphical.target.wants/firefox.service | 1 - overlay/home/user/.xinitrc | 2 +- overlay/usr/local/bin/basementhud | 10 ++++++++++ 9 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 overlay/etc/systemd/user/basementhud.service delete mode 100644 overlay/etc/systemd/user/firefox.service delete mode 100644 overlay/etc/systemd/user/graphical.target delete mode 120000 overlay/etc/systemd/user/graphical.target.wants/firefox.service create mode 100755 overlay/usr/local/bin/basementhud diff --git a/ci/Dockerfile b/ci/Dockerfile index 3c7d506..ece3546 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -10,6 +10,7 @@ RUN dnf install -y \ findutils \ make \ openssh-clients \ + python3-pip \ rsync \ squashfs-tools \ tar \ diff --git a/mkrootfs.sh b/mkrootfs.sh index 1201bfa..c8a7b91 100644 --- a/mkrootfs.sh +++ b/mkrootfs.sh @@ -19,7 +19,6 @@ echo install_weak_deps=False >> "${destdir}"/etc/dnf/dnf.conf dnf --installroot "${destdir}" install -y \ bcm2711-firmware \ dracut-network \ - firefox \ hostname \ kmod \ mesa-dri-drivers \ @@ -65,6 +64,21 @@ chroot "${destdir}" systemctl enable \ systemd-timesyncd \ xinit@user +if ! [ -f "${destdir}"/usr/local/bin/playwright ]; then + python3 -m pip \ + install \ + --prefix "${destdir}"/usr/local \ + playwright +fi +if ! [ -d "${destdir}"/usr/local/ms-playwright ]; then + py_site_dir=$( + "${destdir}"/usr/bin/python3 -c 'import site;print(site.getsitepackages()[0])' + ) + PLAYWRIGHT_BROWSERS_PATH="${destdir}"/usr/local/ms-playwright \ + PYTHONPATH="${destdir}${py_site_dir}" \ + python3 -m playwright install firefox +fi + umask 0022 mksquashfs "${destdir}" "${destdir}/boot/${dest}" \ -comp lz4 \ diff --git a/overlay/etc/systemd/system/xinit@.service b/overlay/etc/systemd/system/xinit@.service index 0d9a5cb..f051747 100644 --- a/overlay/etc/systemd/system/xinit@.service +++ b/overlay/etc/systemd/system/xinit@.service @@ -14,7 +14,7 @@ TTYPath=/dev/tty7 StandardInput=tty StandardOutput=journal StandardError=journal -ExecStart=/usr/bin/startx +ExecStart=/usr/bin/startx -- -nocursor Restart=always [Install] diff --git a/overlay/etc/systemd/user/basementhud.service b/overlay/etc/systemd/user/basementhud.service new file mode 100644 index 0000000..4af7fb8 --- /dev/null +++ b/overlay/etc/systemd/user/basementhud.service @@ -0,0 +1,7 @@ +[Unit] +Description=Basement HUD + +[Service] +Type=simple +Environment=PLAYWRIGHT_BROWSERS_PATH=/usr/local/ms-playwright +ExecStart=/usr/local/bin/basementhud diff --git a/overlay/etc/systemd/user/firefox.service b/overlay/etc/systemd/user/firefox.service deleted file mode 100644 index ee4ac29..0000000 --- a/overlay/etc/systemd/user/firefox.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Firefox web browser - -[Service] -Type=simple -ExecStart=/usr/bin/firefox -Restart=always -StandardInput=null -StandardOutput=journal diff --git a/overlay/etc/systemd/user/graphical.target b/overlay/etc/systemd/user/graphical.target deleted file mode 100644 index 3830c13..0000000 --- a/overlay/etc/systemd/user/graphical.target +++ /dev/null @@ -1,4 +0,0 @@ -[Unit] -Description=Graphical Interface -After=default.target -AllowIsolate=yes diff --git a/overlay/etc/systemd/user/graphical.target.wants/firefox.service b/overlay/etc/systemd/user/graphical.target.wants/firefox.service deleted file mode 120000 index 9b4b5e4..0000000 --- a/overlay/etc/systemd/user/graphical.target.wants/firefox.service +++ /dev/null @@ -1 +0,0 @@ -../firefox.service \ No newline at end of file diff --git a/overlay/home/user/.xinitrc b/overlay/home/user/.xinitrc index b6ceb1a..2f3a150 100644 --- a/overlay/home/user/.xinitrc +++ b/overlay/home/user/.xinitrc @@ -3,5 +3,5 @@ xset s off xset -dpms systemctl --user import-environment DISPLAY -systemctl --user start graphical.target +systemctl --user start basementhud.service exec openbox diff --git a/overlay/usr/local/bin/basementhud b/overlay/usr/local/bin/basementhud new file mode 100755 index 0000000..fd77077 --- /dev/null +++ b/overlay/usr/local/bin/basementhud @@ -0,0 +1,10 @@ +#!/bin/sh + +python3 -m ensurepip +python3 -m pip install -U pip +python3 -m pip install \ + --user \ + --find-links https://files.pyrocufflink.blue/wheels/voonex \ + --upgrade \ + voonex +exec python3 -m voonex