Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! カレントディレクトリのリポジトリを指定した位置におき、
- #! 指定したリポジトリ名で push できるようにする。
- #! ターゲットはパスワードなしで ssh 接続できる想定とする。
- #!
- #! Usage:
- #! put_bare_repository.sh <remotehost>:<remotedirectory> <reponame>
- #!
- SRC=$PWD
- if [ ! -d $SRC/.git ] ; then
- echo current directory is not git repository.
- exit 1
- fi
- TARGET=$1
- REPONAME=$2
- # ターゲットがリモートである前提
- REMOTEHOST=$(echo $TARGET | cut -f1 -d:)
- REMOTEDIR=$(echo $TARGET | cut -f2 -d:)
- if [ ! "$REMOTEDIR" ] ; then
- echo "invalid input TARGET (<remotehost>:<directory>)"
- exit 1
- fi
- if git remote | grep -x $REPONAME ; then
- echo "REPONAME $REPONAME already exist."
- exit 1
- fi
- # 既に存在することのチェック。
- existcheck=$(ssh $REMOTEHOST "[ -e $REMOTEDIR ] && echo exists")
- if [ "$existcheck" ] ; then
- echo "target directory $TARGET already exists, abort."
- exit 1
- fi
- if [ ! "$REPONAME" ] ; then
- echo "you forget to set REPONAME."
- exit 1
- fi
- TMPD=$(mktemp -d)
- git clone --bare $SRC/.git $TMPD/tmp || exit 1
- ssh $REMOTEHOST mkdir -p $REMOTEDIR || exit 1
- rsync -ae ssh $TMPD/tmp/ $REMOTEHOST:$REMOTEDIR/ || exit 1
- git remote add $REPONAME $REMOTEHOST:$REMOTEDIR || exit 1
- git fetch $REPONAME || exit 1
- echo done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement