Skip to content

Commit 59397b1

Browse files
committed
build: apply rule to format shell script
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 1d8a35c commit 59397b1

37 files changed

+561
-591
lines changed

.github/workflows/docker-test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ jobs:
7878
large-packages: false
7979
- name: Checkout code
8080
uses: actions/checkout@main
81+
- name: Format and lint scripts
82+
run: |
83+
make format_shell_scripts
8184
- name: Set up containerd image store feature
8285
uses: nick-invision/retry@master
8386
with:

Base/check-grid.sh

+15-16
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ PORT="4444"
99
echoerr() { echo "$@" 1>&2; }
1010

1111
# process arguments
12-
while [[ $# -gt 0 ]]
13-
do
14-
case "$1" in
15-
--host)
16-
HOST=${2:-"localhost"}
17-
shift 2
18-
;;
19-
--port)
20-
PORT=${2:-"4444"}
21-
shift 2
22-
;;
23-
*)
24-
echoerr "Unknown argument: $1"
25-
exit 1
26-
;;
27-
esac
12+
while [[ $# -gt 0 ]]; do
13+
case "$1" in
14+
--host)
15+
HOST=${2:-"localhost"}
16+
shift 2
17+
;;
18+
--port)
19+
PORT=${2:-"4444"}
20+
shift 2
21+
;;
22+
*)
23+
echoerr "Unknown argument: $1"
24+
exit 1
25+
;;
26+
esac
2827
done
2928

3029
curl -skSL ${SE_SERVER_PROTOCOL:-"http"}://${HOST}:${PORT}/wd/hub/status | jq -r '.value.ready' | grep -q "true" || exit 1

Base/entry_point.sh

+15-15
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ NODE_CONFIG_DIRECTORY=${NODE_CONFIG_DIRECTORY:-"/opt/bin"}
66
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines
77
#==============================================
88

9-
if ! whoami &> /dev/null; then
9+
if ! whoami &>/dev/null; then
1010
if [ -w /etc/passwd ]; then
11-
echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd
11+
echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >>/etc/passwd
1212
fi
1313
fi
1414

@@ -17,19 +17,19 @@ fi
1717
SUPERVISOR_PID=$!
1818

1919
function shutdown {
20-
echo "Trapped SIGTERM/SIGINT/x so shutting down supervisord..."
21-
if [ "${SE_NODE_GRACEFUL_SHUTDOWN}" = "true" ]; then
22-
echo "Waiting for Selenium Node to shutdown gracefully..."
23-
bash ${NODE_CONFIG_DIRECTORY}/nodePreStop.sh
24-
fi
25-
if [ -n "${SE_VIDEO_CONTAINER_NAME}" ]; then
26-
# For K8s, when video sidecar container and shareProcessNamespace are enabled in pod spec
27-
echo "Shutting down ${SE_VIDEO_CONTAINER_NAME} container..."
28-
pkill -f "${SE_VIDEO_CONTAINER_NAME}"
29-
fi
30-
kill -s SIGTERM ${SUPERVISOR_PID}
31-
wait ${SUPERVISOR_PID}
32-
echo "Shutdown complete"
20+
echo "Trapped SIGTERM/SIGINT/x so shutting down supervisord..."
21+
if [ "${SE_NODE_GRACEFUL_SHUTDOWN}" = "true" ]; then
22+
echo "Waiting for Selenium Node to shutdown gracefully..."
23+
bash ${NODE_CONFIG_DIRECTORY}/nodePreStop.sh
24+
fi
25+
if [ -n "${SE_VIDEO_CONTAINER_NAME}" ]; then
26+
# For K8s, when video sidecar container and shareProcessNamespace are enabled in pod spec
27+
echo "Shutting down ${SE_VIDEO_CONTAINER_NAME} container..."
28+
pkill -f "${SE_VIDEO_CONTAINER_NAME}"
29+
fi
30+
kill -s SIGTERM ${SUPERVISOR_PID}
31+
wait ${SUPERVISOR_PID}
32+
echo "Shutdown complete"
3333
}
3434

3535
trap shutdown SIGTERM SIGINT

Distributor/start-selenium-grid-distributor.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ function append_se_opts() {
1111
local log_message="${3:-true}"
1212
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
1313
if [ "${log_message}" = "true" ]; then
14-
echo "Appending Selenium option: ${option} ${value}"
14+
echo "Appending Selenium option: ${option} ${value}"
1515
else
16-
echo "Appending Selenium option: ${option} $(mask ${value})"
16+
echo "Appending Selenium option: ${option} $(mask ${value})"
1717
fi
1818
SE_OPTS="${SE_OPTS} ${option}"
1919
if [ ! -z "${value}" ]; then
20-
SE_OPTS="${SE_OPTS} ${value}"
20+
SE_OPTS="${SE_OPTS} ${value}"
2121
fi
2222
else
2323
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"

EventBus/start-selenium-grid-eventbus.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ function append_se_opts() {
1111
local log_message="${3:-true}"
1212
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
1313
if [ "${log_message}" = "true" ]; then
14-
echo "Appending Selenium option: ${option} ${value}"
14+
echo "Appending Selenium option: ${option} ${value}"
1515
else
16-
echo "Appending Selenium option: ${option} $(mask ${value})"
16+
echo "Appending Selenium option: ${option} $(mask ${value})"
1717
fi
1818
SE_OPTS="${SE_OPTS} ${option}"
1919
if [ ! -z "${value}" ]; then
20-
SE_OPTS="${SE_OPTS} ${value}"
20+
SE_OPTS="${SE_OPTS} ${value}"
2121
fi
2222
else
2323
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"

Hub/start-selenium-grid-hub.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ function append_se_opts() {
1111
local log_message="${3:-true}"
1212
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
1313
if [ "${log_message}" = "true" ]; then
14-
echo "Appending Selenium option: ${option} ${value}"
14+
echo "Appending Selenium option: ${option} ${value}"
1515
else
16-
echo "Appending Selenium option: ${option} $(mask ${value})"
16+
echo "Appending Selenium option: ${option} $(mask ${value})"
1717
fi
1818
SE_OPTS="${SE_OPTS} ${option}"
1919
if [ ! -z "${value}" ]; then
20-
SE_OPTS="${SE_OPTS} ${value}"
20+
SE_OPTS="${SE_OPTS} ${value}"
2121
fi
2222
else
2323
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ set_containerd_image_store:
5151
docker version -f '{{.Server.Experimental}}'
5252
docker info -f '{{ .DriverStatus }}'
5353

54+
format_shell_scripts:
55+
sudo apt-get update -qq ; \
56+
sudo apt-get install -yq shfmt ; \
57+
shfmt -l -w -d $${PWD}/*.sh $${PWD}/**/*.sh $$PWD/**.sh $$PWD/**/generate_** $$PWD/**/wrap_* ; \
58+
git diff --stat --exit-code ; \
59+
EXIT_CODE=$$? ; \
60+
if [ $$EXIT_CODE -ne 0 ]; then \
61+
echo "Some shell scripts are not formatted. Please run 'make format_shell_scripts' to format and update them." ; \
62+
exit 1 ; \
63+
fi ; \
64+
exit $$EXIT_CODE
65+
5466
set_build_nightly:
5567
echo BASE_VERSION=$(BASE_VERSION_NIGHTLY) > .env ; \
5668
echo BASE_RELEASE=$(BASE_RELEASE_NIGHTLY) >> .env ;

NodeBase/generate_config

+32-34
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,79 @@
11
#!/bin/bash
22

33
function short_version() {
4-
local __long_version=$1
5-
local __version_split=( ${__long_version//./ } )
6-
local __major=${__version_split[0]}
7-
local __minor=${__version_split[1]}
8-
echo "${__major}.${__minor:0:1}"
4+
local __long_version=$1
5+
local __version_split=(${__long_version//./ })
6+
local __major=${__version_split[0]}
7+
local __minor=${__version_split[1]}
8+
echo "${__major}.${__minor:0:1}"
99
}
1010

1111
if [[ -z "$CONFIG_FILE" ]]; then
12-
FILENAME="/opt/selenium/config.toml"
12+
FILENAME="/opt/selenium/config.toml"
1313
else
14-
FILENAME="$CONFIG_FILE"
14+
FILENAME="$CONFIG_FILE"
1515
fi
1616

1717
echo "[events]
1818
publish = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_PUBLISH_PORT}\"
1919
subscribe = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_SUBSCRIBE_PORT}\"
20-
" > "$FILENAME"
20+
" >"$FILENAME"
2121

2222
if [[ -z "${SE_NODE_HOST}" ]] && [[ -z "${SE_NODE_PORT}" ]]; then
23-
echo "Configuring server..."
23+
echo "Configuring server..."
2424
else
25-
echo "[server]" >> "$FILENAME"
25+
echo "[server]" >>"$FILENAME"
2626
fi
2727

2828
if [[ -z "${SE_NODE_HOST}" ]]; then
29-
echo "Setting up SE_NODE_HOST..."
29+
echo "Setting up SE_NODE_HOST..."
3030
else
31-
echo "host = \"${SE_NODE_HOST}\"" >> "$FILENAME"
31+
echo "host = \"${SE_NODE_HOST}\"" >>"$FILENAME"
3232
fi
3333

3434
if [[ -z "${SE_NODE_PORT}" ]]; then
35-
echo "Setting up SE_NODE_PORT..."
35+
echo "Setting up SE_NODE_PORT..."
3636
else
37-
echo "port = \"${SE_NODE_PORT}\"" >> "$FILENAME"
37+
echo "port = \"${SE_NODE_PORT}\"" >>"$FILENAME"
3838
fi
3939

40-
echo "[node]" >> "$FILENAME"
40+
echo "[node]" >>"$FILENAME"
4141
# String, Url where the Grid can be reached
4242
if [[ -z "${SE_NODE_GRID_URL}" ]]; then
43-
echo "Setting up SE_NODE_GRID_URL..."
43+
echo "Setting up SE_NODE_GRID_URL..."
4444
else
45-
echo "grid-url = \"${SE_NODE_GRID_URL}\"" >> "$FILENAME"
45+
echo "grid-url = \"${SE_NODE_GRID_URL}\"" >>"$FILENAME"
4646
fi
47-
echo "session-timeout = \"${SE_NODE_SESSION_TIMEOUT}\"" >> "$FILENAME"
48-
echo "override-max-sessions = ${SE_NODE_OVERRIDE_MAX_SESSIONS}" >> "$FILENAME"
49-
echo "detect-drivers = false" >> "$FILENAME"
50-
echo "drain-after-session-count = ${DRAIN_AFTER_SESSION_COUNT:-$SE_DRAIN_AFTER_SESSION_COUNT}" >> "$FILENAME"
47+
echo "session-timeout = \"${SE_NODE_SESSION_TIMEOUT}\"" >>"$FILENAME"
48+
echo "override-max-sessions = ${SE_NODE_OVERRIDE_MAX_SESSIONS}" >>"$FILENAME"
49+
echo "detect-drivers = false" >>"$FILENAME"
50+
echo "drain-after-session-count = ${DRAIN_AFTER_SESSION_COUNT:-$SE_DRAIN_AFTER_SESSION_COUNT}" >>"$FILENAME"
5151
# When node is handled both browser and relay, SE_NODE_MAX_CONCURRENCY is used to configure max concurrency based on sum of them
5252
echo "max-sessions = ${SE_NODE_MAX_CONCURRENCY:-${SE_NODE_MAX_SESSIONS}}
53-
" >> "$FILENAME"
53+
" >>"$FILENAME"
5454

5555
if [ -f /opt/selenium/browser_name ]; then
56-
SE_NODE_BROWSER_NAME=$(cat /opt/selenium/browser_name)
56+
SE_NODE_BROWSER_NAME=$(cat /opt/selenium/browser_name)
5757
fi
5858
if [ -f /opt/selenium/browser_version ]; then
59-
SE_NODE_BROWSER_VERSION=$(short_version $(cat /opt/selenium/browser_version))
59+
SE_NODE_BROWSER_VERSION=$(short_version $(cat /opt/selenium/browser_version))
6060
fi
6161
if [ -f /opt/selenium/browser_binary_location ]; then
62-
SE__BROWSER_BINARY_LOCATION=$(cat /opt/selenium/browser_binary_location)
62+
SE__BROWSER_BINARY_LOCATION=$(cat /opt/selenium/browser_binary_location)
6363
fi
6464

6565
# 'browserName' is mandatory for default stereotype
6666
if [[ -z "${SE_NODE_STEREOTYPE}" ]] && [[ -n "${SE_NODE_BROWSER_NAME}" ]]; then
67-
SE_NODE_STEREOTYPE="{\"browserName\": \"${SE_NODE_BROWSER_NAME}\", \"browserVersion\": \"${SE_NODE_BROWSER_VERSION}\", \"platformName\": \"Linux\", ${SE__BROWSER_BINARY_LOCATION}, \"se:containerName\": \"${SE_NODE_CONTAINER_NAME}\"}"
67+
SE_NODE_STEREOTYPE="{\"browserName\": \"${SE_NODE_BROWSER_NAME}\", \"browserVersion\": \"${SE_NODE_BROWSER_VERSION}\", \"platformName\": \"Linux\", ${SE__BROWSER_BINARY_LOCATION}, \"se:containerName\": \"${SE_NODE_CONTAINER_NAME}\"}"
6868
else
69-
SE_NODE_STEREOTYPE="${SE_NODE_STEREOTYPE}"
69+
SE_NODE_STEREOTYPE="${SE_NODE_STEREOTYPE}"
7070
fi
7171

7272
# 'stereotype' setting is mandatory
7373
if [[ -n "${SE_NODE_STEREOTYPE}" ]]; then
74-
echo "[[node.driver-configuration]]" >> "$FILENAME"
75-
echo "display-name = \"${SE_NODE_BROWSER_NAME}\"" >> "$FILENAME"
76-
echo "stereotype = '${SE_NODE_STEREOTYPE}'" >> "$FILENAME"
77-
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
78-
" >> "$FILENAME"
74+
echo "[[node.driver-configuration]]" >>"$FILENAME"
75+
echo "display-name = \"${SE_NODE_BROWSER_NAME}\"" >>"$FILENAME"
76+
echo "stereotype = '${SE_NODE_STEREOTYPE}'" >>"$FILENAME"
77+
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
78+
" >>"$FILENAME"
7979
fi
80-
81-

NodeBase/generate_relay_config

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#!/bin/bash
22

33
if [[ -z "$CONFIG_FILE" ]]; then
4-
FILENAME="/opt/selenium/config.toml"
4+
FILENAME="/opt/selenium/config.toml"
55
else
6-
FILENAME="$CONFIG_FILE"
6+
FILENAME="$CONFIG_FILE"
77
fi
88

99
if [[ -n "${SE_NODE_RELAY_URL}" ]]; then
10-
echo "[relay]" >> "$FILENAME"
11-
echo "url = \"${SE_NODE_RELAY_URL}\"" >> "$FILENAME"
12-
if [[ -z "${SE_NODE_RELAY_STATUS_ENDPOINT}" ]]; then
13-
echo "status-endpoint = \"/status\"" >> "$FILENAME"
14-
else
15-
echo "status-endpoint = \"${SE_NODE_RELAY_STATUS_ENDPOINT}\"" >> "$FILENAME"
16-
fi
17-
if [[ -n "${SE_NODE_RELAY_PROTOCOL_VERSION}" ]]; then
18-
echo "protocol-version = \"${SE_NODE_RELAY_PROTOCOL_VERSION}\"" >> "$FILENAME"
19-
fi
20-
echo "configs = [
10+
echo "[relay]" >>"$FILENAME"
11+
echo "url = \"${SE_NODE_RELAY_URL}\"" >>"$FILENAME"
12+
if [[ -z "${SE_NODE_RELAY_STATUS_ENDPOINT}" ]]; then
13+
echo "status-endpoint = \"/status\"" >>"$FILENAME"
14+
else
15+
echo "status-endpoint = \"${SE_NODE_RELAY_STATUS_ENDPOINT}\"" >>"$FILENAME"
16+
fi
17+
if [[ -n "${SE_NODE_RELAY_PROTOCOL_VERSION}" ]]; then
18+
echo "protocol-version = \"${SE_NODE_RELAY_PROTOCOL_VERSION}\"" >>"$FILENAME"
19+
fi
20+
echo "configs = [
2121
\"${SE_NODE_RELAY_MAX_SESSIONS}\", \"{\\\"browserName\\\": \\\"${SE_NODE_RELAY_BROWSER_NAME}\\\", \\\"platformName\\\": \\\"${SE_NODE_RELAY_PLATFORM_NAME}\\\", \\\"appium:platformVersion\\\": \\\"${SE_NODE_RELAY_PLATFORM_VERSION}\\\"}\"
2222
]
23-
" >> "$FILENAME"
23+
" >>"$FILENAME"
2424
fi

NodeBase/start-novnc.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#
33
# IMPORTANT: Change this file only in directory NodeBase!
44

5-
if [ "${START_XVFB:-$SE_START_XVFB}" = true ] ; then
6-
if [ "${START_VNC:-$SE_START_VNC}" = true ] ; then
7-
if [ "${START_NO_VNC:-$SE_START_NO_VNC}" = true ] ; then
5+
if [ "${START_XVFB:-$SE_START_XVFB}" = true ]; then
6+
if [ "${START_VNC:-$SE_START_VNC}" = true ]; then
7+
if [ "${START_NO_VNC:-$SE_START_NO_VNC}" = true ]; then
88

99
# Guard against unreasonably high nofile limits. See https://github.com/SeleniumHQ/docker-selenium/issues/2045
1010
# Try to set a new limit if the current limit is too high, or the user explicitly specified a custom limit

NodeBase/start-selenium-node.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ function append_se_opts() {
1818
local log_message="${3:-true}"
1919
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
2020
if [ "${log_message}" = "true" ]; then
21-
echo "Appending Selenium option: ${option} ${value}"
21+
echo "Appending Selenium option: ${option} ${value}"
2222
else
23-
echo "Appending Selenium option: ${option} $(mask ${value})"
23+
echo "Appending Selenium option: ${option} $(mask ${value})"
2424
fi
2525
SE_OPTS="${SE_OPTS} ${option}"
2626
if [ ! -z "${value}" ]; then
27-
SE_OPTS="${SE_OPTS} ${value}"
27+
SE_OPTS="${SE_OPTS} ${value}"
2828
fi
2929
else
3030
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"

NodeBase/start-vnc.sh

+11-13
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@
22
#
33
# IMPORTANT: Change this file only in directory NodeBase!
44

5-
if [ "${START_XVFB:-$SE_START_XVFB}" = true ] ; then
6-
if [ "${START_VNC:-$SE_START_VNC}" = true ] ; then
5+
if [ "${START_XVFB:-$SE_START_XVFB}" = true ]; then
6+
if [ "${START_VNC:-$SE_START_VNC}" = true ]; then
77
# Centering wallpaper
8-
for i in $(seq 1 10)
9-
do
8+
for i in $(seq 1 10); do
109
sleep 0.5
1110
echo "Centering wallpaper"
1211
/usr/bin/fbsetbg -u Esetroot -c /usr/share/images/fluxbox/ubuntu-light.png
1312
if [ $? -eq 0 ]; then
1413
break
15-
fi
16-
done
14+
fi
15+
done
1716
VNC_NO_PASSWORD=${VNC_NO_PASSWORD:-$SE_VNC_NO_PASSWORD}
1817
if [ ! -z $VNC_NO_PASSWORD ]; then
19-
echo "Starting VNC server without password authentication"
20-
X11VNC_OPTS=
18+
echo "Starting VNC server without password authentication"
19+
X11VNC_OPTS=
2120
else
22-
X11VNC_OPTS=-usepw
21+
X11VNC_OPTS=-usepw
2322
fi
2423

2524
VNC_VIEW_ONLY=${VNC_VIEW_ONLY:-$SE_VNC_VIEW_ONLY}
2625
if [ ! -z $VNC_VIEW_ONLY ]; then
27-
echo "Starting VNC server with viewonly option"
28-
X11VNC_OPTS="${X11VNC_OPTS} -viewonly"
26+
echo "Starting VNC server with viewonly option"
27+
X11VNC_OPTS="${X11VNC_OPTS} -viewonly"
2928
fi
3029

3130
VNC_PASSWORD=${VNC_PASSWORD:-$SE_VNC_PASSWORD}
@@ -34,8 +33,7 @@ if [ "${START_XVFB:-$SE_START_XVFB}" = true ] ; then
3433
x11vnc -storepasswd ${VNC_PASSWORD} ${HOME}/.vnc/passwd
3534
fi
3635

37-
for i in $(seq 1 10)
38-
do
36+
for i in $(seq 1 10); do
3937
sleep 1
4038
xdpyinfo -display ${DISPLAY} >/dev/null 2>&1
4139
if [ $? -eq 0 ]; then

0 commit comments

Comments
 (0)