#!/bin/bash #Toolkit Check if command -v unzip 1>/dev/null 2>&1; then printf "unzip is installed\n" else printf "unzip may not be installed. Do you want to continue? (Y/n) " read CHOICE if [[ $CHOICE == 'y' || $CHOICE == 'Y' ]]; then printf 'continue\n' else exit 1 fi fi if command -v curl 1>/dev/null 2>&1; then printf "curl is installed\n" else printf "curl may not be installed. Do you want to continue? (Y/n) " read CHOICE if [[ $CHOICE == 'y' || $CHOICE == 'Y' ]]; then printf 'continue\n' else exit 1 fi fi if command -v wget 1>/dev/null 2>&1; then printf "wget is installed\n" else printf "wget may not be installed. Do you want to continue? (Y/n) " read CHOICE if [[ $CHOICE == 'y' || $CHOICE == 'Y' ]]; then printf 'continue\n' else exit 1 fi fi # Version History Check TEXT=$( curl -s https://terraria.wiki.gg/wiki/Desktop_version_history | tr '\n' ' ' | grep -oP '(?<=
).*?(?=)' ) ALL_VERSIONS=$(echo "$TEXT" | grep -oP '[0-9]+\.[0-9]+(\.[0-9]+)?+(\.[0-9]+)?') LATEST_VERSION=$(printf "%s\n" "$ALL_VERSIONS" | head -n1) VERSION_NO_DOT=$(echo "$LATEST_VERSION" | tr -d '.') if [[ $1 == 'latest' ]]; then echo "Latest version: $VERSION" VERSION=$VERSION_NO_DOT elif [[ -n $1 ]]; then if echo "$ALL_VERSIONS" | tr -d '.' | grep -q "^$1$"; then VERSION=$1 echo "Selected version: $VERSION" else echo "Error: version '$1' not found in version history." exit 1 fi else echo "Latest version: $VERSION" VERSION=$VERSION_NO_DOT fi # Install wget https://terraria.org/api/download/pc-dedicated-server/terraria-server-$VERSION.zip unzip terraria-server-$VERSION.zip rm terraria-server-$VERSION.zip rm -fr ./$VERSION/Windows/ cd $VERSION/Linux/ chmod +x TerrariaServer.bin.x86_64