git服务器上的搭建
参考:https://blog.csdn.net/V__KING__/article/details/103196242
开发pc ubuntu上自动部署脚本
作用:
- 将本地代码push到git服务器上(git服务器会自动编译)
- 将git服务器上的编译文件下载到local主机上
- 将local主机上的编辑文件通过sftp上传到arm板
#!/bin/sh
ip_arm=192.168.7.115
username_arm=root
password_arm=123456
path_arm_app=/webApp
src_file=$(git diff --name-status HEAD~1|egrep "^(A|M)"| awk '{print $2}')
expect_scp_to_arm(){
expect <<-EOF
spawn scp -r $1 $username_arm@$ip_arm:$path_arm_app/$1
expect {
"*yes/no" { send "yes\n";exp_continue }
"*password:" { send "$password_arm\n" }
}
expect eof
EOF
}
expect_cp_to_arm(){
dir_file=`dirname $1`
echo $dir_file
expect <<-EOF
spawn sftp $username_arm@$ip_arm
expect {
"*yes/no" { send "yes\n";exp_continue }
"*password:" { send "$password_arm\n" }
}
expect {
"sftp>" {send "mkdir $path_arm_app/$dir_file\n"}
}
send "cd $path_arm_app/$dir_file\n"
send "put -pr $1\n"
send "quit\n"
expect eof
EOF
}
scp_fast_cache_to_local(){
echo "======copy fast compiled *.mod to local cache dirctory"
git_ip=192.168.7.74
git_name=git
git_repo_path=/home/git/webApplication/cache/*
echo $git_name
expect <<-EOF
spawn scp -r -P 19066 $git_name@$git_ip:$git_repo_path cache
expect {
"*yes/no" { send "yes\n";exp_continue }
"*password:" { send "1\n" }
}
expect eof
EOF
}
scp_LocalCache_to_arm(){
echo "======copy local cache to arm"
expect <<-EOF
spawn scp -r cache $username_arm@$ip_arm:$path_arm_app
expect {
"*yes/no" { send "yes\n";exp_continue }
"*password:" { send "$password_arm\n" }
}
expect eof
EOF
}
git_push_to_git_server(){
echo "======git push to git server"
expect <<-EOF
spawn git push
expect {
"*password:" { send "1\n" }
}
expect eof
EOF
}
# main
if [[ $1 == "upload" ]]; then
echo "upload to arm ..."
for file in $src_file; do
# expect_scp_to_arm $file
expect_cp_to_arm $file
done
git_push_to_git_server
scp_fast_cache_to_local
scp_LocalCache_to_arm
elif [[ $1 == "arm" ]]; then
mvc run
else
mvc clean
mvc compile
mvc run
fi