Last active
July 8, 2020 04:24
-
-
Save azilber/a9d744e3e3ff01d6f99c167b191a552c to your computer and use it in GitHub Desktop.
Migrate Git repos to AWS CodeCommit using Multi-Accounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
P=/home/git/repositories | |
ls -altrh $P/ | |
echo -n "Directory to migrate: " | |
read D | |
echo -n "Profile to migrate to: " | |
read PROFILE | |
workdir=/tmp | |
DIR=$(ls $P/$D | sed 's/.git//g') | |
for g in $DIR; do | |
cd $workdir | |
echo "Doing $D-$g" | |
git clone file://$P/$D/$g.git | |
echo "Cloned" | |
DESC=`ls -altrh $P/$D/$g.git/ |tail -1 |cut -d\ -f6-20` | |
echo "DESC: $DESC" | |
echo "Clone url: $URL" | |
cd $g | |
git log -n 1 | |
if [ $? -gt 0 ]; then | |
echo "Skipping $g. It's empty!" | |
else | |
git config credential.helper "!aws codecommit credential-helper --profile $PROFILE \$@" | |
git config credential.UseHttpPath true | |
URL=`aws codecommit create-repository --repository-name "$D-$g" --tags Terraform=false --repository-description "$DESC" --profile $PROFILE |jq -r '.[].cloneUrlHttp'` | |
echo "Adding remote to $g" | |
git remote add aws $URL | |
git push aws master | |
fi | |
cd $workdir | |
rm -Rf $g | |
echo "Cleaned up" | |
done | |
echo "Completed: $DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment