fix: fix heredoc terminator indentation causing syntax error in setup script

This commit is contained in:
Timothy Hofland
2026-03-12 19:42:25 +01:00
parent eecfe398d7
commit 6cc9d88842

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# MPVJ Headless Setup Script (Hardened & Pre-compiled OF) # MPVJ Headless Setup Script (Final Polish & Robustness)
# Usage: curl -sSL <URL>/setup.sh | sudo bash -s -- <REPO_URL> # Usage: curl -sSL <URL>/setup.sh | sudo bash -s -- <REPO_URL>
set -e set -e
@ -86,7 +86,10 @@ echo "System Staging Phase..."
# 2.1 Pre-Flight Disk Check # 2.1 Pre-Flight Disk Check
FREE_SPACE_KB=$(df / --output=avail | tail -n1) FREE_SPACE_KB=$(df / --output=avail | tail -n1)
[ "$FREE_SPACE_KB" -lt 4194304 ] && { whiptail --msgbox "Error: 4GB free space required." 8 45 < /dev/tty; exit 1; } 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 # 2.2 System Updates
if command -v apt-get > /dev/null; then if command -v apt-get > /dev/null; then
@ -159,11 +162,23 @@ sudo -u "$REAL_USER" git clone "$REPO_URL" "$REAL_HOME/mpvj"
mkdir -p "$REAL_HOME/media" mkdir -p "$REAL_HOME/media"
chown -R "$REAL_USER:$REAL_USER" "$REAL_HOME/mpvj" "$REAL_HOME/media" chown -R "$REAL_USER:$REAL_USER" "$REAL_HOME/mpvj" "$REAL_HOME/media"
# 4.2 Backend Install # 4.2 Build
export NODE_OPTIONS="--max-old-space-size=512"
cd "$REAL_HOME/mpvj/backend" cd "$REAL_HOME/mpvj/backend"
echo "Installing backend dependencies..."
rm -rf node_modules package-lock.json rm -rf node_modules package-lock.json
sudo -u "$REAL_USER" npm install --omit=optional --package-lock=false 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 # 4.3 Setup Systemd
cat <<EOF > /etc/systemd/system/mpvj-backend.service cat <<EOF > /etc/systemd/system/mpvj-backend.service
[Unit] [Unit]
@ -194,33 +209,17 @@ echo "Installing Pre-compiled OpenFrameworks (FAST)..."
cd "$REAL_HOME" cd "$REAL_HOME"
if [ ! -d "openFrameworks" ]; then if [ ! -d "openFrameworks" ]; then
echo "Downloading OpenFrameworks v0.12.1..." echo "Downloading OpenFrameworks v0.12.1..."
# Determine architecture for download
ARCH=$(uname -m) ARCH=$(uname -m)
OF_FILE="of_v0.12.1_linuxaarch64_release.tar.gz" # Default for 64-bit OF_FILE="of_v0.12.1_linuxaarch64_release.tar.gz"
[ "$ARCH" != "aarch64" ] && [ "$ARCH" != "x86_64" ] && OF_FILE="of_v0.12.1_linuxarmv6l_release.tar.gz"
if [ "$ARCH" != "aarch64" ] && [ "$ARCH" != "x86_64" ]; then
echo "32-bit or legacy ARM detected. Using armv6l version."
OF_FILE="of_v0.12.1_linuxarmv6l_release.tar.gz"
fi
# Use the user-suggested URL format if my default fails
DOWNLOAD_URL="https://github.com/openframeworks/openFrameworks/releases/download/0.12.1/$OF_FILE" DOWNLOAD_URL="https://github.com/openframeworks/openFrameworks/releases/download/0.12.1/$OF_FILE"
echo "Downloading from: $DOWNLOAD_URL"
if ! sudo -u "$REAL_USER" wget "$DOWNLOAD_URL"; then if ! sudo -u "$REAL_USER" wget "$DOWNLOAD_URL"; then
echo "Wget failed, trying manual fallback URL..."
sudo -u "$REAL_USER" curl -L -O "$DOWNLOAD_URL" sudo -u "$REAL_USER" curl -L -O "$DOWNLOAD_URL"
fi fi
echo "Extracting OpenFrameworks..."
sudo -u "$REAL_USER" tar -xzf "$OF_FILE" sudo -u "$REAL_USER" tar -xzf "$OF_FILE"
# Use a wildcard to handle the different folder names (aarch64 vs armv6l)
sudo -u "$REAL_USER" mv of_v0.12.1_linux*_release openFrameworks sudo -u "$REAL_USER" mv of_v0.12.1_linux*_release openFrameworks
sudo -u "$REAL_USER" rm "$OF_FILE" sudo -u "$REAL_USER" rm "$OF_FILE"
# Crucial: Install dependencies manually for Debian Trixie/modern systems
# Internal script is obsolete and looks for libgconf-2-4 which is gone.
echo "Installing modern dependencies for Debian Trixie..." echo "Installing modern dependencies for Debian Trixie..."
if command -v apt-get > /dev/null; then if command -v apt-get > /dev/null; then
DEBIAN_FRONTEND=noninteractive apt-get install -y \ DEBIAN_FRONTEND=noninteractive apt-get install -y \
@ -243,28 +242,31 @@ echo "Downloading and building ofxPiMapper Addon..."
cd "$REAL_HOME/openFrameworks/addons" cd "$REAL_HOME/openFrameworks/addons"
[ ! -d "ofxPiMapper" ] && sudo -u "$REAL_USER" git clone --depth 1 https://github.com/kr15h/ofxPiMapper.git [ ! -d "ofxPiMapper" ] && sudo -u "$REAL_USER" git clone --depth 1 https://github.com/kr15h/ofxPiMapper.git
# Apply the highlight patch to the addon before building # Apply patches to the addon before building
cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper" cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper"
if [ -f src/Osc/OscControl.cpp ]; then if [ -f src/Osc/OscControl.cpp ]; then
echo "Applying highlight surface OSC listener modification..." echo "Applying highlight patch..."
if ! grep -q "ofxPiMapper/surface/highlight" src/Osc/OscControl.cpp; then if ! grep -q "ofxPiMapper/surface/highlight" src/Osc/OscControl.cpp; then
sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/i \ # Create a temporary patch file
if (m.getAddress() == "/ofxPiMapper/surface/highlight"){ \ # terminator MUST NOT be indented
int surfaceIndex = m.getArgAsInt32(0); \ cat <<'EOF_PATCH' > /tmp/highlight.patch
mapper->getSurfaceManager()->selectSurface(surfaceIndex); \ if (m.getAddress() == "/ofxPiMapper/surface/highlight"){
return; \ int surfaceIndex = m.getArgAsInt32(0);
}' src/Osc/OscControl.cpp mapper->getSurfaceManager()->selectSurface(surfaceIndex);
fi return;
}
EOF_PATCH
sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/r /tmp/highlight.patch' src/Osc/OscControl.cpp
rm -f /tmp/highlight.patch
fi fi
fi
# Patch for unique_ptr namespace issue in VideoSource.h if [ -f src/Sources/VideoSource.h ]; then
if [ -f src/Sources/VideoSource.h ]; then
echo "Applying std:: namespace patch to VideoSource.h..." echo "Applying std:: namespace patch to VideoSource.h..."
sed -i 's/unique_ptr/std::unique_ptr/g' src/Sources/VideoSource.h sed -i 's/unique_ptr/std::unique_ptr/g' src/Sources/VideoSource.h
fi fi
fi
# Build Example (Clean call - let OF detect platform, but ignore Trixie compiler strictness) # Build Example
cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper/example_basic" cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper/example_basic"
echo "Starting compilation..." echo "Starting compilation..."
sudo -u "$REAL_USER" make -j1 USER_CFLAGS="-Wno-error -Wno-reorder -Wno-sign-compare -Wno-delete-non-virtual-dtor" sudo -u "$REAL_USER" make -j1 USER_CFLAGS="-Wno-error -Wno-reorder -Wno-sign-compare -Wno-delete-non-virtual-dtor"