#!/bin/sh # Install the Circle Signage player on Raspberry Pi OS Lite (Bookworm or # later) or Armbian (Debian/Ubuntu based), 64-bit. # # sudo ./install.sh ./signage-player # first-boot setup on the screen # sudo ./install.sh ./signage-player https://signage.example.org # address stored now # # It installs the runtime libraries (EGL, GLES, GBM, DRM and the Mesa # drivers), creates the `signage` user in the video/render groups, installs # the binary, the config and the systemd unit, lets the player manage # NetworkManager (first-boot Wi-Fi setup) and reboot the device, and enables # the service. Run renderdemo first on new hardware (see README.md). # # Without a server address the screen starts first-boot setup: a setup # Wi-Fi network and a page to enter the server address (and Wi-Fi). With # one, it is stored as the player's own setting (erased by a full reset, # like everything else) and the screen goes straight to pairing. # # The download site's one-line installer (site/player/install.sh) downloads # a release binary and the files in this directory and runs this script # with them, so its interface (the binary and optional address as arguments, # README.md, player.conf.example and signage-player.service next to it) is # relied on there. It sets SIGNAGE_PLAYER_INSTALL_URL, so the messages below # show its command instead of this script's. Running it again upgrades. set -eu BIN=${1:?usage: install.sh path/to/signage-player [SERVER_URL]} SERVER=${2:-} HERE=$(cd "$(dirname "$0")" && pwd) if [ -n "${SIGNAGE_PLAYER_INSTALL_URL:-}" ]; then WITH_SERVER="curl -fsSL $SIGNAGE_PLAYER_INSTALL_URL | sudo env SIGNAGE_ALLOW_NO_NM=1 bash -s -- --server https://signage.example.org" else WITH_SERVER="sudo SIGNAGE_ALLOW_NO_NM=1 ./install.sh ./signage-player https://signage.example.org" fi DATA=/var/lib/signage-player CONF=/etc/signage-player/player.conf if [ "$(id -u)" -ne 0 ]; then echo "install.sh: run as root (sudo)" >&2 exit 1 fi case "$(uname -m)" in aarch64 | x86_64) ;; *) echo "install.sh: $(uname -m) is not supported (64-bit ARM or x86-64 only)" >&2; exit 1 ;; esac # First-boot setup (hotspot, Wi-Fi join, full reset forgetting Wi-Fi) works # through NetworkManager. Installing it here would take over networking on a # board configured some other way (and could cut this SSH session), so it is # a requirement, not something this script switches on. NM=yes if ! command -v nmcli >/dev/null 2>&1 || ! systemctl is-active --quiet NetworkManager.service; then NM=no if [ "${SIGNAGE_ALLOW_NO_NM:-}" != "1" ]; then cat >&2 < Network; elsewhere: apt install network-manager and move the connection over, from the console rather than SSH), or install without first-boot setup and give the server address: $WITH_SERVER Without NetworkManager the player can't show a setup network, and a full reset can't forget saved Wi-Fi networks. EOF exit 1 fi if [ -z "$SERVER" ]; then echo "install.sh: without NetworkManager, give the server address: $WITH_SERVER" >&2 exit 1 fi echo "install.sh: continuing without NetworkManager (SIGNAGE_ALLOW_NO_NM=1): no first-boot setup network" >&2 fi echo "== packages" apt-get update PKGS="libegl1 libgles2 libgbm1 libdrm2 libegl-mesa0 libgl1-mesa-dri mesa-utils-bin ca-certificates" # NetworkManager's shared (hotspot) mode runs dnsmasq from dnsmasq-base. [ "$NM" = yes ] && PKGS="$PKGS dnsmasq-base" # shellcheck disable=SC2086 apt-get install -y --no-install-recommends $PKGS echo "== user" if ! id signage >/dev/null 2>&1; then useradd --system --home-dir "$DATA" --no-create-home --shell /usr/sbin/nologin signage fi for g in video render input; do getent group "$g" >/dev/null && usermod -aG "$g" signage done echo "== binary and config" install -m 0755 "$BIN" /usr/local/bin/signage-player install -d -m 0755 /etc/signage-player if [ ! -f "$CONF" ]; then install -m 0644 "$HERE/player.conf.example" "$CONF" else echo "keeping the existing $CONF" # Older installs put the address here, where it is an override the # player can't erase (a revoked player would pair with it again rather # than start first-boot setup). Move it to the player's own setting. OLD=$(sed -n 's/^[[:space:]]*SIGNAGE_SERVER_URL=[[:space:]]*//p' "$CONF" | tail -n 1) if [ -n "$OLD" ]; then [ -z "$SERVER" ] && SERVER=$OLD sed -i 's/^\([[:space:]]*SIGNAGE_SERVER_URL=\)/#\1/' "$CONF" echo "moved SIGNAGE_SERVER_URL out of $CONF (now commented out) into the player's stored setting" fi fi install -d -m 0755 /usr/share/doc/signage-player install -m 0644 "$HERE/README.md" /usr/share/doc/signage-player/README.md echo "== data directory" install -d -o signage -g signage -m 0700 "$DATA" if [ -n "$SERVER" ]; then # Normalised and checked for form by the player itself (not contacted). runuser -u signage -- /usr/local/bin/signage-player -data-dir "$DATA" -save-server "$SERVER" fi echo "== permissions (reboot, network setup)" install -d -m 0755 /etc/polkit-1/rules.d cat >/etc/polkit-1/rules.d/50-signage-player.rules <<'EOF' // Let the signage player reboot the device (remote reboot command) and, // for first-boot setup and full reset, run its setup Wi-Fi network, join // the Wi-Fi network entered there, and forget saved Wi-Fi networks through // NetworkManager. The service runs outside any login session, so // NetworkManager's defaults would refuse it. polkit.addRule(function(action, subject) { if (subject.user != "signage") { return polkit.Result.NOT_HANDLED; } switch (action.id) { case "org.freedesktop.login1.reboot": case "org.freedesktop.login1.reboot-multiple-sessions": case "org.freedesktop.NetworkManager.settings.modify.system": case "org.freedesktop.NetworkManager.settings.modify.own": case "org.freedesktop.NetworkManager.network-control": case "org.freedesktop.NetworkManager.wifi.scan": case "org.freedesktop.NetworkManager.enable-disable-wifi": case "org.freedesktop.NetworkManager.wifi.share.protected": case "org.freedesktop.NetworkManager.wifi.share.open": return polkit.Result.YES; } return polkit.Result.NOT_HANDLED; }); EOF if [ "$NM" = yes ]; then echo "== setup network captive portal" # On the setup network every name resolves to the player, so phones # detect a captive portal and open the setup page by themselves. Only # NetworkManager's shared-mode dnsmasq reads this directory. install -d -m 0755 /etc/NetworkManager/dnsmasq-shared.d cat >/etc/NetworkManager/dnsmasq-shared.d/signage-captive.conf <<'EOF' # Circle Signage first-boot setup: answer every DNS query on the setup # network (NetworkManager shared mode, 10.42.0.1) with the player itself. address=/#/10.42.0.1 EOF if command -v raspi-config >/dev/null 2>&1; then COUNTRY=$(raspi-config nonint get_wifi_country 2>/dev/null || true) if [ -z "$COUNTRY" ]; then echo "install.sh: the Wi-Fi country is not set, so Wi-Fi may stay blocked (rfkill) and the setup network won't appear." >&2 echo " Set it: sudo raspi-config nonint do_wifi_country GB (your two-letter country code)" >&2 fi fi fi echo "== service" install -m 0644 "$HERE/signage-player.service" /etc/systemd/system/signage-player.service # The player draws on tty1: no login prompt there, and no desktop. systemctl disable --now getty@tty1.service 2>/dev/null || true if systemctl is-enabled display-manager.service >/dev/null 2>&1; then echo "install.sh: a display manager (desktop) is enabled; the player needs the display to itself." >&2 echo " Disable it (sudo systemctl disable --now display-manager) or use an OS Lite image." >&2 fi systemctl daemon-reload systemctl enable signage-player.service systemctl restart signage-player.service echo if [ -n "$SERVER" ]; then echo "Installed. The screen shows a pairing code: claim it in the admin app." else echo "Installed. The screen shows first-boot setup: join its setup Wi-Fi network" echo "with a phone (or scan the QR code), enter the setup code and the server address." fi echo "Logs: journalctl -u signage-player -f"