From e5976fdf4db5e94d215f548649cd6b152819d390 Mon Sep 17 00:00:00 2001 From: filesite-io Date: Tue, 25 Jun 2024 00:09:35 +0800 Subject: [PATCH] add desktop.docker.com connect detect function --- install.sh | 77 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 22 deletions(-) diff --git a/install.sh b/install.sh index d6b9d2d..ef8ba01 100755 --- a/install.sh +++ b/install.sh @@ -21,41 +21,74 @@ getCpuType () { cpu_info=`sysctl -n machdep.cpu.brand_string` if [[ $cpu_info == *"Intel"* ]]; then - return 1 #intel芯片 + return 1 #intel芯片 fi - return 2 #默认为苹果芯片 + return 2 #默认为苹果芯片 } +detectDomainCanConnect () { + domain=$1 + if [ -z "${domain}" ]; then + echo "Usage: detectDomainCanConnect domain" + exit 1 + fi + + ping_res=`ping -c 3 "${domain}"` + if [[ $ping_res == *"100.0% packet loss"* ]]; then + return 0 + fi + + return 1 +} + +#参数:connect_res,可选值:[0, 1] getDockerDesktopDownloadUrl () { - getCpuType - cup_type=$? - #原网址:https://desktop.docker.com/mac/main/arm64/Docker.dmg - dmgLink="https://static.jialuoma.cn/docker_desktop/arm64.dmg" + getCpuType + cup_type=$? - if [ $cup_type -eq 1 ]; then - #原网址:https://desktop.docker.com/mac/main/amd64/Docker.dmg - dmgLink="https://static.jialuoma.cn/docker_desktop/amd64.dmg" - fi + dmgLink_docker="https://desktop.docker.com/mac/main/arm64/Docker.dmg" + dmgLink="https://static.jialuoma.cn/docker_desktop/arm64.dmg" - echo "${dmgLink}" + if [ $cup_type -eq 1 ]; then + dmgLink_docker="https://desktop.docker.com/mac/main/amd64/Docker.dmg" + dmgLink="https://static.jialuoma.cn/docker_desktop/amd64.dmg" + fi + + connect_res=$1 + if [ $connect_res -eq 0 ]; then + echo "${dmgLink}" + else + #原网址 + echo "${dmgLink_docker}" + fi } downloadDockerDesktop () { - link=$1 - echo "docker desktop下载链接:${link}" - echo "即将在浏览器中打开docker desktop的下载链接并开始下载" - echo "请在docker desktop下载完成后,双击打开安装" - open "${link}" - - echo "如果你已经安装完成,请按Y继续安装machete镜像" - read -p "docker desktop已安装,继续?(Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1 - echo "正在为你安装machete镜像..." + link=$1 + if [ -z "${link}" ]; then + echo "Usage: downloadDockerDesktop url" + exit 1 + fi + + echo "docker desktop下载链接:${link}" + echo "即将在浏览器中打开docker desktop的下载链接并开始下载" + echo "请在docker desktop下载完成后,双击打开安装" + open "${link}" + + echo "如果你已经安装完成,请按Y继续安装machete镜像" + read -p "docker desktop已安装,继续?(Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1 + echo "正在为你安装machete镜像..." } -# 测试代码 + +# 安装docker desktop和machete welcome getCpuInfo getCpuType -link=`getDockerDesktopDownloadUrl` +detect_domain='https://desktop.docker.com' +echo "正在检测是否能连接[${detect_domain}],请稍后..." +detectDomainCanConnect "${detect_domain}" +connect_res=$? +link=`getDockerDesktopDownloadUrl $connect_res` downloadDockerDesktop "${link}"