Skip to content

Instantly share code, notes, and snippets.

@neildavis
Created April 4, 2024 14:24
Show Gist options
  • Save neildavis/08176ee619c59a70d6145bb742391ad7 to your computer and use it in GitHub Desktop.
Save neildavis/08176ee619c59a70d6145bb742391ad7 to your computer and use it in GitHub Desktop.
Script to install After Burner 2 outputs mod onto RetroPie 4.8
#!/usr/bin/env bash
# Var for RetroPie-Setup dir
RETROPIE_SETUP_DIR="${HOME}/RetroPie-Setup"
# Var for where RetroPie stores libretro cores
LIBRETRO_CORES_DIR="/opt/retropie/libretrocores"
# Var for top level dir where we will build stuff
BUILD_DIR="${HOME}/aburner2"
# Var for mame2003-plus-libretro git REMOTE repo URL
GIT_URL_MAME_2003_PLUS_LIBRETRO="https://github.com/neildavis/mame2003-plus-libretro"
# Var for mame2003-plus-libretro git repo branch
GIT_BRANCH_MAME_2003_PLUS_LIBRETRO="outputs_aburner2"
# Var for mame2003-plus-libretro git LOCAL repo dir
GIT_DIR_MAME_2003_PLUS_LIBRETRO="${BUILD_DIR}/mame2003-plus-libretro"
# Var for udd_rpi_lib git REMOTE repo URL
GIT_URL_UDD_RPI_LIB="https://github.com/neildavis/udd_rpi_lib"
# Var for udd_rpi_lib git repo branch
GIT_BRANCH_UDD_RPI_LIB="dev-nd"
# Var for udd_rpi_lib git LOCAL repo dir
GIT_DIR_UDD_RPI_LIB="${BUILD_DIR}/udd_rpi_lib"
# Func to clone or update a repo
# $1 = git remote URL, $2 = branch, $3 = dest dir
git_clone_or_pull() {
echo "Git clone $1 at branch $2 into $3 ..."
if [[ -d "$3" ]]; then
# repo has already been cloned, just pull updates
echo "Dir $3 already exists, pulling updates ..."
cd $3
git checkout "$2"
git pull
else
# repo has not yet been cloned. clone it
echo "Cloning $1 at branch $2 into $3 ..."
git clone -b "$2" "$1" "$3"
fi
}
# Let's get up to date!
echo "Updating OS ..."
# Update package repos index
sudo apt update
# Update OS
sudo apt -y upgrade
# Enable SPI if necessary
spi_enabled=$(sudo raspi-config nonint get_spi)
if [ $spi_enabled -eq 1 ]; then
echo "Enabling SPI ..."
sudo raspi-config nonint do_spi 0
else
echo "SPI is already enabled"
fi
# Use RetroPie-Setup to ensure that lr-mame2003 is NOT installed and lr-mame2003-plus IS installed
echo "Checking RetroPie libretro cores setup ..."
if [[ -d "${LIBRETRO_CORES_DIR}/lr-mame2003" ]]; then
echo "lr-mame2003 core is installed in RetroPie. Removing ..."
cd "${RETROPIE_SETUP_DIR}"
sudo ./retropie_packages.sh lr-mame2003 remove
else
echo "lr-mame2003 core is NOT installed in RetroPie. Good!"
fi
if [[ ! -d "${LIBRETRO_CORES_DIR}/lr-mame2003-plus" ]]; then
echo "lr-mame2003-plus core is NOT installed in RetroPie. Installing ..."
cd "${RETROPIE_SETUP_DIR}"
sudo ./retropie_packages.sh lr-mame2003-plus install_bin
sudo ./retropie_packages.sh lr-mame2003-plus configure
else
echo "lr-mame2003-plus core IS installed in RetroPie. Good!"
fi
# Install build tools and dependencies
echo "Installing build tools and dependencies ..."
sudo apt -y install build-essential git wiringpi
# Start to build stuff. Make the dir where we will clone code and build stuff
mkdir -p "${BUILD_DIR}"
# Clone the udd_rpi_lib repo
git_clone_or_pull "${GIT_URL_UDD_RPI_LIB}" "${GIT_BRANCH_UDD_RPI_LIB}" "${GIT_DIR_UDD_RPI_LIB}"
# Clone the mame2003-plus-libretro repo
git_clone_or_pull "${GIT_URL_MAME_2003_PLUS_LIBRETRO}" "${GIT_BRANCH_MAME_2003_PLUS_LIBRETRO}" "${GIT_DIR_MAME_2003_PLUS_LIBRETRO}"
# Build udd_rpi_lib
echo "Building udd_rpi_lib"
cd "${GIT_DIR_UDD_RPI_LIB}"
sudo make install
# Build the lrmame2003osvr outputs server
echo "Building lrmame2003osvr (outputs server)"
cd "${GIT_DIR_MAME_2003_PLUS_LIBRETRO}/outputs"
make install
# Build mame2003-plus-libretro core
echo "Building mame2003-plus-libretro.so ..."
cd "${GIT_DIR_MAME_2003_PLUS_LIBRETRO}"
make system_platform=unix platform=rpi3 -j$(nproc)
# Replace RetroPie version of mame2003-plus-libretro.so with the one we just built
echo "Replacing RetroPie with modified version we built ..."
RETROPIE_MAME_2003_PLUS_LIB="${LIBRETRO_CORES_DIR}/lr-mame2003-plus/mame2003_plus_libretro.so"
# Backup the original
sudo mv "${RETROPIE_MAME_2003_PLUS_LIB}" "${RETROPIE_MAME_2003_PLUS_LIB}.bak"
# Create a symlink to redirect the original lib to our built version
sudo ln -s "${GIT_DIR_MAME_2003_PLUS_LIBRETRO}/mame2003_plus_libretro.so" "${RETROPIE_MAME_2003_PLUS_LIB}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment