2
0

git.commit.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. cat <<END >>/dev/null
  3. touch git-ensure-commit &&
  4. echo "cd `pwd` &&" >git-ensure-commit &&
  5. echo "bash `pwd`/git.commit.sh" >>git-ensure-commit &&
  6. chmod +x git-ensure-commit &&
  7. sudo rm -f /bin/git-ensure-commit &&
  8. sudo mv git-ensure-commit /usr/local/bin/git-ensure-commit
  9. END
  10. echo "submit code to github.com"
  11. echo "argv[0]=$0"
  12. if [[ ! -f $0 ]]; then
  13. echo "directly execute the scripts on shell.";
  14. work_dir=`pwd`
  15. else
  16. echo "execute scripts in file: $0";
  17. work_dir=`dirname $0`; work_dir=`(cd ${work_dir} && pwd)`
  18. fi
  19. work_dir=`(cd ${work_dir}/.. && pwd)`
  20. product_dir=$work_dir
  21. # allow start script from any dir
  22. cd $work_dir && work_branch=`git branch|grep "*"|awk '{print $2}'` && commit_branch=2.0release && git checkout $commit_branch
  23. ret=$ret; if [[ $ret -ne 0 ]]; then echo "switch branch failed. ret=$ret"; exit $ret; fi
  24. echo "work branch is $work_branch"
  25. echo "commit branch is $commit_branch"
  26. . ${product_dir}/scripts/_log.sh
  27. ret=$?; if [[ $ret -ne 0 ]]; then exit $ret; fi
  28. ok_msg "导入脚本成功"
  29. function remote_check()
  30. {
  31. remote=$1
  32. url=$2
  33. git remote -v| grep "$url" >/dev/null 2>&1
  34. ret=$?; if [[ 0 -ne $ret ]]; then
  35. echo "remote $remote not found, add by:"
  36. echo " git remote add $remote $url"
  37. exit -1
  38. fi
  39. ok_msg "remote $remote ok, url is $url"
  40. }
  41. remote_check origin git@github.com:ossrs/srs.git
  42. remote_check srs.winlin git@github.com:winlinvip/simple-rtmp-server.git
  43. remote_check srs.csdn git@code.csdn.net:winlinvip/srs-csdn.git
  44. remote_check srs.oschina git@git.oschina.net:winlinvip/srs.oschina.git
  45. remote_check srs.gitlab git@gitlab.com:winlinvip/srs-gitlab.git
  46. ok_msg "remote check ok"
  47. function sync_push()
  48. {
  49. for ((;;)); do
  50. git push $*
  51. ret=$?; if [[ 0 -ne $ret ]]; then
  52. failed_msg "Retry for failed: git push $*"
  53. sleep 3
  54. continue
  55. else
  56. ok_msg "Success: git push $*"
  57. fi
  58. break
  59. done
  60. }
  61. sync_push origin
  62. sync_push srs.winlin
  63. sync_push srs.csdn
  64. sync_push srs.oschina
  65. sync_push srs.gitlab
  66. ok_msg "push branches ok"
  67. sync_push --tags srs.winlin
  68. sync_push --tags srs.csdn
  69. sync_push --tags srs.oschina
  70. sync_push --tags srs.gitlab
  71. ok_msg "push tags ok"
  72. git checkout $work_branch
  73. ok_msg "switch to work branch $work_branch"
  74. exit 0