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

安装脚本优化

parent a6e840f4
#!/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;
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
if docker --help | grep compose >/dev/null; then
COMPOSE_CMD='docker compose'
fi
DOCKER_COMPOSE_YES='yes';if [ ! `command -v docker-compose` ] && [ "$COMPOSE_CMD" != 'docker compose' ];then DOCKER_COMPOSE_YES='no';fi;
PORT_YES='yes'; if ss -tpl | grep -E '8118|8181' >/dev/null ;then PORT_YES='no';fi;
DOCKER_COMPOSE_YES='yes'
if [ ! $(command -v docker-compose) ] && [ "$COMPOSE_CMD" != 'docker compose' ]; then DOCKER_COMPOSE_YES='no'; fi
PORT_YES='yes'
if ss -tpl | grep -E '8118|8181' >/dev/null; then PORT_YES='no'; fi
cat <<EOF
检查环境:
1. 是否是linux系统 $OS_IS_LINUX
......@@ -26,17 +26,16 @@ 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 ;
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
for arg in "$@";do
if [ -n "$arg" ];then
for arg in "$@"; do
if [ -n "$arg" ]; then
ENV="$arg"
break
fi
......@@ -46,9 +45,6 @@ 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
......@@ -57,31 +53,14 @@ tar --checkpoint=.1000 --checkpoint-action=dot --strip-components=1 -xf data.tg
rm -f data.tgz
echo 'storage 目录权限处理'
find ./ -type d -name 'storage' -exec chmod -R 0777 {} +
cd ../ # 到上一层
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/crm
grep -rlZ 192.168.11.163 ./ | xargs -0 sed -i "s/192.168.11.163/$HOST_IP/g"
cd $CODE_DIR/dwp/main
grep -rlZ 192.168.11.163 ./ | xargs -0 sed -i "s/192.168.11.163/$HOST_IP/g"
cd $CODE_DIR/../
git clone http://gitlab.galaxy-immi.com/kunkka.wh/docker-test.git $BUILD_DIR
cd $BUILD_DIR
cat <<EOF > .env
cat <<EOF >.env
# 环境变量env dev,test,test1,test2等区分
ENV=$ENV
# 服务宿主机的端口
......@@ -104,4 +83,3 @@ 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