添加 删除与安装脚本加入本地目录检查

This commit is contained in:
2026-04-15 02:04:24 +08:00
parent 6f57abda16
commit 137216623c
4 changed files with 66 additions and 29 deletions

50
remove Normal file → Executable file
View File

@@ -1,27 +1,47 @@
#!/bin/bash
# Version Check
# Param Handle
VERSION=$(echo $1 | tr -d '/')
# Version History 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"
ALL_VERSIONS=$(echo "$TEXT" | grep -oP '[0-9]+\.[0-9]+(\.[0-9]+){1,2}')
# LATEST_VERSION=$(echo "$ALL_VERSIONS" | head -n1)
ALL_VERSIONS_NO_DOT=$(printf "%s\n" "$ALL_VERSIONS" | 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
if [[ -n $VERSION ]]; then
if echo "$ALL_VERSIONS" | tr -d '.' | grep -q "^$VERSION$"; then
FINAL_VERSION=$VERSION
else
echo "Error: version '$1' not found in version history."
echo "Error: version '$VERSION' not found in version history."
exit 1
fi
fi
# Local Folder Check
LOCAL_VERSIONS=$(printf '%s\n' * | grep -oP '[0-9]+[0-9]+([0-9]+)?+([0-9]+)?')
if printf '%s\n' "$LOCAL_VERSIONS" | grep -qx -- "$VERSION"; then
FINAL_VERSION="$VERSION"
else
echo "Latest version: $VERSION"
VERSION=$VERSION_NO_DOT
echo "Error: version '$VERSION' does not exist locally."
exit 1
fi
# Remove
rm /fr ./$VERSION
rm -fr ./$FINAL_VERSION