下载并替换文件shell脚本,(检测是否安装了wget,显示下载进度条)

#!/bin/bash

# 网站文件的URL
remote_file_url="https://example.com/path/to/your/file.txt"
# 本地文件路径
local_file_path="/path/to/your/local/file.txt"

# 检查 wget 是否安装
if ! command -v wget &> /dev/null
then
    echo "wget 未安装,正在尝试安装..."
    if [ -f /etc/debian_version ]; then
        # Debian 或 Ubuntu 系统
        sudo apt-get update
        sudo apt-get install -y wget
    elif [ -f /etc/redhat-release ]; then
        # Red Hat 或 CentOS 系统
        sudo yum install -y wget
    else
        echo "不支持的系统,无法自动安装 wget,请手动安装。"
        exit 1
    fi
fi

# 下载文件并显示进度条
wget --progress=bar "$remote_file_url" -O temp_file
if [ $? -eq 0 ]; then
    # 下载成功,替换本地文件
    mv temp_file "$local_file_path"
    echo "文件下载并替换成功!"
else
    # 下载失败,删除临时文件
    rm -f temp_file
    echo "文件下载失败,请检查网络或URL。"
fi

发表回复

登录... 后才能评论