diff --git a/add_mirror.sh b/add_mirror.sh index 579135f393544b6a7a713ec92f6f4975f7b9da18..de5854bc96fe205514c5939cbc2d1f544f2b00c4 100755 --- a/add_mirror.sh +++ b/add_mirror.sh @@ -8,12 +8,15 @@ . "$(dirname $0)/config.sh" cd $(dirname $0) -export token_secret gitlab_url gitlab_namespace gitlab_user +#export env vars for python script +export gitlab_user_token_secret gitlab_url gitlab_namespace gitlab_user #Get the remote gitlab url for the specified project. #If the project doesn't already exist in gitlab then create it. -if python lib/create_gitlab_project.py $1 &> /dev/null;then +echo "Resolving gitlab remote." +if python lib/create_gitlab_project.py $1 1> /dev/null;then gitlab_remote=$(python lib/create_gitlab_project.py $1) + echo "gitlab remote ${gitlab_remote}" else echo "There was an unknown issue with create_gitlab_project.py" 1>&2 exit 1 @@ -22,14 +25,18 @@ fi mkdir -p "${repo_dir}/${gitlab_namespace}" #create a mirror +echo "Creating mirror from $2" cd "${repo_dir}/${gitlab_namespace}" git clone --mirror $2 "$1" cd "$1" #add the gitlab remote +echo "Adding gitlab remote to project." git remote add gitlab ${gitlab_remote} git config --add remote.gitlab.push '+refs/heads/*:refs/heads/*' git config --add remote.gitlab.push '+refs/heads/*:refs/heads/*' #Check the initial repository into gitlab +echo "Checking the mirror into gitlab." git fetch git remote prune origin git push gitlab +echo "All done!" diff --git a/config.sh b/config.sh index 9d472712726136ff3d2dd74265c4c3bd5ce0ff7f..21440fab333f30e29d8250730df40d1a79e5aa07 100644 --- a/config.sh +++ b/config.sh @@ -1,9 +1,19 @@ #Environment file +# +# gitlab-mirror settings +# repo_dir="/home/gitmirror/repositories" -mirror_list=("gitlabhq") -token_secret="$(head -n1 /home/gitmirror/private_token)" -#This group will contain all code mirrors + +# +# Gitlab settings +# + +#This is the Gitlab group where all project mirrors will be grouped. gitlab_namespace="Mirrors" +#This is the web url of your Gitlab server. no trailing slash, just the protocol and server name. gitlab_url="https://comet.irt.drexel.edu" +#Special user you created in Gitlab whose only purpose is to update mirror sites and admin the $gitlab_namespace group. gitlab_user="gitmirror" +#Generate a token for your $gitlab_user and set it here. +gitlab_user_token_secret="$(head -n1 /home/gitmirror/private_token)" diff --git a/git-mirrors.sh b/git-mirrors.sh index 3eddef70ea300ad2edcfb534eec35c2c2b05ad46..4a8047ef689d608840b735afcd906e912aa4bcfb 100755 --- a/git-mirrors.sh +++ b/git-mirrors.sh @@ -5,8 +5,12 @@ . "$(dirname $0)/config.sh" cd $(dirname $0) +STATUS=0 + ls -1 "${repo_dir}/${gitlab_namespace}" | while read mirror;do if ! ./update_mirror.sh "${mirror}" &> /dev/null;then echo "Error: ./update_mirror.sh ${mirror}" 1>&2 + STATUS=1 fi done +exit ${STATUS} diff --git a/lib/create_gitlab_project.py b/lib/create_gitlab_project.py index 6ffd2e89c828fc24942b961ce9ba3e4d9ce48e29..2985b44a962a8c46cccc737453a3425790f4ae93 100755 --- a/lib/create_gitlab_project.py +++ b/lib/create_gitlab_project.py @@ -7,7 +7,7 @@ import gitlab try: project_name=argv[1] - token_secret=os.environ['token_secret'] + token_secret=os.environ['gitlab_user_token_secret'] gitlab_url=os.environ['gitlab_url'] gitlab_namespace=os.environ['gitlab_namespace'] gitlab_user=os.environ['gitlab_user']