#!/bin/bash
# tshock install script for docker container
get_latest() {
  curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
  grep '"tag_name":' |                                            # Get tag line
  sed -E 's/.*"([^"]+)".*/\1/'                                    # Pluck JSON value
}
mkdir /world /config /logs /plugins /tshock
cd /tshock
[ "$TSHOCK_VERSION" == "latest" ] && TSHOCK_VERSION=`get_latest "Pryaxis/TShock"`
wget https://github.com/Pryaxis/TShock/releases/download/$TSHOCK_VERSION/TShock${TSHOCK_VERSION//v}_Terraria1.4.2.3.zip
unzip *.zip
rm *.zip
chmod +x /tshock/TerrariaServer.exe
chmod +x /start
