Created
October 9, 2022 23:47
-
-
Save 0ex-d/8d9e454b2b008cc9236df94438301e2e to your computer and use it in GitHub Desktop.
bitbucket repo manager shell
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 | |
# import multiple remote git repositories to local CODE dir | |
# settings | |
remoteHost=bitbucket.org | |
remoteUser=mrbaguvix | |
remoteDir="~/scm/remote_dir/" | |
branchName="branch_name" | |
remoteRepos=$(ssh -l $remoteUser $remoteHost "ls $remoteDir") | |
localCodeDir="/local_code_dir" | |
# https://mrbaguvix@bitbucket.org/local_code_dir/repo_name.git | |
# if no output from the remote ssh cmd, bail out | |
if [ -z "$remoteRepos" ]; then | |
echo "No results from remote repo listing (via SSH)" | |
exit | |
fi | |
# for each repo found remotely, check if it exists locally | |
# assumption: name repo = repo.git, to be saved to repo (w/o .git) | |
# if dir exists, skip, if not, clone the remote git repo into it | |
for gitRepo in $remoteRepos | |
do | |
localRepoDir=$(echo ${localCodeDir}${gitRepo}|cut -d'.' -f1) | |
if [ -d $localRepoDir ]; then | |
echo -e "Directory $localRepoDir already exits, skipping ...\n" | |
else | |
cloneCmd="git clone https://$remoteUser@$remoteHost/$remoteDir" | |
cloneCmd=$cloneCmd"$gitRepo --branch branchName --single-branch $localRepoDir" | |
cloneCmdRun=$($cloneCmd 2>&1) | |
echo -e "Running: \n$ $cloneCmd" | |
echo -e "${cloneCmdRun}\n\n" | |
fi | |
done |
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 | |
# Shell script to read user input | |
# David Akin | |
read -p 'Enter your git username (e.g mrbaguvix): ' git_username | |
read -p 'Enter remote repository directory (default is remote_dir): ' git_remote_dir | |
if [[ -z $git_username ]]; then | |
echo "Enter a valid git username ❌\n" | |
echo "exiting..." | |
exit | |
fi | |
if [[ -z $git_remote_dir ]]; then | |
echo "Enter a valid remote repository ❌\n" | |
echo "exiting..." | |
exit | |
fi | |
echo "Username $git_username ✅" | |
echo "Remote dir $git_remote_dir ✅" | |
echo "https://${git_username}@bitbucket.org/${git_remote_dir}/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment