updated urls & code cleanup

This commit is contained in:
2020-10-30 15:02:22 +01:00
parent 9750b71f35
commit eb1935468f

View File

@@ -1,191 +1,158 @@
#!/bin/bash
CUR_V="$(find ${SERVER_DIR} -name installed_v_* | cut -d "_" -f3)"
if [ "${GAME_VERSION}" = "latest" ]; then
echo "---Getting latest OpenTTD build version...---"
LAT_V="$(curl -s https://api.github.com/repos/OpenTTD/OpenTTD/releases/latest | grep tag_name | cut -d '"' -f4)"
echo "---Latest OpenTTD build version is: $LAT_V---"
INSTALL_V=$LAT_V
if [ -z $LAT_V ]; then
echo "---Something went wrong, couldn't get latest build version---"
sleep infinity
fi
LAT_V="$(curl -s https://cdn.openttd.org/openttd-releases/latest.yaml | grep "version:" | cut -d ' ' -f3)"
echo "---Latest OpenTTD build version is: $LAT_V---"
INSTALL_V=$LAT_V
if [ -z $LAT_V ]; then
if [ -z $CUR_V ]; then
echo "---Something went wrong, couldn't get latest build version---"
sleep infinity
else
echo "---Can't get latest OpenTTD build version, falling back to installed version $CUR_V!---"
INSTALL_V=$CUR_V
fi
fi
else
INSTALL_V=${GAME_VERSION}
fi
GFX_PK_CUR_V="$(cat ${SERVER_DIR}/games/baseset/changelog.txt 2& >/dev/null | head -1 | cut -d ' ' -f2)"
if [ "${GFX_PK_V}" = "latest" ]; then
echo "---Getting latest OpenGFX version...---"
GFX_PK_V="$(curl -s https://cdn.openttd.org/opengfx-releases/latest.yaml | grep "version:" | cut -d ' ' -f3)"
echo "---Latest OpenGFX version is: $GFX_PK_V---"
if [ -z ${GFX_PK_V} ]; then
if [ -z $GFX_PK_CUR_V ]; then
echo "---Something went wrong, couldn't get latest build version---"
sleep infinity
else
echo "---Can't get latest OpenGFX version, falling back to installed version $GFX_PK_CUR_V!---"
GFX_PK_V=$GFX_PK_CUR_V
fi
fi
else
echo "---Manually set OpenGFX version to ${GFX_PK_V}---"
fi
echo "---Version Check---"
if [ ! -f ${SERVER_DIR}/games/openttd ]; then
echo
echo "-------------------------------------"
echo "-------------------------------------"
echo "---OpenTTD not found! Downloading,---"
echo "---compiling and installing v$INSTALL_V---"
echo "---Please be patient, this can take--"
echo "---some time, waiting 15 seconds..---"
echo "-------------------------------------"
sleep 15
cd ${SERVER_DIR}
if [ "${GAME_VERSION}" = "latest" ]; then
if wget -q -nc --show-progress --progress=bar:force:noscroll -O installed_v_$INSTALL_V https://proxy.binaries.openttd.org/openttd-releases/$INSTALL_V/openttd-$INSTALL_V-source.tar.xz ; then
echo "---Successfully downloaded OpenTTD v$INSTALL_V---"
else
echo "---Can't download OpenTTD v$INSTALL_V putting server into sleep mode---"
sleep infinity
fi
else
if wget -q -nc --show-progress --progress=bar:force:noscroll -O installed_v_$INSTALL_V http://master.binaries.openttd.org/binaries/releases/$INSTALL_V/openttd-$INSTALL_V-source.tar.xz ; then
echo "---Successfully downloaded OpenTTD v$INSTALL_V---"
else
echo "---Can't download OpenTTD v$INSTALL_V putting server into sleep mode---"
sleep infinity
fi
fi
mkdir compileopenttd
echo "---compiling and installing v$INSTALL_V---"
echo "---Please be patient, this can take--"
echo "---some time, waiting 15 seconds..---"
echo "-------------------------------------"
sleep 15
cd ${SERVER_DIR}
if wget -q -nc --show-progress --progress=bar:force:noscroll -O installed_v_$INSTALL_V https://cdn.openttd.org/openttd-releases/$INSTALL_V/openttd-$INSTALL_V-source.tar.xz ; then
echo "---Successfully downloaded OpenTTD v$INSTALL_V---"
else
echo "---Can't download OpenTTD v$INSTALL_V putting server into sleep mode---"
sleep infinity
fi
mkdir compileopenttd
tar -xf installed_v_$INSTALL_V -C ${SERVER_DIR}/compileopenttd/
COMPVDIR="$(find ${SERVER_DIR}/compileopenttd -name open* -print -quit)"
cd $COMPVDIR
$COMPVDIR/configure --prefix-dir=/serverdata/serverfiles --enable-dedicated --personal-dir=/serverfiles/openttd
if [ ! -z "${COMPILE_CORES}" ]; then
CORES_AVAILABLE=${COMPILE_CORES}
else
if [ ! -z "${COMPILE_CORES}" ]; then
CORES_AVAILABLE=${COMPILE_CORES}
else
CORES_AVAILABLE="$(getconf _NPROCESSORS_ONLN)"
fi
fi
make --jobs=$CORES_AVAILABLE
make install
rm -R ${SERVER_DIR}/compileopenttd
if [ ! -f ${SERVER_DIR}/games/openttd ]; then
echo "---Something went wrong, couldn't install OpenTTD v$INSTALL_V---"
sleep infinity
else
echo "---OpenTTD v$INSTALL_V installed---"
fi
if [ ! -d ${SERVER_DIR}/games/baseset ]; then
echo "---OpenGFX not found, downloading...---"
cd ${SERVER_DIR}/games
mkdir baseset
cd ${SERVER_DIR}/games/baseset
if wget -q -nc --show-progress --progress=bar:force:noscroll ${GFXPACK_URL} ; then
echo "---Successfully downloaded OpenGFX---"
else
echo "---Can't download OpenGFX putting server into sleep mode---"
sleep infinity
fi
unzip ${GFXPACK_URL##*/}
TAR="$( echo "${GFXPACK_URL##*/}" | rev | cut -d "." -f2- | rev)"
tar -xf $TAR.tar
mv ${SERVER_DIR}/games/baseset/${TAR}/* ${SERVER_DIR}/games/baseset
rm ${GFXPACK_URL##*/}
rm -R $TAR
rm $TAR.tar
GFX="$(find ${SERVER_DIR}/games/baseset -maxdepth 1 -name '*grf')"
if [ -z "$GFX" ]; then
echo "---Something went wrong, couldn't install OpenGFX---"
sleep infinity
fi
sleep infinity
else
echo "---OpenGFX found---"
fi
fi
CUR_V="$(find ${SERVER_DIR} -name installed_v_* | cut -d "_" -f3)"
if [ "$INSTALL_V" != "$CUR_V" ]; then
echo "---OpenTTD v$INSTALL_V installed---"
fi
elif [ "$INSTALL_V" != "$CUR_V" ]; then
echo
echo "-------------------------------------------------"
echo "-------------------------------------------------"
echo "---Version missmatch, installing v$INSTALL_V----------"
echo "------Changing from v$CUR_V to v$INSTALL_V-------------"
echo "----Please be patient this can take some time----"
echo "---------------Waiting 15 seconds----------------"
echo "-------------------------------------------------"
echo
sleep 15
cd ${SERVER_DIR}
rm installed_v_$CUR_V
rm -R games
rm -R share
if [ "${GAME_VERSION}" = "latest" ]; then
if wget -q -nc --show-progress --progress=bar:force:noscroll -O installed_v_$INSTALL_V https://proxy.binaries.openttd.org/openttd-releases/$INSTALL_V/openttd-$INSTALL_V-source.tar.xz ; then
echo "---Successfully downloaded OpenTTD v$INSTALL_V---"
else
echo "---Can't download OpenTTD v$INSTALL_V putting server into sleep mode---"
sleep infinity
fi
else
if wget -q -nc --show-progress --progress=bar:force:noscroll -O installed_v_$INSTALL_V http://master.binaries.openttd.org/binaries/releases/$INSTALL_V/openttd-$INSTALL_V-source.tar.xz ; then
echo "---Successfully downloaded OpenTTD v$INSTALL_V---"
else
echo "---Can't download OpenTTD v$INSTALL_V putting server into sleep mode---"
sleep infinity
fi
fi
echo "----Please be patient this can take some time----"
echo "---------------Waiting 15 seconds----------------"
echo "-------------------------------------------------"
echo
sleep 15
cd ${SERVER_DIR}
rm installed_v_$CUR_V
rm -R games
rm -R share
if wget -q -nc --show-progress --progress=bar:force:noscroll -O installed_v_$INSTALL_V https://cdn.openttd.org/openttd-releases/$INSTALL_V/openttd-$INSTALL_V-source.tar.xz ; then
echo "---Successfully downloaded OpenTTD v$INSTALL_V---"
else
echo "---Can't download OpenTTD v$INSTALL_V putting server into sleep mode---"
sleep infinity
fi
mkdir compileopenttd
tar -xf installed_v_$INSTALL_V -C ${SERVER_DIR}/compileopenttd/
COMPVDIR="$(find ${SERVER_DIR}/compileopenttd -name openttd-* -print -quit)"
cd $COMPVDIR
$COMPVDIR/configure --prefix-dir=/serverdata/serverfiles --enable-dedicated --personal-dir=/serverfiles/openttd
if [ ! -z "${COMPILE_CORES}" ]; then
CORES_AVAILABLE=${COMPILE_CORES}
else
if [ ! -z "${COMPILE_CORES}" ]; then
CORES_AVAILABLE=${COMPILE_CORES}
else
CORES_AVAILABLE="$(getconf _NPROCESSORS_ONLN)"
fi
fi
make --jobs=$CORES_AVAILABLE
make install
rm -R ${SERVER_DIR}/compileopenttd
if [ ! -f ${SERVER_DIR}/games/openttd ]; then
echo "---Something went wrong, couldn't install OpenTTD v$INSTALL_V---"
sleep infinity
else
echo "---OpenTTD v$INSTALL_V installed---"
fi
if [ ! -d ${SERVER_DIR}/games/baseset ]; then
echo "---OpenGFX not found, downloading...---"
cd ${SERVER_DIR}/games
mkdir baseset
cd ${SERVER_DIR}/games/baseset
if wget -q -nc --show-progress --progress=bar:force:noscroll ${GFXPACK_URL} ; then
echo "---Successfully downloaded OpenGFX---"
else
echo "---Can't download OpenGFX putting server into sleep mode---"
sleep infinity
fi
unzip ${GFXPACK_URL##*/}
TAR="$( echo "${GFXPACK_URL##*/}" | rev | cut -d "." -f2- | rev)"
tar -xf $TAR.tar
mv ${SERVER_DIR}/games/baseset/${TAR}/* ${SERVER_DIR}/games/baseset
rm ${GFXPACK_URL##*/}
rm -R $TAR
rm $TAR.tar
GFX="$(find ${SERVER_DIR}/games/baseset -maxdepth 1 -name '*grf')"
if [ -z "$GFX" ]; then
echo "---Something went wrong, couldn't install OpenGFX---"
sleep infinity
fi
sleep infinity
else
echo "---OpenGFX found---"
fi
echo "---OpenTTD v$INSTALL_V installed---"
fi
else
echo "---OpenTTD v$LAT_V found---"
fi
if [ ! -d ${SERVER_DIR}/games/baseset ]; then
echo "---OpenGFX not found, downloading...---"
cd ${SERVER_DIR}/games
mkdir baseset
cd ${SERVER_DIR}/games/baseset
if wget -q -nc --show-progress --progress=bar:force:noscroll ${GFXPACK_URL} ; then
cd ${SERVER_DIR}/games
mkdir ${SERVER_DIR}/games/baseset
cd ${SERVER_DIR}/games/baseset
if wget -q -nc --show-progress --progress=bar:force:noscroll -O opengfx-${GFX_PK_V}.zip https://cdn.openttd.org/opengfx-releases/${GFX_PK_V}/opengfx-${GFX_PK_V}-all.zip ; then
echo "---Successfully downloaded OpenGFX---"
else
echo "---Can't download OpenGFX putting server into sleep mode---"
sleep infinity
fi
unzip ${GFXPACK_URL##*/}
TAR="$( echo "${GFXPACK_URL##*/}" | rev | cut -d "." -f2- | rev)"
tar -xf $TAR.tar
mv ${SERVER_DIR}/games/baseset/${TAR}/* ${SERVER_DIR}/games/baseset
rm ${GFXPACK_URL##*/}
rm -R $TAR
rm $TAR.tar
GFX="$(find ${SERVER_DIR}/games/baseset -maxdepth 1 -name '*grf')"
if [ -z "$GFX" ]; then
echo "---Something went wrong, couldn't install OpenGFX---"
sleep infinity
fi
unzip opengfx-${GFX_PK_V}.zip
tar --strip-components=1 -xf opengfx-${GFX_PK_V}.tar
rm opengfx-${GFX_PK_V}.zip opengfx-${GFX_PK_V}.tar
GFX="$(find ${SERVER_DIR}/games/baseset -maxdepth 1 -name '*grf')"
if [ -z "$GFX" ]; then
echo "---Something went wrong, couldn't install OpenGFX---"
sleep infinity
fi
elif [ "$GFX_PK_CUR_V" != "$GFX_PK_V" ]; then
echo "---Newer version for OpenGFX found, installing!---"
rm -R ${SERVER_DIR}/games/baseset
mkdir ${SERVER_DIR}/games/baseset
cd ${SERVER_DIR}/games/baseset
if wget -q -nc --show-progress --progress=bar:force:noscroll -O opengfx-${GFX_PK_V}.zip https://cdn.openttd.org/opengfx-releases/${GFX_PK_V}/opengfx-${GFX_PK_V}-all.zip ; then
echo "---Successfully downloaded OpenGFX---"
else
echo "---Can't download OpenGFX putting server into sleep mode---"
sleep infinity
fi
unzip opengfx-${GFX_PK_V}.zip
tar --strip-components=1 -xf opengfx-${GFX_PK_V}.tar
rm opengfx-${GFX_PK_V}.zip opengfx-${GFX_PK_V}.tar
GFX="$(find ${SERVER_DIR}/games/baseset -maxdepth 1 -name '*grf')"
if [ -z "$GFX" ]; then
echo "---Something went wrong, couldn't install OpenGFX---"
sleep infinity
fi
else
echo "---OpenGFX found---"
fi