#!/bin/ash
apt update -y
apt install -y tar xz-utils file jq
mkdir -p /mnt/server/resources /mnt/server/logs/
cd /mnt/server
echo "updating citizenfx resource files"
git clone https://github.com/citizenfx/cfx-server-data.git /tmp
cp -Rf /tmp/resources/* resources/
RELEASE_PAGE=$(curl -sSL https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/)
CHANGELOGS_PAGE=$(curl -sSL https://changelogs-live.fivem.net/api/changelog/versions/linux/server)
if [[ "${CFX_VERSION}" == "recommended" ]] || [[ -z ${CFX_VERSION} ]]; then
DOWNLOAD_LINK=$(echo $CHANGELOGS_PAGE | jq -r '.recommended_download')
elif [[ "${CFX_VERSION}" == "latest" ]]; then
DOWNLOAD_LINK=$(echo $CHANGELOGS_PAGE | jq -r '.latest_download')
else
VERSION_LINK=$(echo -e "${RELEASE_PAGE}" | grep -Eo '".*/*.tar.xz"' | grep -Po '(?<=href=")[^"]*' | sed 's/\"//g' | sed 's/\.\///1' | grep ${CFX_VERSION})
if [[ "${VERSION_LINK}" == "" ]]; then
echo -e "defaulting to recommedned as the version requested was invalid."
DOWNLOAD_LINK=$(echo $CHANGELOGS_PAGE | jq -r '.recommended_download')
else
DOWNLOAD_LINK=$(echo https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/${VERSION_LINK})
fi
fi
if [ ! -z "${DOWNLOAD_URL}" ]; then
if curl --output /dev/null --silent --head --fail ${DOWNLOAD_URL}; then
echo -e "link is valid. setting download link to ${DOWNLOAD_URL}"
DOWNLOAD_LINK=${DOWNLOAD_URL}
else
echo -e "link is invalid closing out"
exit 2
fi
fi
echo -e "Running curl -sSL ${DOWNLOAD_LINK} -o ${DOWNLOAD_LINK##*/}"
curl -sSL ${DOWNLOAD_LINK} -o ${DOWNLOAD_LINK##*/}
echo "Extracting fivem files"
FILETYPE=$(file -F ',' ${DOWNLOAD_LINK##*/} | cut -d',' -f2 | cut -d' ' -f2)
if [ "$FILETYPE" == "gzip" ]; then
tar xzvf ${DOWNLOAD_LINK##*/}
elif [ "$FILETYPE" == "Zip" ]; then
unzip ${DOWNLOAD_LINK##*/}
elif [ "$FILETYPE" == "XZ" ]; then
tar xvf ${DOWNLOAD_LINK##*/}
else
echo -e "unknown filetype. Exiting"
exit 2
fi
rm -rf ${DOWNLOAD_LINK##*/} run.sh
if [ -e server.cfg ]; then
echo "server config file exists"
else
echo "Downloading default fivem config"
curl https://raw.githubusercontent.com/ptero-eggs/game-eggs/main/gta/fivem/server.cfg >>server.cfg
fi
echo "install complete"