build.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. #本地压缩文件名
  3. file_name="hac.zip"
  4. #测试服器上的目录地址
  5. file_path="hac.hczcxx.cn"
  6. #测试服务器上的演示地址
  7. demo_url="http://192.168.0.109:5176/"
  8. #测试服务器上的登录密码
  9. passwd="admin123@"
  10. # 打包前的准备
  11. node ./scripts/build.js
  12. # 执行打包命令
  13. vite build
  14. # 恢复配置文件
  15. node ./scripts/restore.js
  16. # 排除打包文件
  17. if [ $1 == "wgt" ]; then
  18. node ./scripts/public.js
  19. fi
  20. # 执行打包为zip
  21. node ./scripts/zip.js
  22. current_time=$(date "+%Y%m%d%H%M%S")
  23. # 上传到测试服务器
  24. function testServer() {
  25. expect -c "
  26. spawn scp ./zip/${file_name} root@192.168.0.109:/www/wwwroot/${file_path}
  27. expect {
  28. \"yes/no\" {send \"yes\r\";exp_continue;}
  29. \"*password\" {set timeout 500;send \"${passwd}\r\";}
  30. }
  31. expect eof"
  32. #服务器上的相关操作
  33. /usr/bin/expect << EOF
  34. set time 30
  35. spawn ssh root@192.168.0.109
  36. expect {
  37. "*yes/no" { send "yes\r"; exp_continue }
  38. "*password:" { send "${passwd}\r" }
  39. }
  40. # 进入当前项目的目录
  41. expect "*]#"
  42. send "cd /www/wwwroot/${file_path}\r"
  43. # 删除 static 目录
  44. expect "*]#"
  45. send "rm -rf static\r"
  46. # 解压上传的文件压缩包
  47. expect "*]#"
  48. send "unzip -o ${file_name}\r"
  49. # 备份当前文件
  50. expect "*]#"
  51. send "cp ./${file_name} ./backup/${current_time}_${file_name}\r"
  52. # 退出
  53. send "exit\r"
  54. expect eof
  55. EOF
  56. echo "编译打包后自动部署到测试服务器上完成"
  57. echo "测试服务器地址:${demo_url}"
  58. }
  59. # 上传到测试服务器
  60. if [ $2 == "test" ]; then
  61. testServer
  62. else
  63. echo "编译完成"
  64. fi