添加 完善latest参数行为与无参默认行为
This commit is contained in:
72
install
72
install
@@ -1,9 +1,67 @@
|
||||
#!/bin/bash
|
||||
sudo apt update -y
|
||||
sudo apt install wget unzip -y
|
||||
wget https://terraria.org/api/download/pc-dedicated-server/terraria-server-$1.zip
|
||||
unzip terraria-server-$1.zip
|
||||
rm terraria-server-$1.zip
|
||||
rm -fr ./$1/Windows/
|
||||
cd $1/Linux/
|
||||
|
||||
#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 Check
|
||||
TEXT=$(
|
||||
curl -s https://terraria.wiki.gg/wiki/Desktop_version_history | tr '\n' ' ' | grep -oP '(?<=<tbody>).*?(?=</tbody>)'
|
||||
)
|
||||
ALL_VERSIONS=$(echo "$TEXT" | grep -oP '[0-9]+\.[0-9]+(\.[0-9]+)?+(\.[0-9]+)?')
|
||||
VERSION=$(echo "$ALL_VERSIONS" | head -n1)
|
||||
VERSION_NO_DOT=$(echo "$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
|
||||
|
||||
Reference in New Issue
Block a user