#!/bin/bash
apt -y install curl git jq tar
LATEST_JSON=$(curl --silent "https://api.github.com/repos/openmultiplayer/open.mp/releases/latest")
RELEASES=$(curl --silent "https://api.github.com/repos/openmultiplayer/open.mp/releases")
MATCH=open.mp-linux-x86-dynssl
if [ -z "${VERSION}" ] || [ "${VERSION}" == "latest" ]; then
DOWNLOAD_URL=$(echo ${LATEST_JSON} | jq .assets | jq -r .[].browser_download_url | grep -i ${MATCH})
else
VERSION_CHECK=$(echo ${RELEASES} | jq -r --arg VERSION "${VERSION}" '.[] | select(.tag_name==$VERSION) | .tag_name')
if [ "${VERSION}" == "${VERSION_CHECK}" ]; then
DOWNLOAD_URL=$(echo ${RELEASES} | jq -r --arg VERSION "${VERSION}" '.[] | select(.tag_name==$VERSION) | .assets[].browser_download_url' | grep -i ${MATCH})
else
echo -e "defaulting to latest release"
DOWNLOAD_URL=$(echo ${LATEST_JSON} | jq .assets | jq -r .[].browser_download_url | grep -linux-x86 | head -1)
fi
fi
echo "running: curl -sSL -o openmp.tar.gz ${DOWNLOAD_URL}"
curl -sSL -o openmp.tar.gz ${DOWNLOAD_URL}
mkdir -p /mnt/server
tar -xzvf openmp.tar.gz --strip-components=1 -C /mnt/server/
cd /mnt/server || exit
echo "creating default config"
if [ -e config.json ]; then
echo "server config file exists"
else
echo "Downloading default OpenMp config"
curl https://raw.githubusercontent.com/ptero-eggs/game-eggs/main/gta/openmp/config.json >> config.json
fi
echo "-----------------------------------------"
echo "Installation completed..."
echo "-----------------------------------------"