Skip to content

Instantly share code, notes, and snippets.

@sallyom
Created July 29, 2016 18:35
Show Gist options
  • Save sallyom/7873aa65a00a083ef3dd39d60f7ef54d to your computer and use it in GitHub Desktop.
Save sallyom/7873aa65a00a083ef3dd39d60f7ef54d to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
# Need my vagrant branch until PR is merged
REPO=(online ose)
INSTANCE_NAME=$USER-online-dev
SSH_CONFIG=$(mktemp $INSTANCE_NAME.sshconfig.XXX)
vagrant ssh-config > $SSH_CONFIG
for i in "${REPO[@]}"
do
#CURRENT_BRANCH=`git branch | sed -n '/\* /s///p'`
BARE_REPO="$i-bare"
REPO_PATH=/data/src/github.com/openshift/$i
BARE_REPO_PATH=/data/src/github.com/openshift/$BARE_REPO
case "$i" in
online )
CURRENT_BRANCH=`( git rev-parse --abbrev-ref HEAD )`
vagrant ssh -c "REPO=online;
BARE_REPO=$REPO-bare;
REPO_PATH=/data/src/github.com/openshift/$REPO;
BARE_REPO_PATH=/data/src/github.com/openshift/$BARE_REPO;"
;;
ose )
pushd ../ose > /dev/null
CURRENT_BRANCH=`( git rev-parse --abbrev-ref HEAD )`
popd > /dev/null
vagrant ssh -c "REPO=ose;
BARE_REPO=$REPO-bare;
REPO_PATH=/data/src/github.com/openshift/$REPO;
BARE_REPO_PATH=/data/src/github.com/openshift/$BARE_REPO;"
;;
esac
echo "cloning $i..."
# This is specific to AWS 'ec2-user'
vagrant ssh -c "rm -rf $BARE_REPO_PATH;
rm -rf $REPO_PATH;
sudo chown -R ec2-user:ec2-user /data/src/github.com/openshift;
pushd /data/src/github.com/openshift > /dev/null;
git init --bare $BARE_REPO;
git clone $BARE_REPO_PATH $REPO_PATH;
pushd $REPO > /dev/null;
touch file.txt;
git add .;
git commit -m 'added a file';
git config --global push.default simple;
git push origin master;
popd > /dev/null;
popd > /dev/null;"
PUBLIC_DNS=`vagrant ssh -c "curl -s http://169.254.169.254/latest/meta-data/public-hostname"`
echo "VAGRANT PUBLIC DNS: ${PUBLIC_DNS}"
case "$i" in
online )
git push -q ssh://ec2-user@$PUBLIC_DNS$BARE_REPO_PATH --force;;
ose )
pushd ../ose > /dev/null
git push -q ssh://ec2-user@$PUBLIC_DNS$BARE_REPO_PATH --force
popd > /dev/null
;;
esac
# Using my vagrant branch until PR is merged...
vagrant ssh -c "pushd $BARE_REPO_PATH > /dev/null;
git push origin $CURRENT_BRANCH;
popd > /dev/null;
pushd $REPO_PATH > /dev/null;
git remote -v;
git fetch --all;
git checkout $CURRENT_BRANCH;
popd > /dev/null;"
rm $SSH_CONFIG
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment