add startup scripts and configs

This commit is contained in:
2026-11-15 18:36:42 -05:00
parent cb87b8ccc6
commit 7eeff6e211
11 changed files with 276 additions and 0 deletions
Executable
+140
View File
@@ -0,0 +1,140 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "$(id -u)" -ne 0 ]; then
echo "Run as root: sudo ./setup.sh" >&2
exit 1
fi
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONF="$DIR/flightwall.conf"
OWNER="$(stat -c %U "$DIR")"
REBOOT=0
as_owner() {
if [ "$OWNER" = "root" ]; then
"$@"
else
runuser -u "$OWNER" -- "$@"
fi
}
set_conf() {
sed -i -E "s|^$1=.*|$1=$2|" "$CONF"
}
echo "==> Configuration"
[ -f "$CONF" ] || as_owner cp "$DIR/flightwall.conf.example" "$CONF"
. "$CONF"
is_unset() { [ -z "${1:-}" ] || [ "$1" = "0" ]; }
if is_unset "$LAT" || is_unset "$LON"; then
if [ ! -t 0 ]; then
echo "Set LAT and LON in $CONF, then re-run." >&2
exit 1
fi
read -rp "Latitude (e.g. 33.6407): " LAT
read -rp "Longitude (e.g. -84.4277): " LON
current_tz="$(timedatectl show -p Timezone --value 2>/dev/null || echo "$TIMEZONE")"
read -rp "Timezone [$current_tz]: " tz
TIMEZONE="${tz:-$current_tz}"
set_conf LAT "$LAT"
set_conf LON "$LON"
set_conf TIMEZONE "$TIMEZONE"
fi
num='^-?[0-9]+(\.[0-9]+)?$'
if ! [[ "$LAT" =~ $num && "$LON" =~ $num ]]; then
echo "LAT/LON in $CONF must be decimal degrees." >&2
exit 1
fi
if ! timedatectl list-timezones | grep -qx "$TIMEZONE"; then
echo "Unknown TIMEZONE '$TIMEZONE' in $CONF (see: timedatectl list-timezones)." >&2
exit 1
fi
timedatectl set-timezone "$TIMEZONE"
echo "==> Packages"
lighttpd_preinstalled=0
dpkg -s lighttpd >/dev/null 2>&1 && lighttpd_preinstalled=1
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
build-essential git pkg-config python3 \
librtlsdr-dev libusb-1.0-0-dev libncurses-dev lighttpd
if [ "$lighttpd_preinstalled" -eq 0 ]; then
systemctl disable --now lighttpd 2>/dev/null || true
fi
echo "==> Building"
as_owner git -C "$DIR" submodule update --init --recursive
as_owner make -C "$DIR/external/dump1090" -j"$(nproc)" \
RTLSDR=yes BLADERF=no HACKRF=no LIMESDR=no SOAPYSDR=no \
CPPFLAGS="-Wno-error=format-truncation" dump1090
as_owner make -C "$DIR" -j"$(nproc)" app
echo "==> Installing"
install -m 755 "$DIR/external/dump1090/dump1090" /usr/local/bin/flightwall-dump1090
rm -rf /usr/local/share/flightwall/html
mkdir -p /usr/local/share/flightwall /etc/flightwall
cp -r "$DIR/external/dump1090/public_html" /usr/local/share/flightwall/html
sed "s|__WEB_PORT__|$WEB_PORT|" "$DIR/deploy/lighttpd.conf" > /etc/flightwall/lighttpd.conf
getent group plugdev >/dev/null || groupadd --system plugdev
id dump1090 >/dev/null 2>&1 ||
useradd --system --no-create-home --shell /usr/sbin/nologin -G plugdev dump1090
install -m 644 "$DIR/deploy/99-flightwall-rtlsdr.rules" /etc/udev/rules.d/
udevadm control --reload-rules && udevadm trigger
for unit in flightwall flightwall-dump1090 flightwall-web; do
sed "s|__INSTALL_DIR__|$DIR|g" "$DIR/deploy/$unit.service" > "/etc/systemd/system/$unit.service"
done
for svc in dump1090 dump1090-fa dump1090-mutability readsb; do
if systemctl cat "$svc.service" >/dev/null 2>&1; then
echo "Disabling existing $svc service"
systemctl disable --now "$svc.service" || true
fi
done
echo "==> Hardware"
cat > /etc/modprobe.d/flightwall.conf <<'EOF'
blacklist snd_bcm2835
blacklist dvb_usb_rtl28xxu
blacklist rtl2832
blacklist rtl2830
EOF
modprobe -r dvb_usb_rtl28xxu rtl2832 rtl2830 2>/dev/null || true
for boot in /boot/firmware /boot; do
[ -f "$boot/cmdline.txt" ] && break
done
if [ -f "$boot/cmdline.txt" ] && [ "$(nproc --all)" -ge 4 ] &&
! grep -q 'isolcpus=' "$boot/cmdline.txt"; then
sed -i -E '1 s/[[:space:]]*$/ isolcpus=3/' "$boot/cmdline.txt"
REBOOT=1
fi
if [ -f "$boot/config.txt" ]; then
if grep -qE '^dtparam=audio=on' "$boot/config.txt"; then
sed -i -E 's/^dtparam=audio=on/dtparam=audio=off/' "$boot/config.txt"
REBOOT=1
elif ! grep -qE '^dtparam=audio=off' "$boot/config.txt"; then
echo "dtparam=audio=off" >> "$boot/config.txt"
REBOOT=1
fi
fi
echo "==> Services"
systemctl daemon-reload
systemctl enable flightwall-dump1090 flightwall-web flightwall
systemctl restart flightwall-dump1090 flightwall-web flightwall
ip="$(hostname -I | awk '{print $1}')"
echo
echo "Done. Web UI: http://${ip:-<pi-ip>}:$WEB_PORT"
if [ "$REBOOT" -eq 1 ]; then
echo "Boot config changed (isolcpus / audio). Reboot to apply: sudo reboot"
fi