forked from shyim/shopware-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.sh
214 lines (179 loc) · 5.22 KB
/
functions.sh
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env bash
# Coloring/Styling helpers
esc=$(printf '\033')
export esc="${esc}"
export reset="${esc}[0m"
export blue="${esc}[34m"
export green="${esc}[32m"
export lightGreen="${esc}[92m"
export red="${esc}[31m"
export bold="${esc}[1m"
export warn="${esc}[41m${esc}[97m"
export modulesDefault=(base)
export modulesClassic=(base classic)
export modulesClassicComposerProject=(base classic-composer classic)
export modulesPlatform=(base platform)
export modulesLocal=(base local)
function fixHooks() {
rm "${SHOPWARE_FOLDER}/.git/hooks/pre-commit"
cd "${SHOPWARE_FOLDER}" || exit 1
ln -s ../../build/gitHooks/pre-commit .git/hooks/pre-commit
echo "Hooks fixed"
}
function clearCache() {
if [ -d "${SHOPWARE_FOLDER}/var/cache" ]; then
find "${SHOPWARE_FOLDER}/var/cache" -mindepth 1 -maxdepth 1 -type d -exec rm -r {} \;
fi
}
function checkParameter() {
if [[ -z "$SHOPWARE_PROJECT" ]]; then
echo "Please enter a shopware folder name"
exit 1
fi
if [[ ! -d "$SHOPWARE_FOLDER" ]]; then
echo "Folder $SHOPWARE_FOLDER does not exists!"
exit 1
fi
}
function trim_whitespace() {
# Function courtesy of http://stackoverflow.com/a/3352015
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
function get_image() {
folder=$1
var="VHOST_${folder^^}_IMAGE"
var="${var//-/_}"
val=${!var}
SUFFIX=""
if [[ $XDEBUG_ENABLE == "xdebug" ]]; then
SUFFIX="-xdebug"
fi
if [[ -n $val ]]; then
echo "$val"
else
IMAGE="ghcr.io/shyim/shopware-docker/5/nginx"
if [[ -f "$2/public/index.php" ]]; then
IMAGE="ghcr.io/shyim/shopware-docker/6/nginx"
fi
echo "${IMAGE}:php${PHP_VERSION}${SUFFIX}"
fi
}
function get_hosts() {
folder=$1
var="VHOST_${folder^^}_HOSTS"
var="${var//-/_}"
val=${!var}
if [[ -n $val ]]; then
echo "$val"
else
echo "${folder}.${DEFAULT_DOMAIN}" | tr -d '"'
fi
}
function get_host() {
hosts=$(get_hosts "$1")
host=$(cut -d ',' -f 1 <<<"${hosts}")
echo "$host"
}
function get_url() {
host=$(get_host "$1")
if [[ $USE_SSL_DEFAULT == "true" ]]; then
PORT=${HTTPS_PORT}
if [[ ${HTTPS_PORT} == "443" ]]; then
PORT=""
else
PORT=":${PORT}"
fi
echo "https://${host}${PORT}"
else
PORT=${HTTP_PORT}
if [[ ${HTTP_PORT} == "80" ]]; then
PORT=""
else
PORT=":${HTTP_PORT}"
fi
echo "http://${host}${PORT}"
fi
}
function get_cert_name() {
folder=$1
var="VHOST_${folder^^}_CERT_NAME"
var="${var//-/_}"
val=${!var}
if [[ -n $val ]]; then
echo "$val"
else
echo "shared"
fi
}
function get_document_root() {
folder=$1
var="VHOST_${folder^^}_DOCUMENT_ROOT"
var="${var//-/_}"
val=${!var}
if [[ -n $val ]]; then
echo "$val"
else
ROOT="/var/www/html/${folder}"
if [[ -f "$2/public/index.php" ]]; then
ROOT="/var/www/html/${folder}/public"
fi
echo "$ROOT"
fi
}
function get_serve_folders() {
for d in "${CODE_DIRECTORY}"/*; do
if [[ -d "$d" ]]; then
if [ -f "$d/public/index.php" ] || [ -f "$d/shopware.php" ] || [ -f "$d/.swdc/service.yml" ]; then
basename "$d"
fi
fi
done
}
function compose() {
additionalArgs=()
if [[ -e "${HOME}/.config/swdc/services.yml" ]]; then
additionalArgs=(-f "${HOME}/.config/swdc/services.yml")
fi
docker-compose -f "${DOCKER_COMPOSE_FILE}" "${additionalArgs[@]}" "$@"
}
function generate_wildcard_certs() {
openssl genrsa -out "${HOME}/.config/swdc/ssl/ca.key" 2048
openssl req -new -x509 -sha256 -days 20000 -key "${HOME}/.config/swdc/ssl/ca.key" -subj "/C=CN/ST=GD/L=SZ/O=SWDC./CN=SWDC CA" -out "${HOME}/.config/swdc/ssl/ca.crt"
openssl req -newkey rsa:2048 -nodes -keyout "${HOME}/.config/swdc/ssl/shared.key" -subj "/C=CN/ST=GD/L=SZ/O=SWDC, Inc./CN=*.${DEFAULT_DOMAIN}" -out "${HOME}/.config/swdc/ssl/shared.csr"
openssl x509 -req -sha256 -extfile <(echo -n "subjectAltName=DNS:*.${DEFAULT_DOMAIN}") -days 20000 -in "${HOME}/.config/swdc/ssl/shared.csr" -CA "${HOME}/.config/swdc/ssl/ca.crt" -CAkey "${HOME}/.config/swdc/ssl/ca.key" -CAcreateserial -out "${HOME}/.config/swdc/ssl/shared.crt"
}
function check_env_compability() {
if [ "${MYSQL_VERSION}" == "56" ] || [ "${MYSQL_VERSION}" == "57" ] || [ "${MYSQL_VERSION}" == "8" ]; then
echo "${red}Please change your \$MYSQL_VERSION variable to ghcr.io/shyim/shopware-docker/mysql:${MYSQL_VERSION}${reset}"
exit 1
fi
if [ -n "${ELASTICSEARCH_VERSION}" ]; then
echo "${red}ELASTICSEARCH_VERSION is removed. Please replace it with ELASTICSEARCH_IMAGE=blacktop/elasticsearch:${ELASTICSEARCH_VERSION} in your $HOME/.config/swdc/env file${reset}"
exit 1
fi
}
function platform_component() {
NAME=$1
if [[ -e src/Core/composer.json ]]; then
echo "src/${NAME}/"
elif [[ -e vendor/shopware/platform ]]; then
echo "vendor/shopware/platform/src/${NAME}/"
else
echo "vendor/shopware/${NAME,,}/"
fi
}
function fire_hook() {
EVENT=$1
shift
HOOKS_DIR="$HOME/.config/swdc/hooks"
if [[ -n $SWDC_IN_DOCKER ]]; then
HOOKS_DIR="/swdc-cfg/hooks"
fi
if [[ -e "$HOOKS_DIR/$EVENT.sh" ]]; then
# shellcheck disable=SC2145
echo ". $HOOKS_DIR/$EVENT.sh $@"
fi
}