diff --git a/scripts/setup.sh b/scripts/setup.sh index d68567e..a3a9e6b 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -231,41 +231,59 @@ chown "$REAL_USER:$REAL_USER" "$REAL_HOME/mpvj/backend/.env" chmod 600 "$REAL_HOME/mpvj/backend/.env" # 4.5 Install ofxPiMapper Engine -echo "Installing OpenFrameworks and ofxPiMapper (This will take ~1 hour)..." -cd "$REAL_HOME" -if [ ! -d "openFrameworks" ]; then - sudo -u "$REAL_USER" git clone --depth 1 --branch master https://github.com/openframeworks/openFrameworks.git - cd openFrameworks/scripts/linux/debian - ./install_dependencies.sh -y > /dev/null 2>&1 - cd ../../../ - cd scripts/linux/debian - ./install_codecs.sh > /dev/null 2>&1 - cd ../../../ - sudo -u "$REAL_USER" make -j1 -C libs/openFrameworksCompiled/project/linux64 > /dev/null 2>&1 -fi +echo "Installing ofxPiMapper Engine..." -cd "$REAL_HOME/openFrameworks/addons" -if [ ! -d "ofxPiMapper" ]; then - sudo -u "$REAL_USER" git clone https://github.com/kr15h/ofxPiMapper.git - sudo -u "$REAL_USER" git clone https://github.com/vanderlin/ofxOfelia.git -fi +# Priority 1: Check for pre-built binary in the repo +if [ -f "$REAL_HOME/mpvj/bin/ofxPiMapper" ]; then + echo "Pre-built ofxPiMapper binary detected in repo. Installing..." + cp "$REAL_HOME/mpvj/bin/ofxPiMapper" /usr/local/bin/ofxPiMapper + chmod +x /usr/local/bin/ofxPiMapper + echo "ofxPiMapper installed successfully (Binary)." +else + # Priority 2: Build from source (Fall-back) + if [ -f "/usr/local/bin/ofxPiMapper" ]; then + echo "ofxPiMapper already installed in /usr/local/bin. Skipping build." + else + echo "No pre-built binary found. Falling back to source build (This takes ~1 hour)..." + cd "$REAL_HOME" + if [ ! -d "openFrameworks" ]; then + sudo -u "$REAL_USER" git clone --depth 1 --branch master https://github.com/openframeworks/openFrameworks.git + # Only run apt-get if we are on a Debian-based system + if command -v apt-get > /dev/null; then + cd openFrameworks/scripts/linux/debian + ./install_dependencies.sh -y + cd ../../../ + cd scripts/linux/debian + ./install_codecs.sh + cd ../../../ + sudo -u "$REAL_USER" make -j1 -C libs/openFrameworksCompiled/project/linux64 + else + echo "WARNING: Non-Debian system detected. Please install OpenFrameworks dependencies manually." + fi + fi -# Build Example with Highlight Patch -cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper" -if [ -f src/Osc/OscControl.cpp ]; then - echo "Applying highlight surface OSC listener modification..." - sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/i \ - if (m.getAddress() == "/ofxPiMapper/surface/highlight"){ \ - int surfaceIndex = m.getArgAsInt32(0); \ - mapper->getSurfaceManager()->selectSurface(surfaceIndex); \ - return; \ - }' src/Osc/OscControl.cpp -fi + cd "$REAL_HOME/openFrameworks/addons" + [ ! -d "ofxPiMapper" ] && sudo -u "$REAL_USER" git clone https://github.com/kr15h/ofxPiMapper.git + [ ! -d "ofxOfelia" ] && sudo -u "$REAL_USER" git clone https://github.com/vanderlin/ofxOfelia.git -cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper/example-basic" -sudo -u "$REAL_USER" make -j1 > /dev/null 2>&1 -cp bin/example-basic /usr/local/bin/ofxPiMapper -chmod +x /usr/local/bin/ofxPiMapper + # Patch and Build + cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper" + if [ -f src/Osc/OscControl.cpp ] && ! grep -q "highlight" src/Osc/OscControl.cpp; then + echo "Applying highlight patch..." + sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/i \ + if (m.getAddress() == "/ofxPiMapper/surface/highlight"){ \ + int surfaceIndex = m.getArgAsInt32(0); \ + mapper->getSurfaceManager()->selectSurface(surfaceIndex); \ + return; \ + }' src/Osc/OscControl.cpp + fi + + cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper/example-basic" + sudo -u "$REAL_USER" make -j1 + cp bin/example-basic /usr/local/bin/ofxPiMapper + chmod +x /usr/local/bin/ofxPiMapper + fi +fi # 5. FINALIZATION echo "Finalizing..."