Skip to content

Instantly share code, notes, and snippets.

@neildavis
Last active May 15, 2025 10:32
Show Gist options
  • Select an option

  • Save neildavis/08176ee619c59a70d6145bb742391ad7 to your computer and use it in GitHub Desktop.

Select an option

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 top level dir where we will build stuff
BUILD_DIR="${BUILD_DIR:-${HOME}/aburner2}"
# Var for mame2003-plus-libretro target platform
MAME_PLATFORM="${MAME_PLATFORM:-rpi3}"
# Var for mame2003-plus-libretro git REMOTE repo URL
GIT_URL_MAME="${GIT_URL_MAME:-https://github.com/neildavis/mame2003-plus-libretro}"
# Var for mame2003-plus-libretro git repo branch
GIT_BRANCH_MAME="${GIT_BRANCH_MAME:-javi_aburner2}"
# Var for mame2003-plus-libretro git LOCAL repo dir
GIT_DIR_MAME="${GIT_DIR_MAME:-${BUILD_DIR}/mame2003-plus-libretro}"
# Var for udd_rpi_lib git REMOTE repo URL
GIT_URL_UDD="${GIT_URL_UDD:-https://github.com/neildavis/udd_rpi_lib}"
# Var for udd_rpi_lib git repo branch
GIT_BRANCH_UDD="${GIT_BRANCH_UDD:-dev-nd}"
# Var for udd_rpi_lib git LOCAL repo dir
GIT_DIR_UDD="${GIT_DIR_UDD:-${BUILD_DIR}/udd_rpi_lib}"
# Var for RetroPie-Setup dir
RETROPIE_SETUP_DIR="${RETROPIE_SETUP_DIR:-${HOME}/RetroPie-Setup}"
# Var for where RetroPie stores libretro cores
LIBRETRO_CORES_DIR="${LIBRETRO_CORES_DIR:-/opt/retropie/libretrocores}"
# 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 fetch
git checkout -f "$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}" "${GIT_BRANCH_UDD}" "${GIT_DIR_UDD}"
# Clone the mame2003-plus-libretro repo
git_clone_or_pull "${GIT_URL_MAME}" "${GIT_BRANCH_MAME}" "${GIT_DIR_MAME}"
# Build udd_rpi_lib
echo "Building udd_rpi_lib"
cd "${GIT_DIR_UDD}"
sudo make install
# Build the lrmame2003osvr outputs server
echo "Building lrmame2003osvr (outputs server)"
cd "${GIT_DIR_MAME}/outputs"
if [[ -f "$HOME/bin/lrmame2003osvr" ]]; then
echo "Removing previous lrmame2003osvr install"
make uninstall
fi
make install
# Start the outputs server
systemctl --user start lrmame2003osvr 2> /dev/null || true
# Build mame2003-plus-libretro core
echo "Building mame2003-plus-libretro.so ..."
cd "${GIT_DIR_MAME}"
make system_platform=unix platform="${MAME_PLATFORM}" -j$(nproc)
# Replace RetroPie version of mame2003-plus-libretro.so with the one we just built
echo "Replacing RetroPie installed version of mame2003_plus_libretro.so with modified version we built ..."
RETROPIE_MAME_2003_PLUS_LIB="${LIBRETRO_CORES_DIR}/lr-mame2003-plus/mame2003_plus_libretro.so"
RETROPIE_MAME_2003_PLUS_LIB_BAK="${RETROPIE_MAME_2003_PLUS_LIB}.bak"
# Create a backup and symlink to redirect the original lib to our built version
if [[ ! -L "${RETROPIE_MAME_2003_PLUS_LIB}" ]]; then
# Backup the original
if [[ ! -f "${RETROPIE_MAME_2003_PLUS_LIB_BAK}" ]]; then
sudo mv "${RETROPIE_MAME_2003_PLUS_LIB}" "${RETROPIE_MAME_2003_PLUS_LIB_BAK}"
echo "Made a backup of RetroPie installed version of mame2003_plus_libretro.so at ${RETROPIE_MAME_2003_PLUS_LIB_BAK}"
fi
sudo ln -fs "${GIT_DIR_MAME}/mame2003_plus_libretro.so" "${RETROPIE_MAME_2003_PLUS_LIB}"
echo "Created symbolic link for mame2003_plus_libretro.so at ${RETROPIE_MAME_2003_PLUS_LIB}"
else
echo "Symbolic link for mame2003_plus_libretro.so already exists at ${RETROPIE_MAME_2003_PLUS_LIB}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment