-
Notifications
You must be signed in to change notification settings - Fork 0
/
docksal
executable file
·86 lines (67 loc) · 2.46 KB
/
docksal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
## Add a Docksal for existing project.
##
## Usage: fin fj/docksal [project name]
## Run from project root
# Abort if anything fails
set -e
#-------------------------------- Settings -------------------------------------
PROJECT_ROOT=$(pwd)
PROJECT_NAME=$1
BRANCH_NAME=${2:-master}
GIT_REMOTE="[email protected]:fivejars/${PROJECT_NAME}-docksal.git"
#----------------------------- END: Settings -----------------------------------
#---------------------------- Helper functions ---------------------------------
# Console colors
red='\033[0;31m'
green='\033[0;32m'
green_bg='\033[42m'
yellow='\033[1;33m'
NC='\033[0m'
echo-red () { echo -e "${red}$1${NC}"; }
echo-green () { echo -e "${green}$1${NC}"; }
echo-green-bg () { echo -e "${green_bg}$1${NC}"; }
echo-yellow () { echo -e "${yellow}$1${NC}"; }
#-------------------------- END: Helper functions ------------------------------
#------------------------------- Functions -------------------------------------
# Initialize local settings files
load_docksal ()
{
# Check that user has access to fivejars/fj-docksal-commands repository
echo-green "Check access to remote repository"
git ls-remote ${GIT_REMOTE}
# Clone commands to fj directory (Commands Group).
echo-green "Load commands from remote repository"
cd ${PROJECT_ROOT}
git clone --branch ${BRANCH_NAME} ${GIT_REMOTE} .docksal
}
#----------------------------- END: Functions ----------------------------------
#------------------------------- Execution -------------------------------------
echo-green-bg "Add a Docksal for [$PROJECT_NAME] project."
if [[ -z "$PROJECT_NAME" ]]; then
echo-red "Error: Please specify project name: fin fj/docksal [project name]"
exit 1
fi
if [[ -d "$PROJECT_ROOT/.docksal" ]]; then
echo-green ".docksal already exist in this project, pull updates."
cd "$PROJECT_ROOT/.docksal"
git fetch origin ${BRANCH_NAME}
echo-green "Discard changes in working directory."
git checkout
echo-green "Checkout to ${BRANCH_NAME} branch."
EXISTS=$(eval "git show-ref refs/heads/${BRANCH_NAME}")
if [ -z "$EXISTS" ]
then
echo-green "Create branch!"
git checkout -B ${BRANCH_NAME} origin/${BRANCH_NAME}
else
echo-green "Branch exists!"
git checkout ${BRANCH_NAME}
fi
git pull origin ${BRANCH_NAME}
else
echo-green "Load docksal for specified project"
load_docksal
fi
echo-green-bg "Installation completed!"
#----------------------------- END: Execution ----------------------------------