forked from shyim/shopware-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
182 lines (154 loc) · 4.31 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
#!/usr/bin/env bash
# Coloring/Styling helpers
esc=$(printf '\033')
reset="${esc}[0m"
blue="${esc}[34m"
green="${esc}[32m"
lightGreen="${esc}[92m"
red="${esc}[31m"
bold="${esc}[1m"
warn="${esc}[41m${esc}[97m"
modulesDefault=(base)
modulesClassic=(base classic)
modulesClassicComposerProject=(base classic-composer classic)
modulesPlatform=(base platform)
modulesLocal=(base local)
function fixHooks()
{
rm "${SHOPWARE_FOLDER}/.git/hooks/pre-commit"
cd "${SHOPWARE_FOLDER}" || exit
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 [[ ! -z $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 [[ ! -z $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 [[ ! -z $val ]]; then
echo $val
else
echo "shared"
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" ]; then
echo $(basename $d)
fi
fi
done
}
function compose()
{
docker-compose -f ${DOCKER_COMPOSE_FILE} $@
}
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 <(printf "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
}
function platform_component()
{
NAME=$1
if [[ -e vendor/shopware/platform ]]; then
echo "vendor/shopware/platform/src/${NAME}/"
else
echo "vendor/shopware/${NAME,,}"
fi
}