build.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. set -x
  3. function RETVAL() {
  4. rt=$1
  5. if [ $rt != 0 ]; then
  6. echo $rt
  7. exit 1
  8. fi
  9. }
  10. #当前目录
  11. cpath=$(pwd)
  12. ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'`
  13. echo "当前版本 $ver"
  14. echo "编译前端项目"
  15. cd $cpath/web
  16. #国内可替换源加快速度
  17. #npx browserslist@latest --update-db
  18. #npm install --registry=https://registry.npm.taobao.org
  19. #npm install
  20. #npm run build
  21. yarn install --registry=https://registry.npmmirror.com
  22. yarn run build
  23. RETVAL $?
  24. echo "编译二进制文件"
  25. cd $cpath/server
  26. rm -rf ui
  27. cp -rf $cpath/web/ui .
  28. #国内可替换源加快速度
  29. export GOPROXY=https://goproxy.io
  30. go mod tidy
  31. go build -v -o anylink -ldflags "-X main.CommitId=$(git rev-parse HEAD)"
  32. RETVAL $?
  33. cd $cpath
  34. echo "整理部署文件"
  35. deploy="anylink-deploy"
  36. rm -rf $deploy ${deploy}.tar.gz
  37. mkdir $deploy
  38. cp -r server/anylink $deploy
  39. #cp -r server/bridge-init.sh $deploy
  40. cp -r server/conf $deploy
  41. cp -r systemd $deploy
  42. cp -r LICENSE $deploy
  43. tar zcvf ${deploy}.tar.gz $deploy
  44. #注意使用root权限运行
  45. #cd anylink-deploy
  46. #sudo ./anylink --conf="conf/server.toml"