-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
56 lines (50 loc) · 1.46 KB
/
common.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
#!/bin/bash
#
# Copyright (c) 2023 Heiko Lübbe
# This software is licensed under the MIT License.
# For the full license text, see the LICENSE file in the project root or visit https://opensource.org/licenses/MIT
#
# common.sh - functionality sourced by the other bash scripts
#
# function to check if an array contains a specific value
#
containsElement() {
local element match="$1"
shift
for element; do
[[ "$element" == "$match" ]] && return 0
done
return 1
}
# available Joomla versions
all_versions=(3 4 5)
#
# if version given, then check if available
# set ${all_versions[*]} and ${versions[*]} arrays
# set config_cypress_options from env var CYPRESS_OPTIONS or as empty string
# set minor as two-number e.g. "50"
#
checkVersion() {
if [ "$#" -gt 1 ] || ([ "$#" -eq 1 ] && ! containsElement "$1" "${all_versions[@]}"); then
echo "*** Error: no argument (for all) or Joomla version from: ${all_versions[@]}"
exit 1
fi
if [ "$#" -ne 0 ]; then
versions=("$1")
else
versions=${all_versions[*]}
fi
config_cypress_options=""
if [ "$CYPRESS_OPTIONS" != "" ]; then
config_cypress_options="--config $CYPRESS_OPTIONS"
fi
}
#
# check valid Joomla version as one argument
#
checkOneVersion() {
if [ "$#" -ne 1 ] || ! containsElement "$1" "${all_versions[@]}"; then
echo "*** Error: needs Joomla version as one and only argument from: ${all_versions[@]}"
exit 1
fi
}