diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3a26abf7fe10212a12da0efc4aa598b399c5650f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config.sh +*.pyc diff --git a/add_mirror.sh b/add_mirror.sh index 53bb095e37604bdb67d19085940a91edd9dc661a..bf82bfacc65d7758cb9de04989605a253b4b5a86 100755 --- a/add_mirror.sh +++ b/add_mirror.sh @@ -3,15 +3,114 @@ #USAGE # ./add_mirror.sh project_name http://example.com/project.git +#Include all user options +. "$(dirname $0)/config.sh" +cd $(dirname $0) + +PROGNAME="${0##*/}" +PROGVERSION="v0.2" + + +#Default script options +svn=false +git=false +project_name="" +mirror="" + +#Short options are one letter. If an argument follows a short opt then put a colon (:) after it +SHORTOPTS="hvm:p:" +LONGOPTS="help,version,git,svn,mirror:,project:" + +usage() +{ + cat <<EOF +${PROGNAME} ${PROGVERSION} - MIT License by Sam Gleske + +DESCRIPTION: + This will add a git or SVN repository to be mirrored by GitLab. It + first checks to see if the project exists in gitlab. If it does + not exist then it creates it. It will then clone and check in the + first copy into GitLab. From there you must use the update_mirror.sh + script or git git-mirrors.sh script. + + -h,--help Show help + -v,--version Show program version + --git Mirror a git repository (must be explicitly set) + --svn Mirror a SVN repository (must be explicitly set) + --project NAME Set a GitLab project name to NAME. + --mirror URL Repository URL to be mirrored. + + +EOF +} + +ARGS=$(getopt -s bash --options "${SHORTOPTS}" --longoptions "${LONGOPTS}" --name "${PROGNAME}" -- "$@") +eval set -- "$ARGS" +echo "$ARGS" +while true; do + case $1 in + -h|--help) + usage + exit 1 + ;; + -v|--version) + echo "${PROGNAME} ${PROGVERSION}" + exit 1 + ;; + --git) + git=true + shift + ;; + --svn) + svn=true + shift + ;; + -p|--project) + project_name="${2}" + shift 2 + ;; + -m|--mirror) + mirror="${2}" + shift 2 + ;; + --) + shift + break + ;; + *) + shift + break + ;; + esac +done + + +echo "svn=${svn}" +echo "git=${git}" +echo "project_name=${project_name}" +echo "mirror=${mirror}" + + + + + + + + + + + + + + +exit + if [ "${#}" -lt "2" ];then echo "Not enough arguments." 1>&2 echo "e.g. ./add_mirror.sh project_name http://example.com/project.git" 1>&2 exit 1 fi -#Include all user options -. "$(dirname $0)/config.sh" -cd $(dirname $0) #export env vars for python script export gitlab_user_token_secret gitlab_url gitlab_namespace gitlab_user diff --git a/config.sh b/config.sh deleted file mode 100644 index 2bc515279a1b2c6984ad1540e53f1add93cdce00..0000000000000000000000000000000000000000 --- a/config.sh +++ /dev/null @@ -1,22 +0,0 @@ -#Environment file - -# -# gitlab-mirror settings -# - -system_user="gitmirror" -user_home="/home/${system_user}" -repo_dir="${user_home}/repositories" - -# -# 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 "${user_home}/private_token")"