#!/bin/bash
# Source From: blog.hackkey.net/archives/shell-for-speedtest-install
SCRIPTPATH=$(realpath $0)
#SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
#SCRIPTPATH=$(dirname $(readlink -f "$0"))
display_usage() {
echo -e "$SCRIPTPATH
"
echo -e " 快速为Debian/Ubuntu系统安装ookla speedtest测速程序."
echo -e " 可参考:https://www.speedtest.net/zh-Hans/apps/cli"
echo -e "
Usage:
debian-speedtest-install [hostname]"
echo -e "Example:
debian-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 'lsb_release -a'||{
echo -e " $1 目测不是debian系(Debian/Ubuntu)系统";
exit 0
}
ssh $1 'speedtest -V|grep -i "Speedtest by Ookla 1.0.0.2"' 2>/dev/null && {
echo -e " $1 已经安装 Speedtest,且为官方指定deb版";
exit 0
}
echo -e "-----------------------------"
## 安装了非官方版本 speedtest-cli 的情况
echo "来到了判断其他speedtest版本的情况"
ssh $1 'speedtest --version|grep -i "Python "' 2>/dev/null && {
echo -e " $1 系统安装了非官方发布 Python 版本的 speedtest-cli";
echo -e " $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'
}
scp /v/debian/ookla-speedtest-1.0.0-x86_64-linux.deb $1:/root/
ssh $1 'cd /root/;dpkg -i ookla-speedtest-1.0.0-x86_64-linux.deb'
#如有必要,修复安装依赖
#ssh $1 'apt -f install'
echo -e " All action done..."