From 86b06a9b25bf6b79fa8b1fd70f8a0798fb30baf0 Mon Sep 17 00:00:00 2001 From: filesite Date: Wed, 26 Jun 2024 22:06:55 +0800 Subject: [PATCH] container install update --- funs.sh | 266 +++++++++++++++++++++++++++++++++++++++++++++++++++++ install.sh | 260 ++------------------------------------------------- 2 files changed, 275 insertions(+), 251 deletions(-) create mode 100644 funs.sh diff --git a/funs.sh b/funs.sh new file mode 100644 index 0000000..1061c52 --- /dev/null +++ b/funs.sh @@ -0,0 +1,266 @@ +#!/bin/sh + +# 公用方法 + +# 显示欢迎信息 +welcome () { + echo "==欢迎使用machete_installer==" + echo "本脚本为开源项目,网址:https://git.filesite.io/filesite/machete_installer" + echo "它将指引并安装docker desktop和machete的docker镜像" + echo "并完成machete的基本配置,在你的电脑上创建两个网站,一个管理图片,一个管理视频" + echo "" +} + +# 显示结束语 +theend () { + echo "" + echo "==感谢使用machete_installer==" + echo "本脚本为开源项目,网址:https://git.filesite.io/filesite/machete_installer" + echo "个性化配置请参考官方文档:" + echo "https://filesite.io/view/?id=2907455e19bee577f8ed4c9fac83ae95" + echo "" +} + +# 获取用户桌面绝对路径 +getHomePath () { + path=`cd ~/ && pwd` + echo $path +} + +# 获取本地局域网ip地址 +getLocalIp () { + ipstr=`ifconfig -a | grep -v grep | grep '192.168'` + echo "${ipstr}" | cut -d ' ' -f 2 +} + +# 获取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 +} + +# 检测docker image是否下载 +# 返回值:0 - 未下载,1 - 已下载 +detectDockerImageExists () { + imgName=$1 + if [ -z "${imgName}" ]; then + imgName="filesite/machete" + fi + + res=`docker images | grep -v grep | grep "${imgName}" | wc -l` + if [ $res -gt 0 ]; then + return 1 + fi + + return 0 +} + +# 检测docker container是否启动 +# 返回值:0 - 未启动,1 - 已启动 +detectDockerContainerExists () { + containerName=$1 + if [ -z "${containerName}" ]; then + containerName="machete_album" + fi + + res=`docker ps -a | grep -v grep | grep "${containerName}" | wc -l` + if [ $res -gt 0 ]; then + return 1 + fi + + return 0 +} + +# 启动相册容器,端口:8181 +# @album_name 容器名 +# @album_path 相册保存路径 +dockerStartAlbumContainer () { + album_name=$1 + album_path=$2 + if [ -z "${album_name}" ]; then + album_name="machete_album" + fi + if [ -z "${album_path}" ]; then + homePath=`getHomePath` + album_path="${homePath}/Desktop/Album_by_filesite" + fi + + docker run --name "${album_name}" \ + -p 8181:80 \ + -v "${album_path}:/var/www/machete/www/girls/" \ + -itd filesite/machete \ + beauty +} + +# 启动视频容器,端口:8182 +# @blog_name 容器名 +# @blog_path 视频保存路径 +dockerStartVideoContainer () { + blog_name=$1 + blog_path=$2 + if [ -z "${blog_name}" ]; then + blog_name="machete_videos" + fi + if [ -z "${blog_path}" ]; then + homePath=`getHomePath` + blog_path="${homePath}/Desktop/Videos_by_filesite" + fi + + docker run --name "${blog_name}" \ + -p 8182:80 \ + -v "${blog_path}:/var/www/machete/www/videos/" \ + -itd filesite/machete \ + videoblog +} + +# 检测域名是否能连接 +# 返回值:0 - 不能连接,1 - 可连接 +detectDomainCanConnect () { + domain=$1 + if [ -z "${domain}" ]; then + echo "Usage: detectDomainCanConnect domain" + echo "" + 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/docker_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/docker_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" + echo "" + exit 1 + fi + + echo "docker desktop下载链接:${link}" + echo "即将在浏览器中打开docker desktop的下载链接并开始下载" + echo "请在docker desktop下载完成后,双击打开安装" + open "${link}" +} + +# 创建桌面快捷方式 +createShortcuts () { + ip=`getLocalIp` + + type=$1 + + if [ "${type}" == "album" ]; then + echo "[InternetShortcut]" > ~/Desktop/相册.url + echo "URL=http://${ip}:8181" >> ~/Desktop/相册.url + else + echo "[InternetShortcut]" > ~/Desktop/视频.url + echo "URL=http://${ip}:8182" >> ~/Desktop/视频.url + fi +} + +# 升级docker容器里的代码到最新版 +upgradeMacheteInContainers () { + name=$1 + + if [ "${name}}" == "album" ]; then + docker exec -it machete_album /var/www/machete/bin/upgrade.sh + docker container cp template/custom_config_beauty.json machete_album:/var/www/machete/runtime/custom_config.json + else + docker exec -it machete_vlog /var/www/machete/bin/upgrade.sh + docker container cp template/custom_config_videoblog.json machete_vlog:/var/www/machete/runtime/custom_config.json + fi +} + +# 下载演示照片 +downloadSamplesPhotos () { + savePath=$1 + if [ -z "${savePath}" ]; then + savePath="~/Desktop/Album_by_filesite/" + fi + + echo "下载演示照片..." + url="https://static.jialuoma.cn/samples/sample_photos.tar.gz" + curl -o sample_photos.tar.gz "${url}" + tar -zxvf sample_photos.tar.gz + cp -r sample_photos/* $savePath + + echo "下载演示音乐mp3..." + url="https://static.jialuoma.cn/samples/melody.mp3" + curl -o melody.mp3 "${url}" + cp melody.mp3 $savePath +} + +# 下载演示视频 +downloadSamplesVideos () { + savePath=$1 + if [ -z "${savePath}" ]; then + savePath="~/Desktop/Videos_by_filesite/" + fi + + echo "下载演示视频..." + url="https://static.jialuoma.cn/samples/sample_videos.tar.gz" + curl -o sample_videos.tar.gz "${url}" + tar -zxvf sample_videos.tar.gz + cp -r sample_videos/* $savePath +} + diff --git a/install.sh b/install.sh index 7a9ba47..6ee56fb 100755 --- a/install.sh +++ b/install.sh @@ -1,255 +1,10 @@ #!/bin/sh +# 引入公用方法 +. ./funs.sh -# 显示欢迎信息 -welcome () { - echo "==欢迎使用machete_installer==" - echo "本脚本为开源项目,网址:https://git.filesite.io/filesite/machete_installer" - echo "它将指引并安装docker desktop和machete的docker镜像" - echo "并完成machete的基本配置,在你的电脑上创建两个网站,一个管理图片,一个管理视频" - echo "" -} - -# 显示结束语 -theend () { - echo "" - echo "==感谢使用machete_installer==" - echo "本脚本为开源项目,网址:https://git.filesite.io/filesite/machete_installer" - echo "个性化配置请参考官方文档:" - echo "https://filesite.io/view/?id=2907455e19bee577f8ed4c9fac83ae95" - echo "" -} - -# 获取用户桌面绝对路径 -getHomePath () { - path=`cd ~/ && pwd` - echo $path -} - -# 获取本地局域网ip地址 -getLocalIp () { - ipstr=`ifconfig -a | grep -v grep | grep '192.168'` - echo "${ipstr}" | cut -d ' ' -f 2 -} - -# 获取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 -} - -# 检测docker image是否下载 -# 返回值:0 - 未下载,1 - 已下载 -detectDockerImageExists () { - imgName=$1 - if [ -z "${imgName}" ]; then - imgName="filesite/machete" - fi - res=`docker images | grep -v grep | grep "${imgName}" | wc -l` - if [ $res -gt 0 ]; then - return 1 - fi - - return 0 -} - -# 检测docker container是否启动 -# 返回值:0 - 未启动,1 - 已启动 -detectDockerContainerExists () { - containerName=$1 - if [ -z "${containerName}" ]; then - containerName="machete_album" - fi - - res=`docker ps -a | grep -v grep | grep "${containerName}" | wc -l` - if [ $res -gt 0 ]; then - return 1 - fi - - return 0 -} - -# 下载machete最新源码 -# 返回值:0 - 未下载,1 - 已下载 -downloadMacheteSourceCode () { - if [ -f machete_src.zip ]; then - echo "machete源码下载完成" - return 1 - fi - - echo "machete源码下载中..." - url="https://git.filesite.io/filesite/machete/archive/master.zip" - curl -o machete_src.zip "${url}" - - if [ -f machete_src.zip ]; then - echo "machete源码下载完成" - return 1 - else - echo "⚠️⚠️" - echo "achete源码下载失败,请检查网络后重试" - return 0 - fi -} - -# 启动相册容器,端口:8181 -# @album_name 容器名 -# @album_path 相册保存路径 -dockerStartAlbumContainer () { - album_name=$1 - album_path=$2 - if [ -z "${album_name}" ]; then - album_name="machete_album" - fi - if [ -z "${album_path}" ]; then - homePath=`getHomePath` - album_path="${homePath}/Desktop/Album_by_filesite" - fi - - docker run --name "${album_name}" \ - -p 8181:80 \ - -v "${album_path}:/var/www/machete/www/girls/" \ - -itd filesite/machete \ - beauty -} - -# 启动视频容器,端口:8182 -# @blog_name 容器名 -# @blog_path 视频保存路径 -dockerStartVideoContainer () { - blog_name=$1 - blog_path=$2 - if [ -z "${blog_name}" ]; then - blog_name="machete_videos" - fi - if [ -z "${blog_path}" ]; then - homePath=`getHomePath` - blog_path="${homePath}/Desktop/Videos_by_filesite" - fi - - docker run --name "${blog_name}" \ - -p 8182:80 \ - -v "${blog_path}:/var/www/machete/www/videos/" \ - -itd filesite/machete \ - videoblog -} - -# 升级docker容器里的代码到最新版 -upgradeMacheteInContainers () { - docker exec -it machete_album /var/www/machete/bin/upgrade.sh - docker container cp template/custom_config_beauty.json machete_album:/var/www/machete/runtime/custom_config.json - - docker exec -it machete_vlog /var/www/machete/bin/upgrade.sh - docker container cp template/custom_config_videoblog.json machete_vlog:/var/www/machete/runtime/custom_config.json -} - -# 检测域名是否能连接 -# 返回值:0 - 不能连接,1 - 可连接 -detectDomainCanConnect () { - domain=$1 - if [ -z "${domain}" ]; then - echo "Usage: detectDomainCanConnect domain" - echo "" - 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/docker_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/docker_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" - echo "" - exit 1 - fi - - echo "docker desktop下载链接:${link}" - echo "即将在浏览器中打开docker desktop的下载链接并开始下载" - echo "请在docker desktop下载完成后,双击打开安装" - open "${link}" -} - -# 创建桌面快捷方式 -createShortcuts () { - ip=`getLocalIp` - - type=$1 - - if [ "${type}" == "album" ]; then - echo "[InternetShortcut]" > ~/Desktop/相册.url - echo "URL=http://${ip}:8181" >> ~/Desktop/相册.url - else - echo "[InternetShortcut]" > ~/Desktop/视频.url - echo "URL=http://${ip}:8182" >> ~/Desktop/视频.url - fi -} - - -# 安装docker desktop和machete +# ===== 安装docker desktop和machete ===== welcome detectDockerInstalled @@ -356,6 +111,9 @@ if [ $containerExist -eq 0 ]; then echo "启动相册容器中..." dockerStartAlbumContainer "${containerName}" "${album_path}" docker ps | grep "${containerName}" + echo "升级系统到最新版..." + upgradeMacheteInContainers "album" + downloadSamplesPhotos "${album_path}" createShortcuts "album" ip=`getLocalIp` echo "✅✅" @@ -391,6 +149,9 @@ if [ $containerExist -eq 0 ]; then echo "启动视频容器中..." dockerStartVideoContainer "${containerName}" "${vlog_path}" docker ps | grep "${containerName}" + echo "升级系统到最新版..." + upgradeMacheteInContainers "vlog" + downloadSamplesVideos "${vlog_path}" createShortcuts "vlog" ip=`getLocalIp` echo "✅✅" @@ -398,8 +159,5 @@ if [ $containerExist -eq 0 ]; then echo "还可以在浏览器输入:http://${ip}:8182/ 打开" fi -echo "" -echo "升级系统到最新版..." -upgradeMacheteInContainers theend \ No newline at end of file