Skip to content

Instantly share code, notes, and snippets.

@dmc-at-work
Last active March 8, 2019 01:54
Show Gist options
  • Save dmc-at-work/8265d61df3b4b8e07165681d46032880 to your computer and use it in GitHub Desktop.
Save dmc-at-work/8265d61df3b4b8e07165681d46032880 to your computer and use it in GitHub Desktop.
Clone Multiple Git Repositories
################################################################################
#
# prepend
# sed -e s#^#prefix#g file.txt > new_file.txt
# sed -i s#^#prefix#g file.txt
# append
# sed -e s#$#suffix#g file.txt > new_file.txt
# sed -i s#$#suffix#g file.txt
# awk style
# awk '$0="prefix"$0' file > new_file
# awk '$0=$0"suffix"' file > new_file
################################################################################
file=$1
if [ ! -e $file ]; then
echo "File not found!"
exit 1
else
echo "Processing $file..."
fi
cp "$file" "$file".repolist
sed -i 's#^#https://__scm-user__@__scm-cname__/__scm-project-path__/#g' "$file".repolist
sed -i 's#$#.git#g' "$file".repolist
################################################################################
#!/bin/bash
################################################################################
# multi-git-clone.sh
# $ ./multi-git-clone.sh <name-or-*>.repolist
#
# v20190307
# dmc-at-work
#
# Pre-Tasks:
# - Templated .repolist file(s) can be replaced
# with known list of URLs/URIs
# - Or template can be ran through sed replace
# routines for the known URL/URI vars:
# [__scm-user__, __scm-cname__, __scm-project-path__]
# - sed -i "s#__scm-user__#$scm_user-var#g" sample.repolist
# - sed -i "s#__scm-cname__#$scm_cname#g" sample.repolist
# - sed -i "s#__scm-project-path__#$scm_pce_path#g" sample.repolist
# - Or template URL/URI vars can be replaced
# manually
################################################################################
if [[ $# -eq 0 ]] ; then
echo 'Usage:'
echo '$ ./multi-git-clone.sh <name-or-*>.repolist'
exit 1
fi
readarray urls <<< $( cat "$@" )
for scm_url in ${urls[@]}
do
echo "Cloning $scm_url ..."
git clone $scm_url
done
#!/bin/bash
################################################################################
# repolist-variables-update.sh
# $ ./repolist-variables-update.sh <filename>.repolist
#
# v20190307
# dmc-at-work
#
# Description:
# - Utility to update repolist scm vars
# - Use with existing environment variables or
# override with shell script exported environment variables
################################################################################
if [[ $# -eq 0 ]] ; then
echo 'Usage:'
echo '$ ./repolist-variables-update.sh <filename>.repolist'
exit 1
fi
filename=$1
export scm_user={replace-with-user-string}
export scm_name={replace-with-host-string}
export scm_project_path={replace-with-path-string}
sed -i "s#__scm-user__#$scm_user#g" $filename
sed -i "s#__scm-cname__#$scm_cname#g" $filename
sed -i "s#__scm-project-path__#$scm_project_path#g" $filename
https://__scm-cname__/__scm-project-path__/01.git
https://__scm-cname__/__scm-project-path__/02.git
https://__scm-cname__/__scm-project-path__/03.git
https://__scm-cname__/__scm-project-path__/04.git
https://__scm-cname__/__scm-project-path__/05.git
https://__scm-cname__/__scm-project-path__/06.git
https://__scm-cname__/__scm-project-path__/07.git
https://__scm-cname__/__scm-project-path__/08.git
https://__scm-cname__/__scm-project-path__/09.git
https://__scm-cname__/__scm-project-path__/10.git
https://__scm-user__@__scm-cname__/__scm-project-path__/01.git
https://__scm-user__@__scm-cname__/__scm-project-path__/02.git
https://__scm-user__@__scm-cname__/__scm-project-path__/03.git
https://__scm-user__@__scm-cname__/__scm-project-path__/04.git
https://__scm-user__@__scm-cname__/__scm-project-path__/05.git
https://__scm-user__@__scm-cname__/__scm-project-path__/06.git
https://__scm-user__@__scm-cname__/__scm-project-path__/07.git
https://__scm-user__@__scm-cname__/__scm-project-path__/08.git
https://__scm-user__@__scm-cname__/__scm-project-path__/09.git
https://__scm-user__@__scm-cname__/__scm-project-path__/10.git
@johnfrancisdeleon
Copy link

Very nice! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment