Browse Source

main logic ready

master
filesite 5 months ago
parent
commit
b26266116a
  1. 214
      install.sh

214
install.sh

@ -10,6 +10,15 @@ welcome () { @@ -10,6 +10,15 @@ welcome () {
echo ""
}
theend () {
echo ""
echo "==感谢使用machete_installer=="
echo "本脚本为开源项目,网址:https://git.filesite.io/filesite/machete_installer"
echo "个性化配置请参考官方文档:"
echo "https://filesite.io/view/?id=2907455e19bee577f8ed4c9fac83ae95"
echo ""
}
# 获取mac mini的cpu芯片型号信息
getCpuInfo () {
cpu_info=`sysctl -n machdep.cpu.brand_string`
@ -50,12 +59,107 @@ detectDockerStarted () { @@ -50,12 +59,107 @@ detectDockerStarted () {
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
album_path="~/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
blog_path="~/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
@ -95,6 +199,7 @@ downloadDockerDesktop () { @@ -95,6 +199,7 @@ downloadDockerDesktop () {
link=$1
if [ -z "${link}" ]; then
echo "Usage: downloadDockerDesktop url"
echo ""
exit 1
fi
@ -104,6 +209,27 @@ downloadDockerDesktop () { @@ -104,6 +209,27 @@ downloadDockerDesktop () {
open "${link}"
}
# 获取本地局域网ip地址
getLocalIp () {
ipstr=`ifconfig -a | grep -v grep | grep '192.168'`
echo "${ipstr}" | cut -d ' ' -f 2
}
# 创建桌面快捷方式
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
welcome
@ -139,6 +265,7 @@ if [ $docker_installed -eq 0 ]; then @@ -139,6 +265,7 @@ if [ $docker_installed -eq 0 ]; then
echo "⚠"
echo "命令行检测不到docker,请确认docker desktop已经安装"
echo "如果docker desktop已经安装,请关闭当前termina窗口重新打开命令行终端窗口,重新执行此安装脚本"
echo ""
exit 1
fi
fi
@ -154,3 +281,90 @@ fi @@ -154,3 +281,90 @@ fi
echo ""
echo "正在为你安装machete镜像..."
echo ""
detectDockerImageExists "filesite/machete"
imgExist=$?
if [ $imgExist -eq 0 ]; then
echo "下载machete的docker镜像,文件大小89M,预计需要 5 - 10 分钟..."
curl -o machte.tar "https://static.jialuoma.cn/docker_images/machete.tar"
if [ -f ./machete.tar ]; then
sumok="eacbdfb33873e79d1eccca7fa2d0706a"
checkRes=`md5 machete.tar | grep -v grep | grep "${sumok}" | wc -l`
if [ $checkRes -gt 0 ]; then
echo "machete的docker镜像下载完成,即将导入docker"
docker image load --input machete.tar
# 再次确认image下载成功
detectDockerImageExists "filesite/machete"
imgExist=$?
if [ $imgExist -eq 0 ]; then
echo "⚠"
echo "machete的docker镜像导入失败,请检查网络后重试"
echo ""
exit 1
else
echo "machete的docker镜像导入完成,即将开始安装相册和视频系统"
fi
fi
fi
fi
echo ""
echo "开始安装相册系统..."
containerName="machete_album"
detectDockerContainerExists "${containerName}"
containerExist=$?
if [ $containerExist -eq 0 ]; then
read -p "请输入相册保存路径后回车(默认保存到桌面~/Desktop/Album_by_filesite): " album_path
if [ ! -d "${album_path}" ]; then
read -p "目录【${album_path}】不存在,确认创建此目录继续安装吗?(Y/N): " confirm
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then
mkdir -p "${album_path}"
echo "目录【${album_path}】不存在,已帮你创建"
else
echo "⚠"
echo "安装已取消,如需继续安装,请重新执行本安装脚本"
echo ""
exit 1
fi
fi
echo "启动相册容器中..."
dockerStartAlbumContainer "${containerName}" "${album_path}"
docker ps | grep "${containerName}"
createShortcuts "album"
ip=`getLocalIp`
echo "✅✅"
echo "相册系统已成功安装,并在桌面创建了相册系统的快捷方式,可双击打开"
echo "还可以在浏览器输入:http://${ip}:8181/ 打开"
fi
echo ""
echo "开始安装视频系统..."
containerName="machete_vlog"
detectDockerContainerExists "${containerName}"
containerExist=$?
if [ $containerExist -eq 0 ]; then
read -p "请输入视频保存路径后回车(默认保存到桌面~/Desktop/Videos_by_filesite): " vlog_path
if [ ! -d "${vlog_path}" ]; then
read -p "目录【${vlog_path}】不存在,确认创建此目录继续安装吗?(Y/N): " confirm
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then
mkdir -p "${vlog_path}"
echo "目录【${vlog_path}】不存在,已帮你创建"
else
echo "⚠"
echo "安装已取消,如需继续安装,请重新执行本安装脚本"
echo ""
exit 1
fi
fi
echo "启动视频容器中..."
dockerStartVideoContainer "${containerName}" "${vlog_path}"
docker ps | grep "${containerName}"
createShortcuts "vlog"
ip=`getLocalIp`
echo "✅✅"
echo "视频系统已成功安装,并在桌面创建了视频系统的快捷方式,可双击打开"
echo "还可以在浏览器输入:http://${ip}:8182/ 打开"
fi
theend
Loading…
Cancel
Save