From 6f57abda166ce43b2b1cc0bfd034ebd3b583a8b6 Mon Sep 17 00:00:00 2001 From: MyZOOO Date: Sun, 12 Apr 2026 16:41:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E5=AE=8C=E5=96=84latest?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=A1=8C=E4=B8=BA=E4=B8=8E=E6=97=A0=E5=8F=82?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + README.md | 39 +++++++++++++++++++++++++---- install | 72 ++++++++++++++++++++++++++++++++++++++++++++++++------ remove | 27 +++++++++++++++++++- run | 27 +++++++++++++++++++- 5 files changed, 152 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3602361 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +temp \ No newline at end of file diff --git a/README.md b/README.md index 8d9643d..05995a1 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,52 @@ # 泰拉瑞亚服务端安装脚本 此脚本可用于泰拉瑞亚服务端不同版本的安装、启动、卸载 ->⚠️注意!脚本目前仅适用于Ubuntu/Debian等使用apt作为包管理器的Linux发行版 +>⚠️注意!脚本目前仅适用于Linux发行版 ## 使用指南 +### 前置条件 +**脚本用到了`curl` `wget` `unzip`三个工具,脚本内置了工具是否安装的检查步骤** + +如未安装,请使用操作系统对应的包管理器安装 +#### Ubuntu / Debian 系 +使用apt包管理器安装 +```shell +sudo apt install curl wget unzip +``` + +#### Arch 系 +使用pacman包管理器安装 +```shell +sudo pacman -S curl wget unzip +``` + +#### RedHat 系 +使用yum或dnf包管理器安装 +```shell +sudo dnf install curl wget unzip +``` + +#### Apple Mac OS X +使用brew包管理器安装 +```shell +brew install curl wget unzip +``` + ### 1.安装 使用`install`加版本号即可安装泰拉瑞亚服务端 ```shell -install 1456 # 安装1.4.5.6 +bash install 1456 # 安装1.4.5.6 ``` ### 2.删除 使用`remove`加版本号即可删除泰拉瑞亚服务端 ```shell -remove 1456 # 卸载1.4.5.6 +bash remove 1456 # 卸载1.4.5.6 ``` ### 3.启动 使用`run`加版本号即可删除泰拉瑞亚服务端 ```shell -run 1456 # 启动1.4.5.6 +bash run 1456 # 启动1.4.5.6 ``` ->还可以使用`latest`参数直接安装、删除、启动最新版本 (尚未实现) \ No newline at end of file +>还可以使用`latest`参数直接安装、删除、启动最新版本 ~~(尚未实现)~~ +如果未填入参数,则直接按最新版本安装 \ No newline at end of file diff --git a/install b/install index a903c7b..07c58f3 100644 --- a/install +++ b/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 '(?<=).*?(?=)' +) +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 diff --git a/remove b/remove index 7aa697e..b17107d 100644 --- a/remove +++ b/remove @@ -1,2 +1,27 @@ #!/bin/bash -rm /fr ./$1 \ No newline at end of file + +# Version 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]+)?') +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 + +# Remove +rm /fr ./$VERSION \ No newline at end of file diff --git a/run b/run index 8288c4a..74c5eae 100644 --- a/run +++ b/run @@ -1,2 +1,27 @@ #!/bin/bash -bash ./$1/Linux/TerrariaServer + +# Version 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]+)?') +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 + +# Run +bash ./$VERSION/Linux/TerrariaServer