From d1745c5d51908cd7fe88e906ce021d722ca87c19 Mon Sep 17 00:00:00 2001 From: Sam Gleske <sag47@drexel.edu> Date: Wed, 11 Sep 2013 00:22:29 -0400 Subject: [PATCH] Config update and output update. Adding comments to config.sh. Renamed a few config.sh variables to be more intuitive. add_mirror.sh has better user output. Updated to reflect new config.sh. git-mirrors.sh now outputs proper error codes. create_gitlab_project.py updated to reflect new config.sh --- add_mirror.sh | 11 +++++++++-- config.sh | 16 +++++++++++++--- git-mirrors.sh | 4 ++++ lib/create_gitlab_project.py | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/add_mirror.sh b/add_mirror.sh index 579135f..de5854b 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 9d47271..21440fa 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 3eddef7..4a8047e 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 6ffd2e8..2985b44 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'] -- GitLab