-
Notifications
You must be signed in to change notification settings - Fork 2
/
install
executable file
·146 lines (117 loc) · 3.83 KB
/
install
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
set -e
# returns dokman directory
readonly DOKMAN_RELATIVE_PATH=$(dirname "${BASH_SOURCE[0]}")
readonly DOKMAN_SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
# install everything in parent folder
readonly installPath=$(dirname "${DOKMAN_RELATIVE_PATH}")
readonly DOKMAN_DIR_NAME=$(basename "${DOKMAN_SCRIPT_DIR}")
source "${DOKMAN_SCRIPT_DIR}/autoload.sh"
####################################################################
####################################################################
# Configuration
####################################################################
readonly folders=(
services
configurations
environments
images
scripts
)
readonly files=(
.env.dist
.env
)
readonly templateScripts=(
.install.sh
)
readonly symlinkScripts=(
env
run
enter
install
)
readonly gitIgnore=(
"# exclude man .env file"
/.env
"# exclude all environments specific .env files"
/environments/*/.env
"# exclude global override"
/override.yml
"# exclude all environment specific override.yml files"
/environments/*/override.yml
)
####################################################################
####################################################################
# Install logic
####################################################################
title "Installing dokman!"
readonly DOKMAN_PROJECT_NAME=$(questionForceNotEmptyResponse "Project name" "Project name can not be empty string")
title "Setup directories if needed..."
# setup directories if needed
for directory in "${folders[@]}"
do
label=$(foregroundColor "${directory}" "yellow")
if [ ! -d "${installPath}/${directory}" ]; then
mkdir "${installPath}/${directory}"
success "Created directory ${label}"
else
info "Directory ${label} already exists, skipping!"
fi
done
title "Setup files if needed..."
# setup empty files if needed
for file in "${files[@]}"
do
label=$(foregroundColor "${file}" "yellow")
if [ ! -f "${installPath}/${file}" ]; then
touch "${installPath}/${file}"
success "Created file ${label}"
else
info "File ${label} already exists, skipping!"
fi
done
title "Setup .gitignore if needed..."
# setup git ignore file if needed
label=$(foregroundColor ".gitignore" "yellow")
if [ ! -f "${installPath}/.gitignore" ]; then
touch "${installPath}/.gitignore"
success "Created file ${label}"
for line in "${gitIgnore[@]}"
do
echo "${line}" >> "${installPath}/.gitignore"
done
else
info "File ${label} already exists, skipping!"
fi
title "Copying template scripts if needed..."
# setup files from templates
for templateScript in "${templateScripts[@]}"
do
pathToScript="${installPath}/${templateScript}"
label=$(foregroundColor "${templateScript}" "yellow")
if [ ! -f "${pathToScript}" ]; then
scriptContent=$(cat "${DOKMAN_SCRIPT_DIR}/templates/${templateScript}")
# setup template files
createFile "${pathToScript}" "${scriptContent}"
success "Copied template file ${label}"
else
info "File ${label} already exists, skipping!"
fi
done
title "Symlinking scripts if needed..."
for symlinkScript in "${symlinkScripts[@]}"
do
pathToScript="${installPath}/${symlinkScript}"
label=$(foregroundColor "${symlinkScript}" "yellow")
if [ ! -L "${pathToScript}" ]; then
ln -s "${DOKMAN_DIR_NAME}/bin/${symlinkScript}" "${pathToScript}"
success "Symlink for file ${label} created"
else
info "Symlink ${label} already exists, skipping!"
fi
done
title "Setting project name..."
echo "COMPOSE_PROJECT_NAME=${DOKMAN_PROJECT_NAME}" > "${installPath}/.env.dist"
success "Variable COMPOSE_PROJECT_NAME set as $(foregroundColor "${DOKMAN_PROJECT_NAME}" "yellow") in .env.dist configuration"
success "Installation done!"