Skip to content

Commit 30440d5

Browse files
authored
fix(script/v4.sh): error judgement of empty version string (#18)
* fix(script/v4.sh): error judgement of empty version string - Fix an error in REAL_VERSION judgement on api failure - Access real version from cli to ensure actual version is stored * chore(v4.sh): simplify install logic
1 parent b2339e2 commit 30440d5

1 file changed

Lines changed: 23 additions & 18 deletions

File tree

script/v4.sh

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -670,19 +670,14 @@ INSTALL() {
670670
# 如果用户输入了代理地址,则使用代理拼接下载链接
671671
if [ -n "$proxy_input" ]; then
672672
GH_PROXY="$proxy_input"
673-
GH_DOWNLOAD_URL="${GH_PROXY}https://github.com/OpenListTeam/OpenList/releases/download"
673+
GH_DOWNLOAD_URL="${GH_PROXY}https://github.com/OpenListTeam/OpenList/releases/latest/download"
674674
echo -e "${GREEN_COLOR}已使用代理地址: $GH_PROXY${RES}"
675675
else
676676
# 如果不需要代理,直接使用默认链接
677-
GH_DOWNLOAD_URL="https://github.com/OpenListTeam/OpenList/releases/download"
677+
GH_DOWNLOAD_URL="https://github.com/OpenListTeam/OpenList/releases/latest/download"
678678
echo -e "${GREEN_COLOR}使用默认 GitHub 地址进行下载${RES}"
679679
fi
680680

681-
# 获取版本号
682-
echo -e "${GREEN_COLOR}获取版本信息...${RES}"
683-
REAL_VERSION=$(curl -s "https://api.github.com/repos/OpenListTeam/OpenList/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' 2>/dev/null || echo "$VERSION_TAG")
684-
GH_DOWNLOAD_URL="${GH_DOWNLOAD_URL}/${REAL_VERSION}"
685-
686681
# 下载 OpenList 程序
687682
echo -e "\r\n${GREEN_COLOR}下载 OpenList ...${RES}"
688683

@@ -719,6 +714,8 @@ INSTALL() {
719714
fi
720715

721716
# 记录真实版本信息
717+
VERSION_INFO=$($INSTALL_PATH/openlist version 2>&1)
718+
REAL_VERSION=$(echo "$VERSION_INFO" | grep "^Version:" | sed 's/Version://' | tr -d ' ' | grep . || echo "$VERSION_TAG")
722719
echo "$REAL_VERSION" > "$VERSION_FILE"
723720
echo "$(date '+%Y-%m-%d %H:%M:%S')" >> "$VERSION_FILE"
724721

@@ -828,27 +825,33 @@ UPDATE() {
828825
echo -e "${GREEN_COLOR}已使用代理地址: $GH_PROXY${RES}"
829826
else
830827
# 如果不需要代理,直接使用默认链接
828+
GH_PROXY=""
831829
GH_DOWNLOAD_URL="https://github.com/OpenListTeam/OpenList/releases/download"
832830
echo -e "${GREEN_COLOR}使用默认 GitHub 地址进行下载${RES}"
833831
fi
834832

835833
# 获取真实版本信息
836834
echo -e "${GREEN_COLOR}获取版本信息...${RES}"
837-
REAL_VERSION=$(curl -s "https://api.github.com/repos/OpenListTeam/OpenList/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' 2>/dev/null || echo "$VERSION_TAG")
835+
REAL_VERSION=$(curl -s "https://api.github.com/repos/OpenListTeam/OpenList/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' 2>/dev/null | grep . || echo "$VERSION_TAG")
838836

839-
# 检查当前版本
840-
CURRENT_VERSION=""
841-
if [ -f "$VERSION_FILE" ]; then
842-
CURRENT_VERSION=$(head -n1 "$VERSION_FILE" 2>/dev/null)
843-
fi
837+
if [ "$REAL_VERSION" = "beta" ]; then
838+
# 网络问题,获取失败,默认使用latest下载地址
839+
echo -e "${YELLOW_COLOR}提示:获取最新版本信息失败,默认升级到latest版本!${RES}"
840+
GH_DOWNLOAD_URL="${GH_PROXY}https://github.com/OpenListTeam/OpenList/releases/latest/download"
841+
else
842+
# 检查当前版本
843+
CURRENT_VERSION=""
844+
if [ -f "$VERSION_FILE" ]; then
845+
CURRENT_VERSION=$(head -n1 "$VERSION_FILE" 2>/dev/null)
846+
fi
844847

845-
if [ -n "$CURRENT_VERSION" ] && [ "$CURRENT_VERSION" = "$REAL_VERSION" ]; then
846-
echo -e "${GREEN_COLOR}当前已是最新版本 ($CURRENT_VERSION),无需更新${RES}"
847-
return 0
848+
if [ -n "$CURRENT_VERSION" ] && [ "$CURRENT_VERSION" = "$REAL_VERSION" ]; then
849+
echo -e "${GREEN_COLOR}当前已是最新版本 ($CURRENT_VERSION),无需更新${RES}"
850+
return 0
851+
fi
852+
GH_DOWNLOAD_URL="${GH_DOWNLOAD_URL}/${REAL_VERSION}"
848853
fi
849854

850-
GH_DOWNLOAD_URL="${GH_DOWNLOAD_URL}/${REAL_VERSION}"
851-
852855
# 停止 OpenList 服务
853856
echo -e "${GREEN_COLOR}停止 OpenList 进程${RES}\r\n"
854857
systemctl stop openlist
@@ -906,6 +909,8 @@ UPDATE() {
906909
fi
907910

908911
# 更新真实版本信息
912+
VERSION_INFO=$($INSTALL_PATH/openlist version 2>&1)
913+
REAL_VERSION=$(echo "$VERSION_INFO" | grep "^Version:" | sed 's/Version://' | tr -d ' ' | grep . || echo "$REAL_VERSION")
909914
echo "$REAL_VERSION" > "$VERSION_FILE"
910915
echo "$(date '+%Y-%m-%d %H:%M:%S')" >> "$VERSION_FILE"
911916

0 commit comments

Comments
 (0)