winlin

add git2unix and git commit script.

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