Compare commits

12 Commits
raptor ... main

Author SHA1 Message Date
261359f973 fix: improve error handling in NetworkManager hotspot configuration 2026-03-16 09:05:48 +01:00
63a33f4deb fix: enhance NetworkManager hotspot configuration and cleanup process 2026-03-16 08:58:36 +01:00
12ff47207e fix: enhance AP and client mode switching with NetworkManager support 2026-03-16 08:50:26 +01:00
4ad82a1a66 fix: refactor networking scripts for improved robustness and clarity 2026-03-16 08:42:26 +01:00
855339ef42 fix: harden NetworkManager hotspot creation to prevent supplicant-timeout errors on Pi 3B 2026-03-16 08:26:41 +01:00
4e1858de61 fix: make setup script WiFi-safe by removing instant network activation 2026-03-16 00:10:50 +01:00
6fea68f903 fix: force NetworkManager hotspot priority and disconnect active client wifi to ensure AP activation 2026-03-15 23:56:38 +01:00
237ff76670 fix: implement NetworkManager (nmcli) hotspot support for modern Debian/Trixie systems 2026-03-15 23:49:10 +01:00
1aa5717891 fix: enforce absolute unmasking and disable default wifi networking to ensure AP mode success 2026-03-15 23:41:12 +01:00
46b5361ef7 feat: skip compilation and use pre-compiled ofxPiMapper binary for instant setup 2026-03-15 23:20:15 +01:00
778f31a8e7 ci: add pre-built artifacts (frontend/dist + bin/ofxPiMapper) 2026-03-15 22:01:21 +00:00
260a8f16cb fix: implement lightning-fast engine setup by utilizing pre-compiled OpenFrameworks correctly and avoiding core re-compilation 2026-03-15 16:41:53 +01:00
7 changed files with 441 additions and 470 deletions

8
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,8 @@
{
"chat.tools.terminal.autoApprove": {
"/^bash -n scripts/setup\\.sh && bash -n scripts/switch-to-ap\\.sh && bash -n scripts/switch-to-client\\.sh$/": {
"approve": true,
"matchCommandLine": true
}
}
}

View File

@ -9,6 +9,8 @@ const fs = require('fs');
const path = require('path');
const multer = require('multer');
const scriptsDir = path.join(__dirname, '../scripts');
const app = express();
app.use(express.json());
app.use(express.static(path.join(__dirname, '../frontend/dist')));
@ -120,14 +122,14 @@ app.post('/media/assign', (req, res) => {
// Networking API
app.post('/network/ap', (req, res) => {
exec('bash scripts/switch-to-ap.sh', (err, stdout) => {
exec(`bash "${path.join(scriptsDir, 'switch-to-ap.sh')}"`, (err, stdout) => {
if (err) return res.status(500).json({ error: err.message });
res.json({ status: 'switching to ap', output: stdout });
});
});
app.post('/network/client', (req, res) => {
exec('bash scripts/switch-to-client.sh', (err, stdout) => {
exec(`bash "${path.join(scriptsDir, 'switch-to-client.sh')}"`, (err, stdout) => {
if (err) return res.status(500).json({ error: err.message });
res.json({ status: 'switching to client', output: stdout });
});

BIN
bin/ofxPiMapper Executable file

Binary file not shown.

View File

@ -1,332 +0,0 @@
#!/bin/bash
# MPVJ Build Script
# Runs on x86_64 (e.g., Docker) to cross-compile artifacts for aarch64 (RPi 3B).
# Outputs (committed back to the repo):
# frontend/dist/ — pre-built Vite bundle
# bin/ofxPiMapper — aarch64 binary
#
# Usage:
# bash build.sh <REPO_URL> # clones repo into ./mapper, then builds
# bash build.sh <REPO_URL> <DIR> # clones into DIR, then builds
set -e
REPO_URL="${1:-}"
REPO_DIR="${2:-$(pwd)/mapper}"
OF_VERSION="0.12.1"
OF_DIR="$REPO_DIR/_build/openFrameworks"
OF_FILE="of_v${OF_VERSION}_linuxaarch64_release.tar.gz"
OF_URL="https://github.com/openframeworks/openFrameworks/releases/download/${OF_VERSION}/${OF_FILE}"
BIN_OUT="$REPO_DIR/bin"
if [ -z "$REPO_URL" ]; then
echo "Usage: bash $0 <REPO_URL> [CLONE_DIR]"
exit 1
fi
# ── Clone repo if needed ─────────────────────────────────────────────────────
if [ ! -d "$REPO_DIR/frontend" ] || [ ! -d "$REPO_DIR/backend" ]; then
echo "Cloning $REPO_URL into $REPO_DIR ..."
git clone "$REPO_URL" "$REPO_DIR"
fi
echo "Building from: $REPO_DIR"
# ── 1. Install build dependencies ───────────────────────────────────────────
echo "Installing build dependencies..."
if command -v apt-get > /dev/null 2>&1; then
# Enable arm64 packages alongside x86_64 (Debian multiarch)
dpkg --add-architecture arm64
apt-get update -y
# Cross-compiler toolchain (host)
DEBIAN_FRONTEND=noninteractive apt-get install -y \
git curl wget unzip build-essential pkg-config \
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
binutils-aarch64-linux-gnu
# aarch64 dev libraries (provides the .pc files pkg-config needs)
# Note: some arm64 packages share man pages with their amd64 counterparts —
# --force-overwrite is safe here as we only care about headers/.so/.pc files.
DEBIAN_FRONTEND=noninteractive apt-get install -y \
-o Dpkg::Options::="--force-overwrite" \
libmpg123-dev:arm64 libsndfile1-dev:arm64 libopenal-dev:arm64 libassimp-dev:arm64 \
librtaudio-dev:arm64 \
libglew-dev:arm64 libglfw3-dev:arm64 liburiparser-dev:arm64 \
libcurl4-openssl-dev:arm64 libpugixml-dev:arm64 libasound2-dev:arm64 \
libgstreamer1.0-dev:arm64 libgstreamer-plugins-base1.0-dev:arm64 \
libgtk-3-dev:arm64 libboost-filesystem-dev:arm64 \
libfontconfig1-dev:arm64 libfreetype-dev:arm64 libx11-dev:arm64 \
libxrandr-dev:arm64 libxinerama-dev:arm64 libxcursor-dev:arm64 libxi-dev:arm64 \
libpulse-dev:arm64 libudev-dev:arm64 libfreeimage-dev:arm64 \
freeglut3-dev:arm64 libxxf86vm-dev:arm64 \
libcairo2-dev:arm64 \
libblas-dev:arm64 liblapack-dev:arm64
# These conflict with amd64 -dev headers; install runtime-only for .so + .pc
DEBIAN_FRONTEND=noninteractive apt-get install -y \
-o Dpkg::Options::="--force-overwrite" \
libzmq5:arm64 libpsl5:arm64 || true
# Repair any partially-broken state from conflicts
apt-get -f install -y
# Generate minimal .pc files for runtime-only arm64 packages that lack one
if [ ! -f /usr/lib/aarch64-linux-gnu/pkgconfig/libzmq.pc ]; then
ZMQ_VER=$(dpkg -l libzmq5:arm64 2>/dev/null | awk '/^ii/{print $3}' | cut -d- -f1 || echo "4.3.5")
mkdir -p /usr/lib/aarch64-linux-gnu/pkgconfig
cat > /usr/lib/aarch64-linux-gnu/pkgconfig/libzmq.pc <<EOF
prefix=/usr
exec_prefix=\${prefix}
libdir=\${prefix}/lib/aarch64-linux-gnu
includedir=\${prefix}/include
Name: libzmq
Description: ZeroMQ messaging library
Version: $ZMQ_VER
Libs: -L\${libdir} -lzmq
Cflags: -I\${includedir}
EOF
fi
fi
# Install Node.js if missing
if ! command -v node > /dev/null 2>&1; then
echo "Installing Node.js 20..."
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
fi
# ── 2. Build frontend ────────────────────────────────────────────────────────
echo ""
echo "=== Building frontend ==="
cd "$REPO_DIR/frontend"
rm -rf node_modules package-lock.json
npm install --package-lock=false
NODE_OPTIONS="--max-old-space-size=512" npm run build
echo "Frontend built → $REPO_DIR/frontend/dist/"
# ── 3. Download OpenFrameworks aarch64 release ──────────────────────────────
echo ""
echo "=== Downloading OpenFrameworks ${OF_VERSION} (aarch64) ==="
mkdir -p "$REPO_DIR/_build"
if [ ! -d "$OF_DIR" ]; then
cd "$REPO_DIR/_build"
[ ! -f "$OF_FILE" ] && (wget "$OF_URL" || curl -L -O "$OF_URL")
tar -xzf "$OF_FILE"
mv "of_v${OF_VERSION}_linux"*"_release" openFrameworks
rm -f "$OF_FILE"
echo "OpenFrameworks extracted to $OF_DIR"
else
echo "OpenFrameworks already present, skipping download."
fi
# ── 4. Clone & patch ofxPiMapper ────────────────────────────────────────────
echo ""
echo "=== Cloning & patching ofxPiMapper ==="
ADDON_DIR="$OF_DIR/addons/ofxPiMapper"
rm -rf "$ADDON_DIR"
git clone --depth 1 https://github.com/kr15h/ofxPiMapper.git "$ADDON_DIR"
cd "$ADDON_DIR"
# 4a. OscControl.cpp highlight patch
OSC_FILE=$(find src -name "OscControl.cpp" | head -n 1)
if [ -n "$OSC_FILE" ]; then
sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/r /dev/stdin' "$OSC_FILE" <<'EOF_PATCH'
if (m.getAddress() == "/ofxPiMapper/surface/highlight"){
int surfaceIndex = m.getArgAsInt32(0);
mapper->getSurfaceManager()->selectSurface(surfaceIndex);
return;
}
EOF_PATCH
fi
# 4b. C++11 compat header
cat <<'EOF_COMPAT' > src/cpp11_compat.h
#ifndef OFXPIMAPPER_CPP11_COMPAT_H
#define OFXPIMAPPER_CPP11_COMPAT_H
#include <memory>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#if __cplusplus < 201402L
namespace std {
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
}
#endif
using std::unique_ptr;
using std::make_unique;
using std::vector;
using std::string;
#endif
EOF_COMPAT
sed -i '1i #include "cpp11_compat.h"' src/ofxPiMapper.h
find src -type f \( -name "*.h" -o -name "*.cpp" \) \
-exec sed -i 's/\([^:a-zA-Z0-9]\)unique_ptr\b/\1std::unique_ptr/g' {} + \
-exec sed -i 's/\([^:a-zA-Z0-9]\)make_unique\b/\1std::make_unique/g' {} +
for f in $(grep -l "unique_ptr" src/*.h 2>/dev/null || true); do
grep -q "<memory>" "$f" || sed -i '1i #include <memory>' "$f"
done
# 4c. Fix Vec3.cpp: in the #else (glm) branch, toOf() incorrectly returns
# ofVec3f instead of glm::vec3 — a bug in ofxPiMapper upstream.
sed -i '/^#else/,/^#endif/{
s/return ofVec3f(x, y, z);/return glm::vec3(x, y, z);/
}' src/Types/Vec3.cpp
# ── 5. Cross-compile ofxPiMapper for aarch64 ────────────────────────────────
# OF's Makefile supports PLATFORM_ARCH and CROSS_COMPILING as make variables —
# no need to fake uname. Passing them directly bypasses the uname -m check.
echo ""
echo "=== Cross-compiling ofxPiMapper (aarch64) ==="
if ! command -v aarch64-linux-gnu-g++ > /dev/null 2>&1; then
echo "ERROR: aarch64-linux-gnu-g++ not found. Install gcc-aarch64-linux-gnu."
exit 1
fi
cd "$ADDON_DIR/example_basic"
GLOBAL_FLAGS="-Wno-error -Wno-reorder -Wno-sign-compare -Wno-delete-non-virtual-dtor -std=c++11 -O0 -fno-tree-vrp -DOF_VERSION_MAJOR=0 -DOF_VERSION_MINOR=12"
# The OF Makefile has a bug: it calls `export $(PKG_CONFIG_PATH)` which passes the
# VALUE as a variable name under /bin/sh, causing "bad variable name" errors.
# Workaround: don't set PKG_CONFIG_PATH in the environment at all.
# Instead, create a thin wrapper script and pass it via OF's PKG_CONFIG make variable.
PKGCFG_WRAPPER="/usr/local/bin/aarch64-pkg-config"
cat > "$PKGCFG_WRAPPER" << 'PKGCFG_EOF'
#!/bin/sh
exec env \
PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig \
PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig \
PKG_CONFIG_SYSROOT_DIR="" \
pkg-config "$@"
PKGCFG_EOF
chmod +x "$PKGCFG_WRAPPER"
# Ensure PKG_CONFIG_PATH is not set in our environment (avoid the OF Makefile
# "export $(PKG_CONFIG_PATH)" bug which treats its value as a variable name).
unset PKG_CONFIG_PATH
unset PKG_CONFIG_LIBDIR
ARM64_PKG_CONFIG_PATH="/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig"
# OF's config.shared.mk uses $(shell find ...) to discover OF source subdirectory
# include paths and thirdparty lib headers. This can return empty in Docker
# cross-compile environments, causing "ofConstants.h: No such file or directory".
# Work around it by computing the include paths here and injecting them via
# PLATFORM_CFLAGS (which appears in the project compile command regardless).
OF_EXTRA_INCLUDES="-I$OF_DIR/libs/openFrameworks"
# OF source subdirectories (app, utils, math, gl, graphics, events, etc.)
for d in "$OF_DIR/libs/openFrameworks"/*/; do
[ -d "$d" ] && OF_EXTRA_INCLUDES="$OF_EXTRA_INCLUDES -I${d%/}"
done
# Thirdparty header-only libs bundled with OF (glm, json, kiss, tess2, utf8, ...)
for lib in "$OF_DIR/libs"/*/; do
libname=$(basename "$lib")
[ "$libname" = "openFrameworks" ] && continue
[ "$libname" = "openFrameworksCompiled" ] && continue
incdir="${lib}include"
[ -d "$incdir" ] || continue
while IFS= read -r subdir; do
OF_EXTRA_INCLUDES="$OF_EXTRA_INCLUDES -I$subdir"
done < <(find "$incdir" -type d)
done
# ofxPiMapper addon subdirectories (Sources/, Surfaces/, Textures/, etc.)
while IFS= read -r subdir; do
OF_EXTRA_INCLUDES="$OF_EXTRA_INCLUDES -I$subdir"
done < <(find "$ADDON_DIR/src" -type d)
# Bundled OF addons that ofxPiMapper depends on (e.g. ofxXmlSettings, ofxOsc, ...)
# Read the list from addons.make if present, otherwise include all bundled addon src dirs.
ADDONS_MAKE="$ADDON_DIR/example_basic/addons.make"
if [ -f "$ADDONS_MAKE" ]; then
while IFS= read -r addon_name; do
addon_name="${addon_name%%#*}" # strip comments
addon_name="$(echo "$addon_name" | tr -d '[:space:]')"
[ -z "$addon_name" ] && continue
addon_src="$OF_DIR/addons/$addon_name/src"
[ -d "$addon_src" ] || continue
while IFS= read -r subdir; do
OF_EXTRA_INCLUDES="$OF_EXTRA_INCLUDES -I$subdir"
done < <(find "$addon_src" -type d)
# Also include any libs/ bundled inside the addon (e.g. tinyxml in ofxXmlSettings)
addon_libs="$OF_DIR/addons/$addon_name/libs"
if [ -d "$addon_libs" ]; then
# Some addons (ofxXmlSettings) keep headers directly in libs/ (flat layout)
OF_EXTRA_INCLUDES="$OF_EXTRA_INCLUDES -I$addon_libs"
for alib in "$addon_libs"/*/; do
[ -d "$alib" ] || continue
# libs/<name>/include/ layout (e.g. other addons)
alib_inc="${alib}include"
if [ -d "$alib_inc" ]; then
while IFS= read -r subdir; do
OF_EXTRA_INCLUDES="$OF_EXTRA_INCLUDES -I$subdir"
done < <(find "$alib_inc" -type d)
else
# headers directly in libs/<name>/ (no include/ subdir)
OF_EXTRA_INCLUDES="$OF_EXTRA_INCLUDES -I${alib%/}"
fi
done
fi
done < "$ADDONS_MAKE"
fi
# Collect bundled static libs from OF's libs/*/lib/linuxaarch64/*.a
# The Makefile's auto-discovery skips these in cross-compile mode, so
# we add them explicitly via USER_LDFLAGS.
BUNDLED_LDFLAGS=""
for lib in "$OF_DIR/libs"/*/; do
libname=$(basename "$lib")
[ "$libname" = "openFrameworks" ] && continue
[ "$libname" = "openFrameworksCompiled" ] && continue
libdir="${lib}lib/linuxaarch64"
[ -d "$libdir" ] || continue
for a in "$libdir"/*.a; do
[ -f "$a" ] && BUNDLED_LDFLAGS="$BUNDLED_LDFLAGS $a"
done
done
make clean 2>/dev/null || true
make -j1 \
PKG_CONFIG="$PKGCFG_WRAPPER" \
PKG_CONFIG_LIBDIR="$ARM64_PKG_CONFIG_PATH" \
GST_VERSION=1.0 \
PLATFORM_ARCH=aarch64 \
CROSS_COMPILING=1 \
CC=aarch64-linux-gnu-gcc \
CXX=aarch64-linux-gnu-g++ \
AR=aarch64-linux-gnu-ar \
LD=aarch64-linux-gnu-ld \
PLATFORM_CFLAGS="$GLOBAL_FLAGS $OF_EXTRA_INCLUDES -I$ADDON_DIR/src" \
USER_CFLAGS="$GLOBAL_FLAGS" \
USER_CPPFLAGS="-std=c++11" \
USER_LDFLAGS="$BUNDLED_LDFLAGS" \
OF_PROJECT_OPTIMIZATION_FLAGS="-O0"
# ── 6. Collect artifacts ─────────────────────────────────────────────────────
echo ""
echo "=== Collecting artifacts ==="
mkdir -p "$BIN_OUT"
cp bin/example_basic "$BIN_OUT/ofxPiMapper"
chmod +x "$BIN_OUT/ofxPiMapper"
# ── 7. Commit and push artifacts ─────────────────────────────────────────────
echo ""
echo "=== Pushing artifacts to remote ==="
cd "$REPO_DIR"
git config user.email "build-bot@mpvj" 2>/dev/null || true
git config user.name "MPVJ Build Bot" 2>/dev/null || true
git add -f frontend/dist/ bin/ofxPiMapper
git commit -m "ci: add pre-built artifacts (frontend/dist + bin/ofxPiMapper)" || echo "(nothing new to commit)"
git push
echo ""
echo "============================================"
echo " BUILD COMPLETE + PUSHED"
echo "============================================"
echo " Frontend: $REPO_DIR/frontend/dist/"
echo " ofxPiMapper: $BIN_OUT/ofxPiMapper (aarch64)"
echo ""
echo " Run setup.sh on the Pi to deploy."
echo "============================================"

View File

@ -1,154 +1,419 @@
#!/bin/bash
# MPVJ Deployment Script
# Runs on the Raspberry Pi. Expects pre-built artifacts in the repo:
# frontend/dist/ — built by scripts/build.sh
# bin/ofxPiMapper — aarch64 binary built by scripts/build.sh
#
# Usage: sudo bash setup.sh <REPO_URL>
# MPVJ Headless Setup Script (Final Polish & Robustness)
# Usage: curl -sSL <URL>/setup.sh | sudo bash -s -- <REPO_URL>
set -e
set -euo pipefail
REPO_URL=$1
REPO_URL=${1:-}
if [ -z "$REPO_URL" ]; then
echo "Usage: sudo bash $0 <REPO_URL>"
exit 1
AP_ADDRESS="192.168.4.1/24"
AP_GATEWAY="192.168.4.1"
AP_DHCP_RANGE_START="192.168.4.20"
AP_DHCP_RANGE_END="192.168.4.150"
AP_CONNECTION_NAME="MPVJ-AP"
set_wifi_country() {
if command -v raspi-config > /dev/null 2>&1; then
raspi-config nonint do_wifi_country "$WIFI_COUNTRY" || true
fi
if [ -z "$BASH_VERSION" ]; then
echo "ERROR: This script must be run with bash."
exit 1
mkdir -p /etc/wpa_supplicant
if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then
if grep -q '^country=' /etc/wpa_supplicant/wpa_supplicant.conf; then
sed -i "s/^country=.*/country=$WIFI_COUNTRY/" /etc/wpa_supplicant/wpa_supplicant.conf
else
sed -i "1icountry=$WIFI_COUNTRY" /etc/wpa_supplicant/wpa_supplicant.conf
fi
else
cat <<EOF > /etc/wpa_supplicant/wpa_supplicant.conf
country=$WIFI_COUNTRY
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
EOF
fi
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR: Must be run as root (sudo)."
exit 1
fi
# Detect real user
REAL_USER=${SUDO_USER:-$(logname 2>/dev/null || true)}
[ -z "$REAL_USER" ] && REAL_USER=root
REAL_HOME=$(eval echo "~$REAL_USER" 2>/dev/null || echo "/root")
echo "Target User: $REAL_USER ($REAL_HOME)"
# Ensure whiptail is available
if ! command -v whiptail > /dev/null 2>&1; then
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get install -y whiptail
fi
# ── 0. SCRUB ─────────────────────────────────────────────────────────────────
echo "Stopping any running services..."
systemctl stop mpvj-backend.service 2>/dev/null || true
pkill -9 ofxPiMapper 2>/dev/null || true
pkill -9 node 2>/dev/null || true
rm -f /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock /var/cache/apt/archives/lock 2>/dev/null || true
if [ -d "$REAL_HOME/mpvj" ]; then
if whiptail --title "Cleanup" --yesno "Found existing MPVJ install. Wipe it for a clean install?" 10 60 < /dev/tty; then
rm -rf "$REAL_HOME/mpvj"
if [ -f /etc/default/crda ]; then
if grep -q '^REGDOMAIN=' /etc/default/crda; then
sed -i "s/^REGDOMAIN=.*/REGDOMAIN=$WIFI_COUNTRY/" /etc/default/crda
else
echo "REGDOMAIN=$WIFI_COUNTRY" >> /etc/default/crda
fi
fi
# ── 1. CONFIGURATION ─────────────────────────────────────────────────────────
HOSTNAME=$(whiptail --inputbox "Enter Hostname" 8 45 "mpvj" --title "Hostname" 3>&1 1>&2 2>&3 < /dev/tty) || exit 1
HOSTNAME=${HOSTNAME:-mpvj}
if command -v iw > /dev/null 2>&1; then
iw reg set "$WIFI_COUNTRY" || true
fi
}
WIFI_SSID=$(whiptail --inputbox "Enter WiFi SSID" 8 45 "MPVJ-AP" --title "WiFi SSID" 3>&1 1>&2 2>&3 < /dev/tty) || exit 1
WIFI_SSID=${WIFI_SSID:-MPVJ-AP}
configure_wlan0_static_profile() {
if [ -f /etc/dhcpcd.conf ]; then
sed -i '/# BEGIN MPVJ AP/,/# END MPVJ AP/d' /etc/dhcpcd.conf
cat <<EOF >> /etc/dhcpcd.conf
while true; do
WIFI_COUNTRY=$(whiptail --inputbox "Enter 2-letter Country Code (e.g. US, GB)" 8 45 "US" --title "WiFi Country" 3>&1 1>&2 2>&3 < /dev/tty) || exit 1
WIFI_COUNTRY=$(echo "$WIFI_COUNTRY" | tr '[:lower:]' '[:upper:]')
echo "$WIFI_COUNTRY" | grep -qE "^[A-Z]{2}$" && break
whiptail --msgbox "Country Code must be exactly 2 letters." 8 45 < /dev/tty
done
# BEGIN MPVJ AP
interface wlan0
static ip_address=$AP_ADDRESS
nohook wpa_supplicant
# END MPVJ AP
EOF
fi
}
while true; do
WIFI_PASS=$(whiptail --passwordbox "Enter WiFi Password (min 8 chars)" 8 45 --title "WiFi Password" 3>&1 1>&2 2>&3 < /dev/tty) || exit 1
[ ${#WIFI_PASS} -ge 8 ] && break
whiptail --msgbox "Minimum 8 characters required." 8 45 < /dev/tty
done
cleanup_legacy_access_point_stack() {
rm -f /etc/NetworkManager/conf.d/99-mpvj-unmanage-wlan0.conf
rm -f /etc/systemd/system/mpvj-ap-mode.service
systemctl disable mpvj-ap-mode.service hostapd.service dnsmasq.service 2>/dev/null || true
systemctl stop mpvj-ap-mode.service hostapd.service dnsmasq.service 2>/dev/null || true
# ── 2. SYSTEM SETUP ──────────────────────────────────────────────────────────
FREE_SPACE_KB=$(df / --output=avail | tail -n1)
if [ "$FREE_SPACE_KB" -lt 2097152 ]; then
whiptail --msgbox "Error: At least 2GB free space required." 8 45 < /dev/tty
exit 1
if [ -f /etc/dhcpcd.conf ]; then
sed -i '/# BEGIN MPVJ AP/,/# END MPVJ AP/d' /etc/dhcpcd.conf
fi
}
cleanup_networkmanager_access_point_stack() {
rm -f /etc/systemd/system/mpvj-nm-ap.service
systemctl disable mpvj-nm-ap.service 2>/dev/null || true
systemctl stop mpvj-nm-ap.service 2>/dev/null || true
nmcli connection down "$AP_CONNECTION_NAME" 2>/dev/null || true
}
configure_networkmanager_access_point() {
mkdir -p /etc/systemd/system /etc/NetworkManager/conf.d
cleanup_legacy_access_point_stack
cleanup_networkmanager_access_point_stack
cat <<EOF > /etc/NetworkManager/conf.d/90-mpvj-wifi-powersave.conf
[connection]
wifi.powersave = 2
EOF
cat <<EOF > /etc/sysctl.d/90-mpvj-ap.conf
net.ipv4.ip_forward=1
EOF
systemctl enable NetworkManager.service
systemctl restart NetworkManager.service
nmcli radio wifi on || true
nmcli connection delete "$AP_CONNECTION_NAME" 2>/dev/null || true
nmcli device set wlan0 managed yes || true
nmcli device set wlan0 autoconnect yes || true
nmcli device disconnect wlan0 2>/dev/null || true
if ! nmcli --wait 30 device wifi hotspot ifname wlan0 con-name "$AP_CONNECTION_NAME" ssid "$WIFI_SSID" band bg password "$WIFI_PASS"; then
echo "NetworkManager hotspot creation failed."
return 1
fi
echo "Installing runtime dependencies..."
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get install -y \
git hostapd dnsmasq avahi-daemon curl ffmpeg \
libzmq3-dev libavahi-compat-libdnssd-dev
if ! nmcli connection modify "$AP_CONNECTION_NAME" connection.interface-name wlan0; then
echo "NetworkManager hotspot tuning failed (interface-name)."
return 1
fi
if ! nmcli connection modify "$AP_CONNECTION_NAME" connection.autoconnect yes connection.autoconnect-priority 100 connection.wait-device-timeout 30000; then
echo "NetworkManager hotspot tuning failed (autoconnect)."
return 1
fi
if ! nmcli connection modify "$AP_CONNECTION_NAME" 802-11-wireless.mode ap 802-11-wireless.band bg 802-11-wireless.channel 7 802-11-wireless.powersave 2 802-11-wireless.cloned-mac-address permanent; then
echo "NetworkManager hotspot tuning failed (wireless)."
return 1
fi
if ! nmcli connection modify "$AP_CONNECTION_NAME" ipv4.method shared ipv4.addresses "$AP_ADDRESS" ipv4.shared-dhcp-range "$AP_DHCP_RANGE_START,$AP_DHCP_RANGE_END" ipv6.method disabled; then
echo "NetworkManager hotspot tuning failed (IP settings)."
return 1
fi
if ! nmcli connection modify "$AP_CONNECTION_NAME" 802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk "$WIFI_PASS" 802-11-wireless-security.proto rsn 802-11-wireless-security.pairwise ccmp 802-11-wireless-security.group ccmp 802-11-wireless-security.pmf 1; then
echo "NetworkManager hotspot tuning failed (security)."
return 1
fi
nmcli connection modify "$AP_CONNECTION_NAME" remove 802-1x || true
nmcli connection down "$AP_CONNECTION_NAME" 2>/dev/null || true
if ! command -v node > /dev/null 2>&1; then
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
cat <<EOF > /etc/systemd/system/mpvj-nm-ap.service
[Unit]
Description=Bring up MPVJ NetworkManager hotspot on boot
After=NetworkManager.service
Wants=NetworkManager.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/bash -lc 'nmcli radio wifi on || true; nmcli device set wlan0 managed yes || true; nmcli device set wlan0 autoconnect yes || true; nmcli connection reload; nmcli --wait 30 connection up "$AP_CONNECTION_NAME" ifname wlan0'
ExecStop=/usr/bin/bash -lc 'nmcli connection down "$AP_CONNECTION_NAME" 2>/dev/null || true'
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable mpvj-nm-ap.service avahi-daemon.service
if ! systemctl restart mpvj-nm-ap.service; then
echo "NetworkManager hotspot activation failed."
return 1
fi
# Hostname
hostnamectl set-hostname "$HOSTNAME"
sed -i "s/127.0.1.1.*/127.0.1.1\t$HOSTNAME/g" /etc/hosts || true
echo "NetworkManager hotspot configured successfully."
return 0
}
configure_legacy_access_point_stack() {
mkdir -p /etc/hostapd /etc/systemd/system /etc/NetworkManager/conf.d
cleanup_networkmanager_access_point_stack
# ── 3. NETWORKING ────────────────────────────────────────────────────────────
echo "Configuring networking..."
cat <<EOF > /etc/hostapd/hostapd.conf
country_code=$WIFI_COUNTRY
interface=wlan0
driver=nl80211
ssid=$WIFI_SSID
hw_mode=g
channel=7
country_code=$WIFI_COUNTRY
ieee80211n=1
wmm_enabled=1
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=$WIFI_PASS
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
EOF
[ -f /etc/default/hostapd ] && \
sed -i 's|#DAEMON_CONF=""|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
[ -f /etc/dnsmasq.conf ] && mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak || true
cat <<EOF > /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"
EOF
if [ -f /etc/dnsmasq.conf ] && [ ! -f /etc/dnsmasq.conf.mpvj-backup ]; then
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.mpvj-backup
fi
cat <<EOF > /etc/dnsmasq.conf
interface=wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
address=/$HOSTNAME.local/192.168.4.1
bind-interfaces
listen-address=$AP_GATEWAY
domain-needed
bogus-priv
dhcp-range=$AP_DHCP_RANGE_START,$AP_DHCP_RANGE_END,255.255.255.0,24h
address=/$HOSTNAME.local/$AP_GATEWAY
EOF
if [ -f /etc/dhcpcd.conf ] && ! grep -q "interface wlan0" /etc/dhcpcd.conf; then
printf '\ninterface wlan0\n static ip_address=192.168.4.1/24\n nohook wpa_supplicant\n' >> /etc/dhcpcd.conf
cat <<'EOF' > /etc/systemd/system/mpvj-ap-mode.service
[Unit]
Description=Prepare wlan0 for MPVJ access point mode
DefaultDependencies=no
After=systemd-udev-settle.service
Before=network-pre.target hostapd.service dnsmasq.service
Wants=network-pre.target hostapd.service dnsmasq.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/bash -c 'rfkill unblock wlan || true; systemctl stop wpa_supplicant.service wpa_supplicant@wlan0.service 2>/dev/null || true; ip link set wlan0 down || true; ip addr flush dev wlan0 || true; iw dev wlan0 set power_save off || true; ip link set wlan0 up; ip address add 192.168.4.1/24 dev wlan0'
ExecStop=/usr/bin/bash -c 'systemctl stop hostapd.service dnsmasq.service 2>/dev/null || true; ip addr flush dev wlan0 || true'
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF > /etc/NetworkManager/conf.d/99-mpvj-unmanage-wlan0.conf
[keyfile]
unmanaged-devices=interface-name:wlan0
EOF
cat <<EOF > /etc/sysctl.d/90-mpvj-ap.conf
net.ipv4.ip_forward=1
EOF
configure_wlan0_static_profile
systemctl daemon-reload
systemctl unmask hostapd dnsmasq 2>/dev/null || true
systemctl enable mpvj-ap-mode.service hostapd.service dnsmasq.service avahi-daemon.service
systemctl disable wpa_supplicant.service wpa_supplicant@wlan0.service 2>/dev/null || true
}
configure_access_point_stack() {
if command -v nmcli > /dev/null 2>&1 && systemctl list-unit-files NetworkManager.service --no-legend 2>/dev/null | grep -q '^NetworkManager\.service'; then
echo "Using NetworkManager hotspot configuration for wlan0..."
if ! configure_networkmanager_access_point; then
echo "Falling back to hostapd/dnsmasq hotspot configuration for wlan0..."
cleanup_networkmanager_access_point_stack
configure_legacy_access_point_stack
fi
else
echo "Using hostapd/dnsmasq hotspot configuration for wlan0..."
configure_legacy_access_point_stack
fi
}
if [ -z "$REPO_URL" ]; then
echo "Usage: $0 <REPO_URL>"
exit 1
fi
# ── 4. DEPLOY APP ────────────────────────────────────────────────────────────
echo "Deploying application from $REPO_URL ..."
# 0. BASH & ROOT CHECK
if [ -z "$BASH_VERSION" ]; then
echo "ERROR: This script must be run with BASH, not SH."
echo "Please use: sudo bash setup.sh $REPO_URL"
exit 1
fi
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR: This script must be run as root (use sudo)."
exit 1
fi
# Detect user
REAL_USER=${SUDO_USER:-$(logname)}
REAL_HOME=$(eval echo "~$REAL_USER")
echo "Target User: $REAL_USER ($REAL_HOME)"
# 0.5 SCRUB & SANITIZE PHASE
echo "Scrubbing system for a clean installation..."
systemctl stop mpvj-backend.service 2>/dev/null || true
pkill -9 ofxPiMapper 2>/dev/null || true
pkill -9 node 2>/dev/null || true
# Remove old setup artifacts
swapoff /swapfile_mpvj 2>/dev/null || true
rm -f /swapfile_mpvj 2>/dev/null || true
# Clear any stale apt locks
rm -f /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock /var/cache/apt/archives/lock 2>/dev/null || true
# Ask to wipe previous data for a fresh start
if [ -d "$REAL_HOME/mpvj" ] || [ -d "$REAL_HOME/openFrameworks" ]; then
if whiptail --title "Cleanup" --yesno "Found existing MPVJ or OpenFrameworks data. Wipe them for a clean install?" 10 60 < /dev/tty; then
echo "Wiping old directories..."
rm -rf "$REAL_HOME/mpvj" "$REAL_HOME/openFrameworks"
fi
fi
# 1. INTERROGATION PHASE
echo "Interrogating user for configuration..."
# 1.1 Hostname
while true; do
HOSTNAME=$(whiptail --inputbox "Enter Hostname (e.g. mpvj)" 8 45 "mpvj" --title "Hostname Configuration" 3>&1 1>&2 2>&3 < /dev/tty) || exit 1
HOSTNAME=${HOSTNAME:-mpvj}
if echo "$HOSTNAME" | grep -qE '^[a-zA-Z0-9-]+$'; then
break
fi
whiptail --msgbox "Error: Hostname may only contain letters, numbers, and hyphens." 8 60 < /dev/tty
done
# 1.2 SSID
WIFI_SSID=$(whiptail --inputbox "Enter WiFi SSID (e.g. MPVJ-AP)" 8 45 "MPVJ-AP" --title "WiFi SSID Configuration" 3>&1 1>&2 2>&3 < /dev/tty) || exit 1
WIFI_SSID=${WIFI_SSID:-MPVJ-AP}
# 1.3 Country Code & Password
while true; do
WIFI_COUNTRY=$(whiptail --inputbox "Enter 2-letter Country Code (e.g. US, GB)" 8 45 "US" --title "WiFi Country Configuration" 3>&1 1>&2 2>&3 < /dev/tty) || exit 1
WIFI_COUNTRY=$(echo "$WIFI_COUNTRY" | tr '[:lower:]' '[:upper:]')
if ! echo "$WIFI_COUNTRY" | grep -qE "^[A-Z]{2}$"; then
whiptail --msgbox "Error: Country Code must be 2 letters." 8 45 < /dev/tty
else
break
fi
done
while true; do
WIFI_PASS=$(whiptail --passwordbox "Enter WiFi Password (min 8 chars)" 8 45 --title "WiFi Password Configuration" 3>&1 1>&2 2>&3 < /dev/tty) || exit 1
if [ ${#WIFI_PASS} -lt 8 ]; then
whiptail --msgbox "Error: Minimum 8 characters required." 8 45 < /dev/tty
else
break
fi
done
# 2. SYSTEM STAGING PHASE
echo "System Staging Phase..."
# 2.1 Pre-Flight Disk Check
FREE_SPACE_KB=$(df / --output=avail | tail -n1)
if [ "$FREE_SPACE_KB" -lt 4194304 ]; then
whiptail --msgbox "Error: 4GB free space required." 8 45 < /dev/tty
exit 1
fi
# 2.2 System Updates
if command -v apt-get > /dev/null; then
apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
elif command -v pacman > /dev/null; then
pacman -Syu --noconfirm
fi
# 2.3 Install Dependencies
echo "Installing Core Dependencies..."
if command -v apt-get > /dev/null; then
DEBIAN_FRONTEND=noninteractive apt-get install -y git hostapd dnsmasq avahi-daemon curl ffmpeg build-essential libzmq3-dev libavahi-compat-libdnssd-dev wget unzip \
libmpg123-dev libsndfile1-dev libopenal-dev libassimp-dev \
libglew-dev libglfw3-dev liburiparser-dev \
libcurl4-openssl-dev libpugixml-dev libasound2-dev \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly gstreamer1.0-libav \
libgtk-3-dev libboost-filesystem-dev \
libfontconfig1-dev libfreetype-dev libx11-dev \
libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev \
libpulse-dev libudev-dev libfreeimage-dev librtaudio-dev \
freeglut3-dev libxxf86vm-dev
elif command -v pacman > /dev/null; then
pacman -S --noconfirm git hostapd dnsmasq avahi curl ffmpeg base-devel zeromq wget unzip
fi
# Install Node.js if missing
if ! command -v node > /dev/null; then
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - || true
command -v apt-get > /dev/null && apt-get install -y nodejs
fi
# 2.4 Hostname & WiFi Country
hostnamectl set-hostname "$HOSTNAME"
sed -i "s/127.0.1.1.*/127.0.1.1\t$HOSTNAME/g" /etc/hosts || true
set_wifi_country
# 2.5 OS-Agnostic Swap Increase (2GB)
echo "Ensuring 2GB Swap for build..."
if [ ! -f /swapfile_mpvj ]; then
fallocate -l 2G /swapfile_mpvj || dd if=/dev/zero of=/swapfile_mpvj bs=1M count=2048
chmod 600 /swapfile_mpvj
mkswap /swapfile_mpvj
swapon /swapfile_mpvj
fi
# 3. NETWORKING
echo "Configuring Networking..."
rfkill unblock wlan || true
configure_access_point_stack
# 4. DEPLOYMENT
echo "Deploying Application..."
[ -d "$REAL_HOME/mpvj" ] && mv "$REAL_HOME/mpvj" "$REAL_HOME/mpvj.old.$(date +%s)"
sudo -u "$REAL_USER" git clone "$REPO_URL" "$REAL_HOME/mpvj"
# Verify pre-built artifacts exist
if [ ! -d "$REAL_HOME/mpvj/frontend/dist" ]; then
echo "ERROR: frontend/dist/ not found in repo."
echo "Run scripts/build.sh on your x86_64 machine first and commit the artifacts."
exit 1
fi
if [ ! -f "$REAL_HOME/mpvj/bin/ofxPiMapper" ]; then
echo "ERROR: bin/ofxPiMapper not found in repo."
echo "Run scripts/build.sh on your x86_64 machine first and commit the artifacts."
exit 1
fi
# Install npm deps for backend only (no build needed)
cd "$REAL_HOME/mpvj/backend"
sudo -u "$REAL_USER" npm install --omit=optional --package-lock=false
# Install ofxPiMapper binary
install -m 755 "$REAL_HOME/mpvj/bin/ofxPiMapper" /usr/local/bin/ofxPiMapper
# Media directory
mkdir -p "$REAL_HOME/media"
chown -R "$REAL_USER:$REAL_USER" "$REAL_HOME/mpvj" "$REAL_HOME/media"
# ── 5. SYSTEMD SERVICE ───────────────────────────────────────────────────────
# 4.2 Build
export NODE_OPTIONS="--max-old-space-size=512"
cd "$REAL_HOME/mpvj/backend"
echo "Installing backend dependencies..."
rm -rf node_modules package-lock.json
sudo -u "$REAL_USER" npm install --omit=optional --package-lock=false
cd "$REAL_HOME/mpvj/frontend"
if [ ! -d "dist" ]; then
echo "Installing frontend dependencies and building..."
rm -rf node_modules package-lock.json
sudo -u "$REAL_USER" npm install --omit=optional --package-lock=false
sudo -u "$REAL_USER" npm run build
else
echo "Pre-built frontend detected. Skipping frontend build."
fi
# 4.3 Setup Systemd
cat <<EOF > /etc/systemd/system/mpvj-backend.service
[Unit]
Description=MPVJ Backend
@ -165,7 +430,7 @@ EOF
systemctl daemon-reload
systemctl enable mpvj-backend.service
# Write .env
# 4.4 .env
cat <<EOF > "$REAL_HOME/mpvj/backend/.env"
PORT=80
MPVJ_HOSTNAME=$HOSTNAME
@ -173,6 +438,18 @@ MPVJ_SSID=$WIFI_SSID
MPVJ_MEDIA_DIR=$REAL_HOME/media
EOF
# ── 6. DONE ───────────────────────────────────────────────────────────────────
whiptail --title "Success" --msgbox "INSTALL COMPLETE!\n\nRebooting into AP Mode.\nSSID: $WIFI_SSID\nIP: 192.168.4.1" 12 45 < /dev/tty
# 4.5 THE PRE-BUILT ENGINE SOLUTION (FASTEST)
echo "Installing Pre-compiled ofxPiMapper Binary..."
BINARY_URL="https://gitea.superwcpot.nl/timothy/mapper/raw/branch/main/bin/ofxPiMapper"
if ! curl -sSL -o /usr/local/bin/ofxPiMapper "$BINARY_URL"; then
wget -O /usr/local/bin/ofxPiMapper "$BINARY_URL"
fi
chmod +x /usr/local/bin/ofxPiMapper
# 5. FINALIZATION
echo "Cleaning up..."
swapoff /swapfile_mpvj 2>/dev/null || true
rm /swapfile_mpvj 2>/dev/null || true
whiptail --title "Success" --msgbox "INSTALL COMPLETE!\n\nRebooting into AP Mode.\nHostname: $HOSTNAME.local\nSSID: $WIFI_SSID\nPassword: $WIFI_PASS\nIP: $AP_GATEWAY" 14 60 < /dev/tty
reboot

View File

@ -1,14 +1,25 @@
#!/bin/bash
echo "Switching to AP Mode..."
# Stop wpa_supplicant for client mode
systemctl stop wpa_supplicant
set -euo pipefail
# Configure static IP for wlan0 (normally handled by dhcpcd or systemd-networkd)
# ifconfig wlan0 192.168.4.1
echo "Switching to AP mode..."
# Start AP services
systemctl start hostapd
systemctl start dnsmasq
rfkill unblock wlan || true
echo "AP Mode active: MPVJ-3B"
if command -v nmcli > /dev/null 2>&1 && nmcli connection show MPVJ-AP > /dev/null 2>&1; then
nmcli radio wifi on || true
nmcli device set wlan0 managed yes || true
nmcli device set wlan0 autoconnect yes || true
nmcli connection up MPVJ-AP ifname wlan0
else
systemctl stop wpa_supplicant.service wpa_supplicant@wlan0.service 2>/dev/null || true
ip link set wlan0 down || true
ip addr flush dev wlan0 || true
ip link set wlan0 up
ip address add 192.168.4.1/24 dev wlan0
systemctl start mpvj-ap-mode.service
systemctl restart hostapd.service
systemctl restart dnsmasq.service
fi
echo "AP mode active on wlan0 at 192.168.4.1"

View File

@ -1,14 +1,19 @@
#!/bin/bash
echo "Switching to Client Mode..."
# Stop AP services
systemctl stop hostapd
systemctl stop dnsmasq
set -euo pipefail
# Start wpa_supplicant
systemctl start wpa_supplicant
echo "Switching to client mode..."
# Normally would trigger a re-scan or wait for IP
# dhclient wlan0
if command -v nmcli > /dev/null 2>&1 && nmcli connection show MPVJ-AP > /dev/null 2>&1; then
nmcli connection down MPVJ-AP 2>/dev/null || true
nmcli device set wlan0 autoconnect yes || true
nmcli device connect wlan0 2>/dev/null || true
else
systemctl stop mpvj-ap-mode.service 2>/dev/null || true
systemctl stop hostapd.service dnsmasq.service
ip addr flush dev wlan0 || true
ip link set wlan0 up || true
systemctl start wpa_supplicant.service || systemctl start wpa_supplicant@wlan0.service
fi
echo "Client Mode active. Connecting to configured SSID..."
echo "Client mode active. wlan0 returned to wpa_supplicant."