From e4d0b582cbeb15fda486bf3b3d68c0e852e140cc Mon Sep 17 00:00:00 2001 From: mack-a <57424792+mack-a@users.noreply.github.com> Date: Fri, 31 Jul 2020 09:55:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=85=BC=E5=AE=B9Ubuntu):=20=E5=85=BC?= =?UTF-8?q?=E5=AE=B9Ubuntu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- find_best_cdn_ip.sh | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/find_best_cdn_ip.sh b/find_best_cdn_ip.sh index 78af623..dea852f 100755 --- a/find_best_cdn_ip.sh +++ b/find_best_cdn_ip.sh @@ -54,9 +54,14 @@ pingTool(){ for ((i=0;i<${#ip[*]};i++)) do pingResult=`ping -c ${num} -W ${timeout} ${ip[$i]}` - packetLoss=`echo ${pingResult}|awk -F "[%]" '{print $1}'|awk -F "[p][a][c][k][e][t][s][ ][r][e][c][e][i][v][e][d][,][ ]" '{print $2}'` - roundTrip=`echo ${pingResult}|awk -F "[r][o][u][n][d][-][t][r][i][p]" '{print $2}'|awk '{print $3}'|awk -F "[/]" '{print $1"."$2"."$3"."$4}'|awk -F "[/]" '{print $1$2$3$4}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}'` + + if [[ "${release}" = "ubuntu" ]] + then + packetLoss=`echo ${pingResult}|awk -F "[%]" '{print $1}'|awk -F "[r][e][c][e][i][v][e][d][,][ ]" '{print $2}'` + roundTrip=`echo ${pingResult}|awk -F "[r][t][t]" '{print $2}'|awk '{print $3}'|awk -F "[/]" '{print $1"."$2"."$3"."$4}'|awk -F "[/]" '{print $1$2$3$4}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}'` + fi + ## |awk -F "[/]" '{print $1$2$3}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}' if [[ -z ${roundTrip} ]] then @@ -91,4 +96,35 @@ init(){ fi pingTool } +checkSystem(){ + + if [[ ! -z `find /etc -name "redhat-release"` ]] || [[ ! -z `cat /proc/version | grep -i "centos" | grep -v grep ` ]] || [[ ! -z `cat /proc/version | grep -i "red hat" | grep -v grep ` ]] || [[ ! -z `cat /proc/version | grep -i "redhat" | grep -v grep ` ]] + then + release="centos" + installType='yum -y install' + removeType='yum -y remove' + upgrade="yum update -y --skip-broken" + elif [[ ! -z `cat /etc/issue | grep -i "debian" | grep -v grep` ]] || [[ ! -z `cat /proc/version | grep -i "debian" | grep -v grep` ]] + then + release="debian" + installType='apt -y install' + upgrade="apt update -y" + removeType='apt -y autoremove' + elif [[ ! -z `cat /etc/issue | grep -i "ubuntu" | grep -v grep` ]] || [[ ! -z `cat /proc/version | grep -i "ubuntu" | grep -v grep` ]] + then + release="ubuntu" + installType='apt -y install' + upgrade="apt update -y" + removeType='apt --purge remove' + fi + if [[ -z ${release} ]] + then + echoContent red "本脚本不支持此系统,请将下方日志反馈给开发者" + cat /etc/issue + cat /proc/version + killSleep > /dev/null 2>&1 + exit 0; + fi +} +checkSystem init