Created
January 27, 2021 19:39
-
-
Save davidegironi/ff622406f1be118b8d3fe89db4f5a76a to your computer and use it in GitHub Desktop.
Script to download all repositories from a Bitbucket account
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
# Bitbucket Git Downloader | |
# Copyright (c) Davide Gironi, 2021 | |
# Released under GPLv3 | |
# Downloads all the repository from a Bitbucket account |
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 | |
# Bitbucket Git Downloader | |
# Copyright (c) Davide Gironi, 2021 | |
# Released under GPLv3 | |
DATAFOLDER=gitdata | |
if [ -z "$GIT_USERNAME" ]; then | |
echo "No GIT_USERNAME supplied" | |
exit | |
fi | |
if [ -z "$GIT_PASSWORD" ]; then | |
echo "No GIT_PASSWORD supplied" | |
exit | |
fi | |
if [ ! -d "$DATAFOLDER" ]; then | |
echo "data folder does not exists" | |
exit | |
fi | |
cd $DATAFOLDER | |
user=$GIT_USERNAME:$GIT_PASSWORD | |
url='https://api.bitbucket.org/2.0/user/permissions/repositories' | |
while [ ! "$url" == "null" ] | |
do | |
curl -u $user $url > repositories.json | |
jq -r '.values[] | .repository.links.html.href' repositories.json > repositories.txt | |
for repo in `cat repositories.txt` | |
do | |
REPOSITORYNAME=`basename "$repo"` | |
echo "Cloning" $REPOSITORYNAME | |
if [ -d $REPOSITORYNAME ] | |
then | |
cd $REPOSITORYNAME | |
git pull | |
cd .. | |
else | |
git clone $repo | |
fi | |
done | |
url=`jq -r '.next' repositories.json` | |
done | |
rm repositories.json | |
rm repositories.txt | |
cd - |
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 | |
# Bitbucket Git Downloader | |
# Copyright (c) Davide Gironi, 2021 | |
# Released under GPLv3 | |
#downloads all the repository from a Bitbucket account | |
#set you credential | |
#to store your password use git credential helper | |
# git config --global credential.helper store | |
export GIT_USERNAME=gitusername | |
export GIT_PASSWORD=gitpassword | |
./bitbucketgitdownloader.sh | |
Thanks for sharing your mod!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minor fix -- do the following before git clone command and make sure your ssh key is in the account, then you can just clone the ssh repo URL.