添加 完善latest参数行为与无参默认行为
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
temp
|
||||
39
README.md
39
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`参数直接安装、删除、启动最新版本 (尚未实现)
|
||||
>还可以使用`latest`参数直接安装、删除、启动最新版本 ~~(尚未实现)~~
|
||||
如果未填入参数,则直接按最新版本安装
|
||||
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
|
||||
|
||||
27
remove
27
remove
@@ -1,2 +1,27 @@
|
||||
#!/bin/bash
|
||||
rm /fr ./$1
|
||||
|
||||
# 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
|
||||
|
||||
# Remove
|
||||
rm /fr ./$VERSION
|
||||
27
run
27
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 '(?<=<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
|
||||
|
||||
# Run
|
||||
bash ./$VERSION/Linux/TerrariaServer
|
||||
|
||||
Reference in New Issue
Block a user