Created
January 15, 2020 20:07
-
-
Save dcoric/2b45b174ad429f3169044c0d8c092cf7 to your computer and use it in GitHub Desktop.
Synchronization script for shpayz project
This file contains hidden or 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 | |
| DIR= | |
| MODULE= | |
| BRANCH= | |
| TAG_VERSION= | |
| ERROR_TAG= | |
| BRANCH_EXISTS= | |
| TAG_EXISTS= | |
| print_usage() { | |
| printf "Unknown flag $ERROR_TAG\n\n" | |
| printf "Usage: \n" | |
| printf "$0 [:parameter [value]]\n" | |
| printf "\nParameters:\n\t" | |
| printf -- "-d" | |
| printf "\t set module directory\n\t" | |
| printf -- "-m" | |
| printf "\t set module name\n\t" | |
| printf -- "-b" | |
| printf "\t set branch name\n\t" | |
| printf -- "-t" | |
| printf "\t set tag name\n" | |
| printf "\n" | |
| printf "Example: ${0}" | |
| printf -- " -t v16.032.00 -d shpayz -m super-module\n\n" | |
| exit 2 | |
| } | |
| while getopts 'd:m:b:t:?h' flag; do | |
| case "${flag}" in | |
| d) DIR="${OPTARG}" ;; | |
| m) MODULE="${OPTARG}" ;; | |
| b) BRANCH="${OPTARG}" ;; | |
| t) TAG_VERSION="${OPTARG}" ;; | |
| h|?) print_usage ;; | |
| esac | |
| done | |
| ([ -z "$DIR" ] || [ -z "$MODULE" ]) && print_usage | |
| [ -z "$TAG_VERSION" ] && [ -z "$BRANCH" ] && BRANCH="production" | |
| MODULE_DIR="${DIR}/${MODULE}" | |
| printf "Selected parameters: \n\tDIR:${DIR}\n\tMODULE:${MODULE}\n\tBRANCH:${BRANCH}\n\tTAG:${TAG_VERSION}\n\tMODULE-DIR:${MODULE_DIR}\n" | |
| #exit 1 #Enable for param test | |
| [[ -d "$DIR" ]] || mkdir -p $DIR | |
| BRANCH_EXISTS=$(git ls-remote --heads git@gitlab.mylimobiz.local:shpayz/$MODULE.git $BRANCH | wc -l) | |
| TAG_EXISTS=$(git ls-remote --tags git@gitlab.mylimobiz.local:shpayz/$MODULE.git $TAG_VERSION | wc -l) | |
| if [ -d "$MODULE_DIR" ] | |
| then | |
| echo "$MODULE_DIR directory exists!" | |
| if [ -z "$TAG_VERSION" ]; then | |
| cd $MODULE_DIR && git fetch --all && git checkout $BRANCH && git status && git pull | |
| else | |
| cd $MODULE_DIR && git fetch --all && git checkout tags/$TAG_VERSION | |
| fi | |
| else | |
| echo "$MODULE_DIR directory not found!" | |
| cd $DIR | |
| if [ -z "$TAG_VERSION" ]; | |
| then | |
| git clone git@gitlab.mylimobiz.local:shpayz/$MODULE.git && cd $MODULE && git fetch --all && git checkout $BRANCH && git pull origin $BRANCH | |
| else | |
| git clone git@gitlab.mylimobiz.local:shpayz/$MODULE.git && cd $MODULE && git fetch --all && git checkout tags/$TAG_VERSION | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment