Shell获取git status文件变动push到远程服务器

使用场景:在本地进行修改代码,将修改的代码push到远程服务器进行编译


# 获取git status的文件,自动push到服务器

export S=/devdata/AndroidS/
export S_SERVER=/data/AndroidS/




echo '1. Android S '
echo '3. Android Q '

export num=1
case $num in
    1)
        export LOCALHOST_CODE=$S
		export SERVER_CODE=$S_SERVER
        ;;
    2)
        ;;
    3)
        ;;
    *)
        echo "error"
esac

echo "get git status information..."

result=$(cd $LOCALHOST_CODE && git status);

# echo $result

echo "本地源码--->$LOCALHOST_CODE"
echo "服务器源码--->$SERVER_CODE"

for word in $result
do
	#echo $word
	#echo "!!!!!"
	
	file=$LOCALHOST_CODE$word
	file_server=$SERVER_CODE$word
	
	#echo $file
	
	if [ -d "$file" ]; then
	
	  # echo "$file is a directory "
	  
	  if [[ "$file" =~ "frameworks" ]] || [[ "$file" =~ "packages" ]] || [[ "$file" =~ "libcore" ]] || [[ "$file" =~ "bazel" ]]; then
	    
		# 远程发送命令
		ssh xxx@ip "rm -rf $file_server"
	  	echo "push directory $file* ---> $file_server"
		ssh xxx@ip "mkdir $file_server"
		scp -r $file*  xxx@ip:$file_server/
	  fi
	  #if [[  "$file" =~ "tools" ]]; then
		#scp -r $file  xxx@ip:$file_server/
	  #fi

	elif [ -f "$file" ]; then

	  # echo "$file is a file"
	  if [[  "$file" =~ "frameworks" ]] || [[  "$file" =~ "packages" ]] || [[  "$file" =~ "system" ]] || [[  "$file" =~ "vendor" ]] || [[  "$file" =~ "libcore" ]] || [[  "$file" =~ "soong" ]] ; then
	  	
		#echo "$file"
		#echo "$file_server"
		scp -r $file  xxx@ip:$file_server
	  fi

	fi
done

echo 'scp files done'

你可能感兴趣的:(linux,linux)