Shell脚本:centos-speedtest-install,Cygwin自动为RedHat/CentOS系统安装ookla speedtest测速程序

stevehe 2021年08月02日 224次浏览
#!/bin/bash 
SCRIPTPATH=$(realpath $0)
#SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
#SCRIPTPATH=$(dirname $(readlink -f "$0"))

display_usage() {
	echo -e "$SCRIPTPATH\n"
    echo -e "\t快速为CentOS/RedHat系统安装ookla speedtest测速程序."
	echo -e "\t可参考:https://www.speedtest.net/zh-Hans/apps/cli"
    echo -e "\nUsage:\n\tcentos-speedtest-install [hostname]"
	echo -e "Example:\n\tcentos-speedtest-install racknerd"
}
# if less than two arguments supplied, display usage
if [  $# -lt 1 ]
then
    display_usage
    exit 1
fi

# check whether user had supplied -h or --help . If yes display usage
if [[ ( $* == "--help") ||  $* == "-h" ]]
then
    display_usage
    exit 0
fi

ssh $1 'cat /etc/redhat-release'||{
echo -e "\t $1 目测不是CentOS/RedHat系统";
exit 0
}
ssh $1 'speedtest -V|grep -i "Speedtest by Ookla 1.0.0.2"' 2>/dev/null && {
echo -e "\t $1 已经安装 Speedtest,且为官方指定deb版";
exit 0
}
echo -e "-----------------------------"
## 安装了非官方版本 speedtest-cli 的情况
echo "来到了判断其他speedtest版本的情况"
ssh $1 'speedtest --version|grep -i "Python "' 2>/dev/null && {
echo -e "\t $1 系统安装了非官方发布 Python 版本的 speedtest-cli";
echo -e "\t $1 github地址:https://github.com/sivel/speedtest-cli";
#卸载非官方版本或者:移除同名文件,但不删除软件包;二选一即可
#way 1:删除非官方发行包
#ssh $1 'pip uninstall speedtest-cli'
#way 2:移除speedtest重名文件,使用 speedtest-cli 仍可访问非官方版本
#ssh $1 'rm -vf /usr/local/bin/speedtest'
}
## 如果未安装wget,则先安装
ssh $1 'wget -V 2>/dev/null||yum install -y wget'
##---- way 2 check wget has installed------
#ssh $1 'type wget>/dev/null||yum install -y wget'
ssh $1 'wget https://bintray.com/ookla/rhel/rpm -O /etc/yum.repos.d/bintray-ookla-rhel.repo;yum install -y speedtest'

echo -e "\tAll action done..."

image.png