BuildEnvironments/LinuxGeneralCompiler/dlvs.sh

49 lines
No EOL
1.4 KiB
Bash

#!/bin/bash
# Function to download game files based on version
download_game() {
local version=$1
local url
local extract_path="~/.local/share/vintagestory_${version}"
# Check if version contains a "-"
if [[ $version == *"-"* ]]; then
url="https://cdn.vintagestory.at/gamefiles/unstable/vs_server_linux-x64_${version}.tar.gz"
else
url="https://cdn.vintagestory.at/gamefiles/stable/vs_server_linux-x64_${version}.tar.gz"
fi
if [[ $version == *"-pre"* ]]; then
url="https://cdn.vintagestory.at/gamefiles/pre/vs_server_linux-x64_${version}.tar.gz"
fi
# Check if extract path already exists and is not empty
if [ -d "$extract_path" ] && [ ! -z "$(ls -A "$extract_path")" ]; then
echo "Extract path $extract_path already exists and is not empty, skipping download."
return
fi
# Download game files
download_path="/vs_server_linux-x64_${version}"
curl -k "$url" -o "${download_path}.tar.gz"
# Extract and clean up
mkdir -pv $extract_path
cd $extract_path
tar -xf "${download_path}.tar.gz" && rm -v "${download_path}.tar.gz"
if [ $? -eq 0 ]
then
cd /
echo "Successfully downloaded and extracted $version to $extract_path"
else
rm -rf "$download_path"
rm -rf "$extract_path"
echo "Game version ${version} was not found. Something went wrong. Cleaning up artifacts..."
cd /
fi
}
# Call the function with version as argument (e.g. "1.20.12")
download_game "$1"