Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #! カレントディレクトリのリポジトリを指定した位置におき、
  2. #! 指定したリポジトリ名で push できるようにする。
  3. #! ターゲットはパスワードなしで ssh 接続できる想定とする。
  4. #!
  5. #! Usage:
  6. #! put_bare_repository.sh <remotehost>:<remotedirectory> <reponame>
  7. #!
  8.  
  9. SRC=$PWD
  10.  
  11. if [ ! -d $SRC/.git ] ; then
  12. echo current directory is not git repository.
  13. exit 1
  14. fi
  15.  
  16. TARGET=$1
  17. REPONAME=$2
  18.  
  19. # ターゲットがリモートである前提
  20. REMOTEHOST=$(echo $TARGET | cut -f1 -d:)
  21. REMOTEDIR=$(echo $TARGET | cut -f2 -d:)
  22.  
  23. if [ ! "$REMOTEDIR" ] ; then
  24. echo "invalid input TARGET (<remotehost>:<directory>)"
  25. exit 1
  26. fi
  27.  
  28. if git remote | grep -x $REPONAME ; then
  29. echo "REPONAME $REPONAME already exist."
  30. exit 1
  31. fi
  32.  
  33. # 既に存在することのチェック。
  34. existcheck=$(ssh $REMOTEHOST "[ -e $REMOTEDIR ] && echo exists")
  35. if [ "$existcheck" ] ; then
  36. echo "target directory $TARGET already exists, abort."
  37. exit 1
  38. fi
  39.  
  40. if [ ! "$REPONAME" ] ; then
  41. echo "you forget to set REPONAME."
  42. exit 1
  43. fi
  44.  
  45. TMPD=$(mktemp -d)
  46.  
  47. git clone --bare $SRC/.git $TMPD/tmp || exit 1
  48. ssh $REMOTEHOST mkdir -p $REMOTEDIR || exit 1
  49. rsync -ae ssh $TMPD/tmp/ $REMOTEHOST:$REMOTEDIR/ || exit 1
  50. git remote add $REPONAME $REMOTEHOST:$REMOTEDIR || exit 1
  51. git fetch $REPONAME || exit 1
  52.  
  53. echo done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement