Forest_Client/Tool/BuildTool/upload_to_server.sh

52 lines
1.3 KiB
Bash
Executable File

##!/bin/bash
SHELL_DIR=$(dirname $0)
echo "change dir to $SHELL_DIR"
cd "$SHELL_DIR"
# Source the local environment
if [ -f ./local_env.sh ]; then
source ./local_env.sh
echo "found the local_env file"
fi
# 获取项目相关参数
if [ -f ./project_env.sh ]; then
source ./project_env.sh
echo "found the project_env file"
fi
VERSION="$1"
PLATFORM="$2"
WORKSPACE="$3"
NEWASSETS="$4"
REMOTE_PATH="/$REMOTE_UPLOAD_PATH/$WORKSPACE/$PLATFORM/$VERSION"
echo "remote path : $REMOTE_PATH"
# Set remote Build Path (local) (modify as needed)
BUILD_PATH="../../$PROJECT_NAME/ServerData/$PLATFORM/"
# Check if NEWASSETS is true, if so, delete existing assets on remote server
#if [ "$NEWASSETS" = "true" ]; then
# ssh "$REMOTE_USER@$REMOTE_HOST" "rm -rf $REMOTE_PATH/*"
#fi
tar -czvf upload.tgz -C "$BUILD_PATH" .
ssh "$REMOTE_USER@$REMOTE_HOST" "mkdir -p $REMOTE_PATH"
scp upload.tgz "$REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH"
ssh "$REMOTE_USER@$REMOTE_HOST" "cd $REMOTE_PATH;tar -xzvf upload.tgz;rm -rf upload.tgz"
upload_result=$?
if [ $upload_result -eq 0 ]; then
echo "Build uploaded to remote server successfully."
else
sh to_inner_wechat_robot.sh "$PLATFORM】【$VERSION】【$PROFILE】Failed to upload build to remote server! "
echo "Failed to upload build to remote server."
fi
rm -rf upload.tgz