#!/usr/bin/env bash # Also will build libSwell for you. set -eo pipefail C_RED=$(tput setaf 1) C_GREEN=$(tput setaf 2) C_BLUE=$(tput setaf 4) C_RESET=$(tput sgr0) fail() { echo "${C_RED}Error: $1${C_RESET}" >&2 exit 1 } success() { echo "${C_GREEN}$1${C_RESET}" } info() { echo "${C_BLUE}$1${C_RESET}" } REAPER_VERSION="761" REAPER_TAR="reaper${REAPER_VERSION}_linux_x86_64.tar.xz" REAPER_URL="https://www.reaper.fm/files/7.x/${REAPER_TAR}" INSTALL_DIR="/opt" TMP_DIR="/tmp" EXTRACT_DIR="reaper_linux_x86_64" WDL_DIR="${TMP_DIR}/WDL" SAFE_PROC="$(nproc --ignore=1)" fetch_deps() { for cmd in wget tar xdg-desktop-menu xdg-icon-resource xdg-mime; do command -v "$cmd" >/dev/null 2>&1 || fail "Required command '$cmd' not found. Please install it first." done DEPS=(libgtk-3-0t64 libmp3lame0 ffmpeg vlc build-essential libgtk-3-dev git) MISSING_DEPS=() for pkg in "${DEPS[@]}"; do if ! dpkg -s "$pkg" &>/dev/null; then MISSING_DEPS+=("$pkg") fi done if [ ${#MISSING_DEPS[@]} -gt 0 ]; then info "Installing missing dependencies: ${MISSING_DEPS[*]}" sudo apt-get update || fail "Failed to update package lists" sudo apt-get install -y "${MISSING_DEPS[@]}" || fail "Failed to install dependencies" else success "All dependencies already installed." fi return 0 } install() { if [ -d "${INSTALL_DIR}/REAPER" ] && [ -f "${INSTALL_DIR}/REAPER/reaper" ]; then success "REAPER is already installed in ${INSTALL_DIR}/REAPER, nothing to do." return 0 fi if [ -f "${TMP_DIR}/${REAPER_TAR}" ]; then success "REAPER archive already downloaded in ${TMP_DIR}/${REAPER_TAR}." else info "Downloading REAPER ${REAPER_VERSION}..." wget "${REAPER_URL}" -O "${TMP_DIR}/${REAPER_TAR}" || fail "Failed to download REAPER from ${REAPER_URL}" fi if [ -d "${TMP_DIR}/${EXTRACT_DIR}" ]; then success "REAPER archive already extracted in ${TMP_DIR}/${EXTRACT_DIR}." else info "Extracting REAPER to ${TMP_DIR}/${EXTRACT_DIR}..." tar -xf "${TMP_DIR}/${REAPER_TAR}" -C "${TMP_DIR}" || fail "Failed to extract REAPER tarball" fi if [ ! -f "${TMP_DIR}/${EXTRACT_DIR}/install-reaper.sh" ]; then fail "install-reaper.sh not found in extracted archive" fi info "Running REAPER installer..." cd "${TMP_DIR}/${EXTRACT_DIR}" || fail "Failed to change directory to ${TMP_DIR}/${EXTRACT_DIR}" sudo sh ./install-reaper.sh --install "${INSTALL_DIR}" --integrate-sys-desktop --usr-local-bin-symlink --quiet || fail "REAPER installation failed" if [ ! -f "${INSTALL_DIR}/REAPER/reaper" ] || [ ! -L "/usr/local/bin/reaper" ]; then fail "REAPER installation failed: executable or symlink not found after installation, please check the installer output for details." fi success "REAPER ${REAPER_VERSION} installed successfully!" success "Installation path: ${INSTALL_DIR}/REAPER" success "Symlink: /usr/local/bin/reaper" return 0 } libSwell() { info "Building libSwell.so..." if [ -d "${WDL_DIR}" ]; then success "WDL build directory already exists at ${WDL_DIR}, skipping clone." else git clone "https://www-dev.cockos.com/wdl/WDL.git" "${WDL_DIR}" || fail "Failed to clone WDL repository" fi cd "${WDL_DIR}/WDL/swell" || fail "Failed to change directory to ${WDL_DIR}/WDL/swell" make -j"${SAFE_PROC}" || fail "Failed to build libSwell.so" info "Installing custom libSwell.so..." sudo cp -f "${WDL_DIR}/WDL/swell/libSwell.so" "${INSTALL_DIR}/REAPER/libSwell.so" || fail "Failed to install libSwell.so" success "libSwell.so installed successfully" success "Installed libSwell.so path: ${INSTALL_DIR}/REAPER/libSwell.so" return 0 } cleanup() { info "Cleaning up..." if [ -d "${TMP_DIR}/${EXTRACT_DIR}" ]; then rm -rf "${TMP_DIR:?}/${EXTRACT_DIR:?}" || fail "Failed to remove temporary extraction directory" fi if [ -f "${TMP_DIR}/${REAPER_TAR}" ]; then rm -f "${TMP_DIR}/${REAPER_TAR}" || fail "Failed to remove temporary REAPER tarball" fi if [ -d "${WDL_DIR}" ]; then rm -rf "${WDL_DIR}" || fail "Failed to remove WDL build directory" fi return 0 } fetch_deps || fail "Dependency installation failed" install || fail "REAPER installation failed" libSwell || fail "libSwell installation failed" cleanup || fail "Cleanup failed"