12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #!/bin/bash
- #本地压缩文件名
- file_name="hac.zip"
- #测试服器上的目录地址
- file_path="hac.hczcxx.cn"
- #测试服务器上的演示地址
- demo_url="http://192.168.0.109:5176/"
- #测试服务器上的登录密码
- passwd="admin123@"
- # 打包前的准备
- node ./scripts/build.js
- # 执行打包命令
- vite build
- # 恢复配置文件
- node ./scripts/restore.js
- # 排除打包文件
- if [ $1 == "wgt" ]; then
- node ./scripts/public.js
- fi
- # 执行打包为zip
- node ./scripts/zip.js
- current_time=$(date "+%Y%m%d%H%M%S")
- # 上传到测试服务器
- function testServer() {
- expect -c "
- spawn scp ./zip/${file_name} root@192.168.0.109:/www/wwwroot/${file_path}
- expect {
- \"yes/no\" {send \"yes\r\";exp_continue;}
- \"*password\" {set timeout 500;send \"${passwd}\r\";}
- }
- expect eof"
- #服务器上的相关操作
- /usr/bin/expect << EOF
- set time 30
- spawn ssh root@192.168.0.109
- expect {
- "*yes/no" { send "yes\r"; exp_continue }
- "*password:" { send "${passwd}\r" }
- }
- # 进入当前项目的目录
- expect "*]#"
- send "cd /www/wwwroot/${file_path}\r"
- # 删除 static 目录
- expect "*]#"
- send "rm -rf static\r"
- # 解压上传的文件压缩包
- expect "*]#"
- send "unzip -o ${file_name}\r"
- # 备份上一次的压缩文件
- expect "*]#"
- send "mv ./backup/${file_name} ./backup/${current_time}_${file_name}\r"
- # 执行清理备份文件脚本
- expect "*]#"
- send "node ./backup.js\r"
- # 移动当前文件到备份目录
- expect "*]#"
- send "mv ./${file_name} ./backup/${file_name}\r"
- # 退出
- send "exit\r"
- expect eof
- EOF
- echo "编译打包后自动部署到测试服务器上完成"
- echo "测试服务器地址:${demo_url}"
- }
- # 上传到测试服务器
- if [ $2 == "test" ]; then
- testServer
- else
- echo "编译完成"
- fi
|