|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +DISPLAY_CONTROLLER_URL=https://raw.githubusercontent.com/opsboost/iss-display-controller/main |
| 4 | +PYTHON_WAYLAND_VERSION=latest |
| 5 | +PYTHON_WAYLAND_ARCHIVE=python-wayland-${PYTHON_WAYLAND_VERSION}.tar.xz |
| 6 | +PYTHON_WAYLAND_URL=https://github.com/bbusse/python-wayland/releases/download/latest/${PYTHON_WAYLAND_ARCHIVE} |
| 7 | +SWAY_CONFIG_URL=https://raw.githubusercontent.com/bbusse/swayvnc/main/config |
| 8 | +SERVICE_USER=iss |
| 9 | +PAYLOAD="mpv /home/${SERVICE_USER}/video.mp4" |
| 10 | +STREAMS_PLAYLIST_URL="https://raw.githubusercontent.com/jnk22/kodinerds-iptv/master/iptv/clean/clean_tv.m3u" |
| 11 | + |
| 12 | +setup_sway() { |
| 13 | + printf "Fetching sway config\n" |
| 14 | + curl --output-dir "${ROOTFS_PATH}"/etc/sway -LO "${SWAY_CONFIG_URL}" |
| 15 | + |
| 16 | + # Write Sway start script |
| 17 | + printf "Writing sway-launcher\n" |
| 18 | + sway_write_launcher |
| 19 | + |
| 20 | + # Write Sway openrc startup file |
| 21 | + printf "Writing openrc start script\n" |
| 22 | + mkdir -p "${ROOTFS_PATH}"/etc/local.d |
| 23 | + sway_write_start_script |
| 24 | + |
| 25 | + # Write exec to sway's config.d |
| 26 | + sway_configure_payload |
| 27 | + |
| 28 | + chmod +x "${ROOTFS_PATH}"/usr/bin/sway-launcher |
| 29 | + chmod +x "${ROOTFS_PATH}"/etc/local.d/sway.start |
| 30 | +} |
| 31 | + |
| 32 | +sway_configure_payload() { |
| 33 | + mkdir "${ROOTFS_PATH}"/etc/sway/config.d |
| 34 | + printf "exec %s" "${PAYLOAD}" >> "${ROOTFS_PATH}"/etc/sway/config.d/exec-payload |
| 35 | +} |
| 36 | + |
| 37 | +sway_write_launcher() { |
| 38 | +cat << \EOF > "${ROOTFS_PATH}"/usr/bin/sway-launcher |
| 39 | +#!/bin/sh |
| 40 | +
|
| 41 | +# Launch sway with a specific user, from a specific Virtual Terminal (vt) |
| 42 | +# Two arguments are expected: a username (e.g., larry) and the id of a free vt (e.g., 7) |
| 43 | +
|
| 44 | +# Prepare the tty for the user |
| 45 | +chown ${1} "/dev/tty${2}" |
| 46 | +chmod 600 "/dev/tty${2}" |
| 47 | +
|
| 48 | +# Setup a clean environment for the user, take over the target vt, then launch sway as non-root user |
| 49 | +su -l root -c "openvt -s -c ${2} -- su -l ${1} -c \"XDG_RUNTIME_DIR=/tmp WLR_LIBINPUT_NO_DEVICES=1 sway\"" |
| 50 | +EOF |
| 51 | +} |
| 52 | + |
| 53 | +sway_write_start_script() { |
| 54 | +cat << EOF > "${ROOTFS_PATH}"/etc/local.d/sway.start |
| 55 | +#!/bin/sh |
| 56 | +sway-launcher ${SERVICE_USER} 2 |
| 57 | +EOF |
| 58 | +} |
| 59 | + |
| 60 | +main() { |
| 61 | + printf "Adding packages\n" |
| 62 | + chroot_exec apk add ffmpeg \ |
| 63 | + gstreamer \ |
| 64 | + gstreamer-tools \ |
| 65 | + gst-plugins-base \ |
| 66 | + gst-plugins-bad \ |
| 67 | + gst-plugins-good \ |
| 68 | + iw \ |
| 69 | + linux-firmware-cypress \ |
| 70 | + mesa-dri-gallium \ |
| 71 | + mpv \ |
| 72 | + py3-pip \ |
| 73 | + podman \ |
| 74 | + seatd \ |
| 75 | + sway \ |
| 76 | + wpa_supplicant \ |
| 77 | + xz |
| 78 | + |
| 79 | + # Build dependencies - we remove them again later |
| 80 | + chroot_exec apk add gcc \ |
| 81 | + git \ |
| 82 | + jpeg-dev \ |
| 83 | + libc-dev \ |
| 84 | + libffi-dev \ |
| 85 | + libxkbcommon-dev \ |
| 86 | + py3-wheel \ |
| 87 | + python3-dev \ |
| 88 | + zlib-dev \ |
| 89 | + |
| 90 | + printf "Creating user\n" |
| 91 | + chroot_exec adduser --disabled-password ${SERVICE_USER} |
| 92 | + chroot_exec adduser ${SERVICE_USER} video |
| 93 | + chroot_exec adduser ${SERVICE_USER} seat |
| 94 | + |
| 95 | + # Enable services |
| 96 | + chroot_exec rc-update add seatd |
| 97 | + chroot_exec rc-update add wpa_supplicant |
| 98 | + |
| 99 | + # Add kernel modules to load |
| 100 | + cp /input/modules "${ROOTFS_PATH}"/etc/ |
| 101 | + |
| 102 | + # Load device tree overlay |
| 103 | + echo "dtoverlay=vc4-kms-v3d" >> "${BOOTFS_PATH}"/config.txt |
| 104 | + |
| 105 | + setup_sway |
| 106 | + |
| 107 | + # Add display-controller for stream handling |
| 108 | + printf "Adding display-controller\n" |
| 109 | + curl -s -S --output-dir "${ROOTFS_PATH}/usr/bin" -LO "${DISPLAY_CONTROLLER_URL}/controller.py" |
| 110 | + curl -s -S --output-dir "${ROOTFS_PATH}/home/${SERVICE_USER}" -LO "${DISPLAY_CONTROLLER_URL}/requirements.txt" |
| 111 | + chroot_exec pip install -r /home/${SERVICE_USER}/requirements.txt |
| 112 | + chmod +x "${ROOTFS_PATH}"/usr/bin/controller.py |
| 113 | + |
| 114 | + # Add python-wayland |
| 115 | + printf "Adding python-wayland\n" |
| 116 | + mkdir -p "${ROOTFS_PATH}/usr/local/src" |
| 117 | + curl -s -S --output-dir "${ROOTFS_PATH}/usr/local/src/" -LO "${PYTHON_WAYLAND_URL}" |
| 118 | + chroot_exec cd /usr/local/src && tar xf "${PYTHON_WAYLAND_ARCHIVE}" |
| 119 | + |
| 120 | + # Remove build dependencies |
| 121 | + chroot_exec apk del gcc \ |
| 122 | + git \ |
| 123 | + jpeg-dev \ |
| 124 | + libc-dev \ |
| 125 | + libffi-dev \ |
| 126 | + libxkbcommon-dev \ |
| 127 | + py3-wheel \ |
| 128 | + python3-dev \ |
| 129 | + zlib-dev |
| 130 | + |
| 131 | + # Fetching streams playlist |
| 132 | + printf "Fetching streams playlist\n" |
| 133 | + curl -s -S --output-dir "${ROOTFS_PATH}"/home/${SERVICE_USER} -LO ${STREAMS_PLAYLIST_URL} |
| 134 | +} |
| 135 | + |
| 136 | +main "$@" |
0 commit comments