From 2b99345ba508467f35c864d055ebc526b104ec57 Mon Sep 17 00:00:00 2001 From: kx1t <15090643+kx1t@users.noreply.github.com> Date: Mon, 20 Nov 2023 23:45:36 -0500 Subject: [PATCH] fixes related to a new version of rbfeeder:armhf and some general cleanup (#184) * use native on all arm archs, cleanup logging * fix - changelog.gz doesn't always exist * add check for CPU serial number (again required from rbfeeder 1.0.9) * doc update: ensure hexdump is installed when adding FakeCpuSerial * only explicitly load armhf packages when arch needs to be emulated * fix typo * only do `dpkg --add-architecture armhf` when really needed * remove i386 building from test builds * make checking for cpu serial case independent --- .github/workflows/on_pr.yml | 2 +- Dockerfile | 50 +++++++++++-------- .../scripts/01-show-rbfeeder-changelog | 11 ++-- rootfs/etc/s6-overlay/scripts/02-rbfeeder | 37 +++++++++----- .../s6-overlay/scripts/03-show-architecture | 18 ++++--- .../etc/s6-overlay/scripts/978json-splitter | 19 +++---- rootfs/etc/s6-overlay/scripts/rbfeeder | 18 +++---- rootfs/etc/s6-overlay/scripts/stats | 8 +-- rootfs/usr/bin/rbfeeder_wrapper.sh | 17 ++++--- version_0.4.3_workarounds.md | 6 ++- 10 files changed, 110 insertions(+), 76 deletions(-) diff --git a/.github/workflows/on_pr.yml b/.github/workflows/on_pr.yml index 8d79d0e..bd54cec 100644 --- a/.github/workflows/on_pr.yml +++ b/.github/workflows/on_pr.yml @@ -49,7 +49,7 @@ jobs: with: push_enabled: false platform_linux_arm32v6_enabled: false - platform_linux_i386_enabled: true + platform_linux_i386_enabled: false get_version_method: file_in_container:file=/CONTAINER_VERSION # test_build: diff --git a/Dockerfile b/Dockerfile index 7f5cb3c..13f7ae9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base as downloader # This downloader image has the rb24 apt repo added, and allows for downloading and extracting of rbfeeder binary deb package. +ARG TARGETPLATFORM TARGETOS TARGETARCH SHELL ["/bin/bash", "-o", "pipefail", "-c"] @@ -14,19 +15,17 @@ RUN set -x && \ xz-utils \ && \ # add rb24 repo - dpkg --add-architecture armhf && \ + if [ "${TARGETARCH:0:3}" != "arm" ]; then \ + dpkg --add-architecture armhf; \ + RB24_PACKAGES=(rbfeeder:armhf); \ + else \ + RB24_PACKAGES=(rbfeeder); \ + fi && \ apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 1D043681 && \ bash -c "echo 'deb https://apt.rb24.com/ bullseye main' > /etc/apt/sources.list.d/rb24.list" && \ - apt-get update && \ - # download rbfeeder deb - pushd /tmp && \ - apt-get download \ - rbfeeder:armhf \ - && \ - # extract rbfeeder deb - ls -lah && \ - ar xv ./rbfeeder_*armhf.deb && \ - tar xvf ./data.tar.xz -C / + apt-get update -q && \ + apt-get install -q -o Dpkg::Options::="--force-confnew" -y --no-install-recommends --no-install-suggests \ + "${RB24_PACKAGES[@]}" FROM ghcr.io/sdr-enthusiasts/docker-baseimage:qemu @@ -42,16 +41,17 @@ ENV BEASTHOST=readsb \ VERBOSE_LOGGING=false \ ENABLE_MLAT=true +ARG TARGETPLATFORM TARGETOS TARGETARCH + COPY rootfs/ / -COPY --from=downloader /usr/bin/rbfeeder /usr/bin/rbfeeder_armhf +COPY --from=downloader /usr/bin/rbfeeder /usr/bin/rbfeeder_arm COPY --from=downloader /usr/bin/dump1090-rb /usr/bin/dump1090-rb -COPY --from=downloader /usr/share/doc/rbfeeder/changelog.gz /usr/share/doc/rbfeeder/changelog.gz +COPY --from=downloader /usr/share/doc/rbfeeder/ /usr/share/doc/rbfeeder/ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # hadolint ignore=DL3008,SC2086,SC2039,SC2068 RUN set -x && \ - dpkg --add-architecture armhf && \ # define required packages TEMP_PACKAGES=() && \ KEPT_PACKAGES=() && \ @@ -65,12 +65,22 @@ RUN set -x && \ TEMP_PACKAGES+=(libpython3-dev) && \ KEPT_PACKAGES+=(python3-setuptools) && \ # required to run rbfeeder - KEPT_PACKAGES+=(libc6:armhf) && \ - KEPT_PACKAGES+=(libcurl4:armhf) && \ - KEPT_PACKAGES+=(libglib2.0-0:armhf) && \ - KEPT_PACKAGES+=(libjansson4:armhf) && \ - KEPT_PACKAGES+=(libprotobuf-c1:armhf) && \ - KEPT_PACKAGES+=(librtlsdr0:armhf) && \ + if [ "${TARGETARCH:0:3}" != "arm" ]; then \ + dpkg --add-architecture armhf; \ + KEPT_PACKAGES+=(libc6:armhf) && \ + KEPT_PACKAGES+=(libcurl4:armhf) && \ + KEPT_PACKAGES+=(libglib2.0-0:armhf) && \ + KEPT_PACKAGES+=(libjansson4:armhf) && \ + KEPT_PACKAGES+=(libprotobuf-c1:armhf) && \ + KEPT_PACKAGES+=(librtlsdr0:armhf); \ + else \ + KEPT_PACKAGES+=(libc6) && \ + KEPT_PACKAGES+=(libcurl4) && \ + KEPT_PACKAGES+=(libglib2.0-0) && \ + KEPT_PACKAGES+=(libjansson4) && \ + KEPT_PACKAGES+=(libprotobuf-c1) && \ + KEPT_PACKAGES+=(librtlsdr0); \ + fi && \ KEPT_PACKAGES+=(netbase) && \ # install packages apt-get update && \ diff --git a/rootfs/etc/s6-overlay/scripts/01-show-rbfeeder-changelog b/rootfs/etc/s6-overlay/scripts/01-show-rbfeeder-changelog index cf3d92f..0dd6494 100755 --- a/rootfs/etc/s6-overlay/scripts/01-show-rbfeeder-changelog +++ b/rootfs/etc/s6-overlay/scripts/01-show-rbfeeder-changelog @@ -1,9 +1,10 @@ #!/usr/bin/env bash +#shellcheck shell=bash disable=SC1091 -white="\e[0;97m" -reset="\e[0m" +source /scripts/common +s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) # Show latest changelog -echo -e "${white}" -zcat /usr/share/doc/rbfeeder/changelog.gz | grep -B9999 -m 1 " -- " -echo -e "${reset}" +if [[ -e /usr/share/doc/rbfeeder/changelog.gz ]]; then + "${s6wrap[@]}" zcat /usr/share/doc/rbfeeder/changelog.gz | grep -B9999 -m 1 " -- " +fi diff --git a/rootfs/etc/s6-overlay/scripts/02-rbfeeder b/rootfs/etc/s6-overlay/scripts/02-rbfeeder index 69e5aa0..f7a77a1 100755 --- a/rootfs/etc/s6-overlay/scripts/02-rbfeeder +++ b/rootfs/etc/s6-overlay/scripts/02-rbfeeder @@ -1,22 +1,25 @@ #!/command/with-contenv bash -# shellcheck shell=bash +#shellcheck shell=bash disable=SC1091,SC2015 + +source /scripts/common +s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) # Check to make sure the correct command line arguments have been set EXITCODE=0 if [ -z "${LAT}" ]; then - echo "ERROR: LAT environment variable not set" + "${s6wrap[@]}" echo "[ERROR] LAT environment variable not set" EXITCODE=1 fi if [ -z "${LONG}" ]; then - echo "ERROR: LONG environment variable not set" + "${s6wrap[@]}" echo "[ERROR] LONG environment variable not set" EXITCODE=1 fi if [ -z "${BEASTHOST}" ]; then - echo "ERROR: BEASTHOST environment variable not set" + "${s6wrap[@]}" echo "[ERROR] BEASTHOST environment variable not set" EXITCODE=1 fi if [ -z "${ALT}" ]; then - echo "ERROR: ALT environment variable not set" + "${s6wrap[@]}" echo "[ERROR] ALT environment variable not set" EXITCODE=1 else ALT="${ALT%%.*}" @@ -27,9 +30,9 @@ fi # Set up timezone if [ -z "${TZ}" ]; then - echo "WARNING: TZ environment variable not set" + "${s6wrap[@]}" echo "[WARNING] TZ environment variable not set" else - ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone + ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone || true fi # Generate /etc/rbfeeder.ini based on environment variables @@ -42,11 +45,11 @@ debug_level=${DEBUG_LEVEL:-0} if [ -z "${SHARING_KEY}" ] then - echo "" - echo "WARNING: SHARING_KEY environment variable was not set!" - echo "Please make sure you note down the key generated." - echo "Pass the key as environment var SHARING_KEY on next launch!" - echo "" + "${s6wrap[@]}" echo "" + "${s6wrap[@]}" echo "[WARNING] SHARING_KEY environment variable was not set!" + "${s6wrap[@]}" echo " Please make sure you note down the key generated." + "${s6wrap[@]}" echo " Pass the key as environment var SHARING_KEY on next launch!" + "${s6wrap[@]}" echo "" else echo "key=$SHARING_KEY" >> /etc/rbfeeder.ini fi @@ -90,8 +93,18 @@ if [[ -n "$UAT_RECEIVER_HOST" ]]; then } >> /etc/rbfeeder.ini fi +if ! grep -qi "Serial\s*:" /proc/cpuinfo; then + # rbfeeder won't work without a serial number + "${s6wrap[@]}" echo "" + "${s6wrap[@]}" echo "[ERROR] Your machine doesn't have a serial number in /proc/cpuinfo" + "${s6wrap[@]}" echo " You must resolve this for the container to run. Instruction to fix it can be found here:" + "${s6wrap[@]}" echo " https://github.com/sdr-enthusiasts/docker-radarbox/blob/main/version_0.4.3_workarounds.md#workaround-for-cpu-serial" + sleep infinity & wait $! +fi + # Create log dirs mkdir -p /var/log/rbfeeder +mkdir -p /run/shm chown nobody:nogroup /var/log/rbfeeder touch /var/log/rbfeeder.log truncate --size=0 /var/log/rbfeeder.log diff --git a/rootfs/etc/s6-overlay/scripts/03-show-architecture b/rootfs/etc/s6-overlay/scripts/03-show-architecture index 5ef61ef..b561cff 100755 --- a/rootfs/etc/s6-overlay/scripts/03-show-architecture +++ b/rootfs/etc/s6-overlay/scripts/03-show-architecture @@ -1,11 +1,13 @@ #!/usr/bin/env bash -white="\e[0;97m" -reset="\e[0m" +#shellcheck shell=bash disable=SC1091 -echo -e "${white}" -echo "Hardware information:" -echo "Machine: $(uname -m)" -echo "Processor: $(uname -p)" -echo "Platform: $(uname -i)" -echo -e "${reset}" +source /scripts/common +s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) + +"${s6wrap[@]}" cat << EOM +Hardware information: +Machine: $(uname -m) +Processor: $(uname -p) +Platform: $(uname -i) +EOM diff --git a/rootfs/etc/s6-overlay/scripts/978json-splitter b/rootfs/etc/s6-overlay/scripts/978json-splitter index 79e0edf..33fb124 100755 --- a/rootfs/etc/s6-overlay/scripts/978json-splitter +++ b/rootfs/etc/s6-overlay/scripts/978json-splitter @@ -1,15 +1,16 @@ #!/command/with-contenv bash -# shellcheck shell=bash +#shellcheck shell=bash disable=SC1091 + +source /scripts/common +s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) + set -eo pipefail # Don't continue if UAT_RECEIVER_HOST isn't set if [[ -z "$UAT_RECEIVER_HOST" ]]; then - sleep 86400 - exit 0 + sleep infinity & wait $! +else + # shellcheck disable=SC2016 + "${s6wrap[@]}" socat -d -d TCP-LISTEN:30979,fork TCP:"$UAT_RECEIVER_HOST":"${UAT_RECEIVER_PORT:-30979}" + sleep 5 fi - -# shellcheck disable=SC2016 -socat -d -d TCP-LISTEN:30979,fork TCP:"$UAT_RECEIVER_HOST":"${UAT_RECEIVER_PORT:-30979}" \ - 2>&1 | awk '{print "[978json-splitter] " $0}' - -sleep 5 diff --git a/rootfs/etc/s6-overlay/scripts/rbfeeder b/rootfs/etc/s6-overlay/scripts/rbfeeder index 168acec..585f770 100755 --- a/rootfs/etc/s6-overlay/scripts/rbfeeder +++ b/rootfs/etc/s6-overlay/scripts/rbfeeder @@ -1,6 +1,8 @@ #!/command/with-contenv bash -#shellcheck shell=bash -#shellcheck disable=SC2016 +#shellcheck shell=bash disable=SC2016,SC1091 + +source /scripts/common +s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) # Prevent writing of coredumps # - Reason for coredumps: https://github.com/mikenye/docker-radarbox/issues/9#issuecomment-633068833 @@ -9,13 +11,9 @@ ulimit -c 0 # can be run natively if [ "$VERBOSE_LOGGING" == "true" ]; then - /usr/bin/rbfeeder 2>&1 | \ - stdbuf -oL awk '{print "[rbfeeder] " $0}' + "${s6wrap[@]}" /usr/bin/rbfeeder + else - /usr/bin/rbfeeder 2>&1 | \ - stdbuf -oL awk '! / Statistics updated every 60 seconds /' | \ - stdbuf -oL awk '! /Packets sent in the last 60 seconds: /' | \ - stdbuf -oL awk '! / Data sent: /' | \ - stdbuf -oL awk '! / Data received: /' | \ - stdbuf -oL awk '{print "[rbfeeder] " $0}' + "${s6wrap[@]}" /usr/bin/rbfeeder | \ + stdbuf -oL grep -v "Statistics updated every 60 seconds|\Packets sent in the last 60 seconds:|\Data sent:|\Data received:" fi diff --git a/rootfs/etc/s6-overlay/scripts/stats b/rootfs/etc/s6-overlay/scripts/stats index 90bcf87..234c30e 100755 --- a/rootfs/etc/s6-overlay/scripts/stats +++ b/rootfs/etc/s6-overlay/scripts/stats @@ -1,5 +1,8 @@ #!/command/with-contenv bash -#shellcheck shell=bash +#shellcheck shell=bash disable=SC1091 + +source /scripts/common +s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) sleep $((STATS_INTERVAL_MINUTES * 60)) @@ -13,8 +16,7 @@ while read -r L; do done < "$RBFEEDER_LOG_FILE" #shellcheck disable=SC2016 -echo "Packets sent in past $STATS_INTERVAL_MINUTES minutes: $PACKETS_SINCE_LAST_UPDATE, total packets since container start: $TOTAL_PACKETS" \ -| stdbuf -oL awk '{print "[rbfeeder-stats] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}' +"${s6wrap[@]}" echo "Packets sent in past $STATS_INTERVAL_MINUTES minutes: $PACKETS_SINCE_LAST_UPDATE, total packets since container start: $TOTAL_PACKETS" # truncate the log file to 150 lines #shellcheck disable=SC2005 diff --git a/rootfs/usr/bin/rbfeeder_wrapper.sh b/rootfs/usr/bin/rbfeeder_wrapper.sh index 8cfc42f..d16605d 100755 --- a/rootfs/usr/bin/rbfeeder_wrapper.sh +++ b/rootfs/usr/bin/rbfeeder_wrapper.sh @@ -1,17 +1,20 @@ #!/usr/bin/env bash +# shellcheck shell=bash disable=SC1091 # This wrapper file will determine how to run rbfeeder, either natively or via qemu-arm-static. # All command line arguments passed to this script will be passed directly to rbfeeder_armhf. +source /scripts/common +s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) + # attempt to run natively -if /usr/bin/rbfeeder_armhf --no-start --version > /dev/null 2>&1; then - /usr/bin/rbfeeder_armhf "$@" +if /usr/bin/rbfeeder_arm --no-start --version >/dev/null 2>&1; then + /usr/bin/rbfeeder_arm "$@" -elif qemu-arm-static /usr/bin/rbfeeder_armhf --no-start --version > /dev/null 2>&1; then - qemu-arm-static /usr/bin/rbfeeder_armhf "$@" +elif qemu-arm-static /usr/bin/rbfeeder_arm --no-start --version >/dev/null 2>&1; then + qemu-arm-static /usr/bin/rbfeeder_arm "$@" else - >&2 echo "ERROR: Could not run rbfeeder natively or via qemu" - sleep 3600 - + "${s6wrap[@]}" echo "[ERROR] Could not run rbfeeder natively or via qemu" + sleep infinity & wait $! fi diff --git a/version_0.4.3_workarounds.md b/version_0.4.3_workarounds.md index 613b184..a82b0f6 100644 --- a/version_0.4.3_workarounds.md +++ b/version_0.4.3_workarounds.md @@ -14,11 +14,15 @@ For systems that don't have a CPU serial number in `/proc/cpuinfo`, we can "fudg ```bash # make a directory to hold our fake data -mkdir -p /opt/adsb/data +mkdir -p -m 777 /opt/adsb/data # generate a fake cpuinfo file # start by taking our current cpuinfo file cp /proc/cpuinfo /opt/adsb/data/fake_cpuinfo +chmod u+w /opt/adsb/data/fake_cpuinfo + +# ... make sure we have hexdump installed +[[ ! which hexdump >/dev/null 2>&1 ]] && sudo apt install -y bsdmainutils # ... and add a fake serial number to the end echo -e "serial\t\t: $(hexdump -n 8 -e '4/4 "%08X" 1 "\n"' /dev/urandom | tr '[:upper:]' '[:lower:]')" >> /opt/adsb/data/fake_cpuinfo