#!/bin/bash

#读取构建参数
echo "$1"

type="$1"

#进入归档目录
cd /builds/go-admin || exit

#判断是测试环境还是生产环境
if [ "$type" == "prod" ]; then
  file="/www/wwwroot/admin.deovo.com/admin_server/go-admin/go-admin"
  service_name="go_admin:go_admin"
else
  file="/www/wwwroot/dev.admin.deovo.com/admin_server/go-admin/dev-go-admin"
  service_name="dev_go_admin:dev_go_admin_00"
fi

echo "目标文件：$file"
echo "supervisor process name: $service_name"

#删除历史二进制文件 拷贝新的文件到对应文件夹
rm -rf "$file" && cp go-admin "$file"

#归档重命名
current_time=$(date +'%y%m%d%H%M%S')
new_filename="go-admin-${current_time}"
mv go-admin "$new_filename"


#重启服务
supervisorctl restart "$service_name"
