-
Notifications
You must be signed in to change notification settings - Fork 1
/
info
executable file
·173 lines (154 loc) · 6.95 KB
/
info
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
#!/bin/bash
#
# info - Retrieves Joomla Branches Tester status information.
#
# Distributed under the GNU General Public License version 2 or later, Copyright (c) 2024 Heiko Lübbe
# https://github.com/muhme/joomla-branches-tester
if [[ $(dirname "$0") != "scripts" || ! -f "scripts/helper.sh" ]]; then
echo "Please run me as 'scripts/info'. Thank you for your cooperation! :)"
exit 1
fi
source scripts/helper.sh
function help {
echo "
info – Retrieves Joomla Branches Tester status information.
The optional 'instance' argument displays Joomla Branches Tester instance details.
The optional 'base' argument displays information about the base Docker containers.
Optional Joomla instance arguments can be one or more of installed: ${allInstalledInstances[*]}.
The optional argument 'help' displays this page. For full details see https://bit.ly/JBT-README.
If no argument is provided, all information is displayed.
$(random_quote)"
}
# shellcheck disable=SC2207 # There are no spaces in instance numbers
allInstalledInstances=($(getAllInstalledInstances))
if [ $# -eq 0 ]; then
# shellcheck disable=SC2207 # There are no spaces in instance numbers
all_todos=("instance" "base" $(getAllInstalledInstances))
else
all_todos=()
fi
while [ $# -ge 1 ]; do
if [[ "$1" =~ ^(help|-h|--h|-help|--help|-\?)$ ]]; then
help
exit 0
elif [ "$1" = "instance" ]; then
all_todos+=("$1")
shift # Argument is eaten as to show JBT information.
elif [ "$1" = "base" ]; then
all_todos+=("$1")
shift # Argument is eaten as to show base containers.
elif [ -d "joomla-$1" ]; then
all_todos+=("$1")
shift # Argument is eaten as one instance.
else
help
error "Argument '$1' is not valid."
exit 1
fi
done
docker_running=false
if docker info >/dev/null 2>&1; then
docker_running=true
else
log "Docker is NOT running?"
fi
for todo in "${all_todos[@]}"; do
if [ "${todo}" = "instance" ]; then
# Get the current local version and the latest version from the GitHub repository
local_version=$(cat VERSION)
# Ignore failures (e.g., if the system is offline).
git_version=$(curl -s -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/muhme/joomla-branches-tester/main/VERSION || true)
# Real compare version numbers as raw.githubusercontent.com is always a little behind the times
version_gt() {
[ "$(printf '%s\n' "$@" | sort -V | tail -n 1)" != "$1" ]
}
header "Joomla Branches Tester (JBT) version ${local_version}"
if version_gt "${local_version}" "${git_version}"; then
red "There is a newer version ${git_version} available. Please run 'git pull' to stay current."
fi
if ${docker_running}; then
echo " Docker version $(docker version --format '{{.Server.Version}}') is running with" \
"$(docker ps -q | wc -l | tr -d ' ') containers and $(docker images -q | wc -l | tr -d ' ') images"
docker inspect jbt-network|grep EnableIPv6| sed -e 's/[ ]*//' -e 's/[",]//g' -e 's/^/ /'
fi
elif [ "$todo" = "base" ]; then
if ${docker_running}; then
header "Base Containers"
for container in "${JBT_BASE_CONTAINERS[@]}"; do
if [ "$(docker ps -q -f "name=${container}")" ]; then
padded_container=$(printf "%-11s" "$container")
ports=$(docker port "${container}" | awk '{printf "%s; ", $0} END {print ""}' | sed 's/; $/\n/')
echo " $padded_container is running, ports: $ports"
else
echo " " && error "${container} is not running."
fi
done
fi
else # Installed Joomla instance
instance="$todo"
branch_name=$(docker exec "jbt-${instance}" bash -c "git branch -r --contains HEAD 2>/dev/null | head -1 | sed 's|[ ]*origin/||'")
if [ -n "${branch_name}" ]; then
header "jbt-${instance} Branch ${branch_name}"
else
tag_name=$(docker exec "jbt-${instance}" bash -c "git describe --tags 2>/dev/null; true")
if [ -n "${tag_name}" ]; then
header "jbt-${instance} Tag ${tag_name}"
else
header "jbt-${instance} ¿Grafted?"
fi
fi
if ${docker_running}; then
if [ "$(docker ps -q -f "name=jbt-${instance}")" ]; then
ports=$(docker port "jbt-${instance}" | awk '{printf "%s; ", $0} END {print ""}' | sed 's/; $/\n/')
echo " Container jbt-${instance} is running, ports: $ports"
else
echo " Container jbt-${instance} is NOT running."
fi
fi
if [ -d "joomla-${instance}" ]; then
version_file="joomla-${instance}/libraries/src/Version.php"
if [ -f "${version_file}" ]; then
product=$(grep "const PRODUCT" "${version_file}" | awk -F"'" '{print $2}')
major_version=$(grep "const MAJOR_VERSION" "${version_file}" | awk -F" " '{print $NF}' | tr -d ';')
minor_version=$(grep "const MINOR_VERSION" "${version_file}" | awk -F" " '{print $NF}' | tr -d ';')
patch_version=$(grep "const PATCH_VERSION" "${version_file}" | awk -F" " '{print $NF}' | tr -d ';')
extra_version=$(grep "const EXTRA_VERSION" "${version_file}" | awk -F"'" '{print $NF}' | tr -d ';')
dev_status=$(grep "const DEV_STATUS" "${version_file}" | awk -F"'" '{print $2}')
echo -n " Joomla Version: $product $major_version.$minor_version.$patch_version"
if [ -n "${extra_version}" ]; then
echo "-$extra_version"
fi
echo " ${dev_status}"
fi
if ${docker_running}; then
php_version=$(docker exec "jbt-${instance}" bash -c "php --version")
# Extract the PHP version (first line) using sed
php_version_number=$(echo "$php_version" | sed -n 's/^PHP \([0-9\.]*\).*/PHP \1/p')
# Check if Xdebug is included in the PHP version info
if echo "$php_version" | grep -q "Xdebug"; then
echo " $php_version_number with Xdebug"
else
echo " $php_version_number"
fi
fi
# Handle .js or .mjs from PR https://github.com/joomla/joomla-cms/pull/43676 – [4.4] Move the Cypress Tests to ESM
if [ -f "joomla-${instance}/cypress.config.mjs" ]; then
config_file="joomla-${instance}/cypress.config.mjs"
elif [ -f "joomla-${instance}/cypress.config.js" ]; then
config_file="joomla-${instance}/cypress.config.js"
fi
if [ -f "${config_file}" ]; then
db_type=$(grep db_type "${config_file}" | sed 's/db_type//' | tr -d " ,'" | sed 's/://')
db_host=$(grep db_host "${config_file}" | sed 's/db_host//' | tr -d " ,'" | sed 's/://')
db_port=$(grep db_port "${config_file}" | sed 's/db_port//' | tr -d " ,'" | sed 's/://')
echo " ${db_type}, ${db_host}, ${db_port}"
else
echo " Without Cypress configuration file"
fi
echo " /joomla-${instance}: $(du -ms "joomla-${instance}" | awk '{print $1}')MB"
docker exec "jbt-${instance}" bash -c "JBT_INTERNAL=42 /jbt/scripts/repos.sh \"joomla-${instance}\""
else
echo " /joomla-${instance} is NOT existing"
fi
fi
done