Skip to content

分享一个openwrt中检查是否有更新版本的rtp2httpd,并且更新到最新版本的shell脚本,主要是为了方便 #319

@QiangGeCode

Description

@QiangGeCode
#!/bin/bash

# 获取 GitHub 上最新的版本号(去掉开头的 'v')
latest_version=$(curl -s https://api.github.com/repos/stackia/rtp2httpd/releases/latest | grep tag_name | cut -f4 -d "\"" | cut -c2-)

# 检查是否成功获取到最新版本
if [ -z "$latest_version" ]; then
    echo "错误:无法从 GitHub 获取最新版本信息。"
    exit 1
fi

# 获取当前安装的版本号
installed_version=$(rtp2httpd -h 2>/dev/null | grep Version | cut -f2 -d " ")

# 检查 rtp2httpd 命令是否存在且能返回版本
if [ -z "$installed_version" ]; then
    echo "错误:未找到 rtp2httpd 命令或无法获取其版本信息。"
    exit 1
fi

# 比较版本号(使用 sort -V 进行语义化版本比较)
if [ "$(printf '%s\n%s' "$installed_version" "$latest_version" | sort -V | head -n1)" = "$installed_version" ] && \
   [ "$installed_version" != "$latest_version" ]; then
    # installed_version <= latest_version 且不相等 → 有更新
    echo "rtp2httpd有更新的版本,版本号为:$latest_version"

    # 提示用户是否更新
    read -p "是否要更新到最新版本?[Y/n] " choice
    case "$choice" in
        n|N)
            echo "已取消更新。"
            ;;
        *)
            echo "正在运行安装脚本..."
            if uclient-fetch -q -O - https://raw.githubusercontent.com/stackia/rtp2httpd/main/scripts/install-openwrt.sh | sh; then
                echo "rtp2httpd 已成功更新!"
            else
                echo "更新失败!请手动检查网络或权限问题。"
                exit 1
            fi
            ;;
    esac
else
    echo "当前安装的rtp2httpd($installed_version)为最新的版本"
fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions