Commit 58717435 authored by Kunkka王辉's avatar Kunkka王辉 😲

安装脚本优化

parent 468acba6
#!/bin/bash
# 获取本机ip 192 ip
HOST_IP=$(hostname -I | grep -E "192\.168\.[0-9]+\.[0-9]+" -o)
OS_IS_LINUX='yes'; if [ $(uname -o) != "GNU/Linux" ]; then OS_IS_LINUX='no'; fi
DOCKER_YES='yes';if [ ! `command -v docker` ];then DOCKER_YES='no';fi;
GIT_YES='yes';if [ ! `command -v git` ];then DOCKER_YES='no';fi;
TAR_YES='yes';if [ ! `command -v tar` ];then DOCKER_YES='no';fi;
AVAILABLE_MEMORY=$(free -m | awk 'NR==2{print $7}')
CAN_COMPILE=0
MEM_MSG=',小于4G,不足跑前端编译'
if [ $AVAILABLE_MEMORY -gt 4200 ]; then
CAN_COMPILE=1
MEM_MSG='yes'
fi
COMPOSE_CMD='docker-compose'
if docker --help | grep compose >/dev/null ; then
COMPOSE_CMD='docker compose'
......@@ -17,11 +26,12 @@ cat <<EOF
4. docker-compose/docker compose $DOCKER_COMPOSE_YES
5. tar $TAR_YES
6. 端口8118,8181是否可用 $PORT_YES
7. 本机可用内存 ${AVAILABLE_MEMORY}M $MEM_MSG
8. 本机IP $HOST_IP
EOF
if echo "$TAR_YES$GIT_YES$DOCKER_COMPOSE_YES$OS_IS_LINUX$DOCKER_YES$PORT_YES" | grep no >/dev/null ;then
exit ;
fi
# 变量声明
ENV='dev'
CODE_DIR=$(pwd)/code-$ENV
......@@ -36,18 +46,40 @@ BUILD_DIR=galaxy-$ENV
if [ ! -d $CODE_DIR ]; then
mkdir -p $CODE_DIR
fi
echo '拉取工具镜像'
docker pull gplane/pnpm:7.4
docker pull node:14.20-alpine
cd $CODE_DIR
echo "下载demo代码"
curl -o data.tgz -# http://192.168.11.163/demo/code-demo-920.tgz
echo '解压缩......'
tar --strip-components=1 -xf data.tgz
echo '解压缩(每1000个文件输出一个.)'
tar --checkpoint=.1000 --checkpoint-action=dot --strip-components=1 -xf data.tgz
rm -f data.tgz
echo 'storage 目录权限处理'
find ./ -type d -name 'storage' -exec chmod -R 0777 {} +
echo '下载compose项目'
cd ../ # 到上一层
git clone git@gitlab.galaxy-immi.com:kunkka.wh/docker-test.git $BUILD_DIR
echo '下载前端编译项目'
curl -o front.tgz -# http://192.168.11.163/demo/code-front-compile.tgz
echo '解压缩中.'
tar --checkpoint=.1000 --checkpoint-action=dot -xf front.tgz
rm -f front.tgz
cd compile/Document-System
sed -i "s/192.168.11.163/$HOST_IP/g" .env.dev
cat .env.dev
if [ $CAN_COMPILE -eq 1]; then
echo '开始编译打包前端dwp/main'
docker run --rm -v $(pwd):/app -w /app gplane/pnpm:7.4 vite build --mode dev --outDir main
yes | cp -rf main $CODE_DIR/dwp/
cd ../compile/crm
sed -i "s/192.168.11.163/$HOST_IP/g" .env.testa
cat .env.testa
echo '开始编译打包前端crm'
cd $CODE_DIR/../compile/crm
docker run --rm -v $(pwd):/app -w /app node:14.20-alpine node_modules/@vue/cli-service/bin/vue-cli-service build --mode testa --dest crm
yes | cp -rf crm $CODE_DIR/
fi
cd $CODE_DIR/../
git clone http://gitlab.galaxy-immi.com/kunkka.wh/docker-test.git $BUILD_DIR
cd $BUILD_DIR
cat <<EOF > .env
# 环境变量env dev,test,test1,test2等区分
......@@ -68,8 +100,8 @@ $COMPOSE_CMD up -d
cat <<EOF
本地访问地址
http://本机ip:8118/
http://本机ip:8181/
http://$HOST_IP:8118/ DWP
http://$HOST_IP:8181/ CRM
安装完成!
EOF
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment