|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 显示欢迎信息
|
|
|
|
|
welcome () {
|
|
|
|
|
echo "==欢迎使用machete_installer=="
|
|
|
|
|
echo "本脚本为开源项目,网址:https://git.filesite.io/filesite/machete_installer"
|
|
|
|
|
echo "它将指引并安装docker desktop和machete的docker镜像"
|
|
|
|
|
echo "并完成machete的基本配置,在你的电脑上创建两个网站,一个管理图片,一个管理视频"
|
|
|
|
|
echo ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 获取mac mini的cpu芯片型号信息
|
|
|
|
|
getCpuInfo () {
|
|
|
|
|
cpu_info=`sysctl -n machdep.cpu.brand_string`
|
|
|
|
|
echo "你的电脑芯片型号:${cpu_info}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 获取电脑cpu类型
|
|
|
|
|
# 返回值:1 = intel芯片,2 = 苹果芯片
|
|
|
|
|
getCpuType () {
|
|
|
|
|
cpu_info=`sysctl -n machdep.cpu.brand_string`
|
|
|
|
|
|
|
|
|
|
if [[ $cpu_info == *"Intel"* ]]; then
|
|
|
|
|
return 1 #intel芯片
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return 2 #默认为苹果芯片
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 检测是否已经安装了docker
|
|
|
|
|
# 返回值:0 - 未安装,1 - 已安装
|
|
|
|
|
detectDockerInstalled () {
|
|
|
|
|
res=`command -v docker | wc -l`
|
|
|
|
|
if [ $res -gt 0 ]; then
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 检测docker desktop是否启动
|
|
|
|
|
# 返回值:0 - 未启动,1 - 已启动
|
|
|
|
|
detectDockerStarted () {
|
|
|
|
|
res=`docker images | grep -v grep | grep "IMAGE ID" | wc -l`
|
|
|
|
|
if [ $res -gt 0 ]; then
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 检测域名是否能连接
|
|
|
|
|
# 返回值:0 - 不能连接,1 - 可连接
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 获取docker desktop下载地址
|
|
|
|
|
# 参数:connect_res,可选值:[0, 1]
|
|
|
|
|
getDockerDesktopDownloadUrl () {
|
|
|
|
|
getCpuType
|
|
|
|
|
cup_type=$?
|
|
|
|
|
|
|
|
|
|
dmgLink_docker="https://desktop.docker.com/mac/main/arm64/Docker.dmg"
|
|
|
|
|
dmgLink="https://static.jialuoma.cn/docker_desktop/arm64.dmg"
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 下载docker desktop
|
|
|
|
|
downloadDockerDesktop () {
|
|
|
|
|
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}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 安装docker desktop和machete
|
|
|
|
|
welcome
|
|
|
|
|
|
|
|
|
|
detectDockerInstalled
|
|
|
|
|
docker_installed=$?
|
|
|
|
|
|
|
|
|
|
if [ $docker_installed -eq 0 ]; then
|
|
|
|
|
getCpuInfo
|
|
|
|
|
getCpuType
|
|
|
|
|
detect_domain='https://desktop.docker.com'
|
|
|
|
|
echo "正在检测是否能连接[${detect_domain}],请稍后..."
|
|
|
|
|
detectDomainCanConnect "${detect_domain}"
|
|
|
|
|
connect_res=$?
|
|
|
|
|
if [ $connect_res -eq 0 ]; then
|
|
|
|
|
echo "⚠️⚠️"
|
|
|
|
|
echo "当前网络无法连接[${detect_domain}],即将从备用网址下载docker desktop,预计耗时 30 分钟"
|
|
|
|
|
echo "如果你已经下载过docker desktop,请复制到当前电脑直接安装"
|
|
|
|
|
read -p "确认继续下载?(Y/N): " confirm
|
|
|
|
|
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then
|
|
|
|
|
link=`getDockerDesktopDownloadUrl $connect_res`
|
|
|
|
|
downloadDockerDesktop "${link}"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "如果你已经安装完成,请按Y继续安装machete镜像"
|
|
|
|
|
read -p "docker desktop已安装,继续?(Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
|
|
|
|
|
|
|
|
|
|
detectDockerInstalled
|
|
|
|
|
docker_installed=$?
|
|
|
|
|
if [ $docker_installed -eq 0 ]; then
|
|
|
|
|
echo "⚠️⚠️⚠️"
|
|
|
|
|
echo "命令行检测不到docker,请确认docker desktop已经安装"
|
|
|
|
|
echo "如果docker desktop已经安装,请关闭当前termina窗口重新打开命令行终端窗口,重新执行此安装脚本"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
detectDockerStarted
|
|
|
|
|
docker_started=$?
|
|
|
|
|
if [ $docker_started -eq 0 ]; then
|
|
|
|
|
echo "⚠️⚠️"
|
|
|
|
|
echo "请双击docker图标启动docker desktop,再继续下一步"
|
|
|
|
|
read -p "已经启动docker desktop,继续安装?(Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
echo "正在为你安装machete镜像..."
|
|
|
|
|
echo ""
|