Skip to content

Commit

Permalink
build: apply rule to format shell script
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Aug 29, 2024
1 parent 1d8a35c commit 59397b1
Show file tree
Hide file tree
Showing 37 changed files with 561 additions and 591 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ jobs:
large-packages: false
- name: Checkout code
uses: actions/checkout@main
- name: Format and lint scripts
run: |
make format_shell_scripts
- name: Set up containerd image store feature
uses: nick-invision/retry@master
with:
Expand Down
31 changes: 15 additions & 16 deletions Base/check-grid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ PORT="4444"
echoerr() { echo "$@" 1>&2; }

# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
--host)
HOST=${2:-"localhost"}
shift 2
;;
--port)
PORT=${2:-"4444"}
shift 2
;;
*)
echoerr "Unknown argument: $1"
exit 1
;;
esac
while [[ $# -gt 0 ]]; do
case "$1" in
--host)
HOST=${2:-"localhost"}
shift 2
;;
--port)
PORT=${2:-"4444"}
shift 2
;;
*)
echoerr "Unknown argument: $1"
exit 1
;;
esac
done

curl -skSL ${SE_SERVER_PROTOCOL:-"http"}://${HOST}:${PORT}/wd/hub/status | jq -r '.value.ready' | grep -q "true" || exit 1
30 changes: 15 additions & 15 deletions Base/entry_point.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ NODE_CONFIG_DIRECTORY=${NODE_CONFIG_DIRECTORY:-"/opt/bin"}
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines
#==============================================

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

Expand All @@ -17,19 +17,19 @@ fi
SUPERVISOR_PID=$!

function shutdown {
echo "Trapped SIGTERM/SIGINT/x so shutting down supervisord..."
if [ "${SE_NODE_GRACEFUL_SHUTDOWN}" = "true" ]; then
echo "Waiting for Selenium Node to shutdown gracefully..."
bash ${NODE_CONFIG_DIRECTORY}/nodePreStop.sh
fi
if [ -n "${SE_VIDEO_CONTAINER_NAME}" ]; then
# For K8s, when video sidecar container and shareProcessNamespace are enabled in pod spec
echo "Shutting down ${SE_VIDEO_CONTAINER_NAME} container..."
pkill -f "${SE_VIDEO_CONTAINER_NAME}"
fi
kill -s SIGTERM ${SUPERVISOR_PID}
wait ${SUPERVISOR_PID}
echo "Shutdown complete"
echo "Trapped SIGTERM/SIGINT/x so shutting down supervisord..."
if [ "${SE_NODE_GRACEFUL_SHUTDOWN}" = "true" ]; then
echo "Waiting for Selenium Node to shutdown gracefully..."
bash ${NODE_CONFIG_DIRECTORY}/nodePreStop.sh
fi
if [ -n "${SE_VIDEO_CONTAINER_NAME}" ]; then
# For K8s, when video sidecar container and shareProcessNamespace are enabled in pod spec
echo "Shutting down ${SE_VIDEO_CONTAINER_NAME} container..."
pkill -f "${SE_VIDEO_CONTAINER_NAME}"
fi
kill -s SIGTERM ${SUPERVISOR_PID}
wait ${SUPERVISOR_PID}
echo "Shutdown complete"
}

trap shutdown SIGTERM SIGINT
Expand Down
6 changes: 3 additions & 3 deletions Distributor/start-selenium-grid-distributor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ function append_se_opts() {
local log_message="${3:-true}"
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
if [ "${log_message}" = "true" ]; then
echo "Appending Selenium option: ${option} ${value}"
echo "Appending Selenium option: ${option} ${value}"
else
echo "Appending Selenium option: ${option} $(mask ${value})"
echo "Appending Selenium option: ${option} $(mask ${value})"
fi
SE_OPTS="${SE_OPTS} ${option}"
if [ ! -z "${value}" ]; then
SE_OPTS="${SE_OPTS} ${value}"
SE_OPTS="${SE_OPTS} ${value}"
fi
else
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"
Expand Down
6 changes: 3 additions & 3 deletions EventBus/start-selenium-grid-eventbus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ function append_se_opts() {
local log_message="${3:-true}"
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
if [ "${log_message}" = "true" ]; then
echo "Appending Selenium option: ${option} ${value}"
echo "Appending Selenium option: ${option} ${value}"
else
echo "Appending Selenium option: ${option} $(mask ${value})"
echo "Appending Selenium option: ${option} $(mask ${value})"
fi
SE_OPTS="${SE_OPTS} ${option}"
if [ ! -z "${value}" ]; then
SE_OPTS="${SE_OPTS} ${value}"
SE_OPTS="${SE_OPTS} ${value}"
fi
else
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"
Expand Down
6 changes: 3 additions & 3 deletions Hub/start-selenium-grid-hub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ function append_se_opts() {
local log_message="${3:-true}"
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
if [ "${log_message}" = "true" ]; then
echo "Appending Selenium option: ${option} ${value}"
echo "Appending Selenium option: ${option} ${value}"
else
echo "Appending Selenium option: ${option} $(mask ${value})"
echo "Appending Selenium option: ${option} $(mask ${value})"
fi
SE_OPTS="${SE_OPTS} ${option}"
if [ ! -z "${value}" ]; then
SE_OPTS="${SE_OPTS} ${value}"
SE_OPTS="${SE_OPTS} ${value}"
fi
else
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ set_containerd_image_store:
docker version -f '{{.Server.Experimental}}'
docker info -f '{{ .DriverStatus }}'

format_shell_scripts:
sudo apt-get update -qq ; \
sudo apt-get install -yq shfmt ; \
shfmt -l -w -d $${PWD}/*.sh $${PWD}/**/*.sh $$PWD/**.sh $$PWD/**/generate_** $$PWD/**/wrap_* ; \
git diff --stat --exit-code ; \
EXIT_CODE=$$? ; \
if [ $$EXIT_CODE -ne 0 ]; then \
echo "Some shell scripts are not formatted. Please run 'make format_shell_scripts' to format and update them." ; \
exit 1 ; \
fi ; \
exit $$EXIT_CODE

set_build_nightly:
echo BASE_VERSION=$(BASE_VERSION_NIGHTLY) > .env ; \
echo BASE_RELEASE=$(BASE_RELEASE_NIGHTLY) >> .env ;
Expand Down
66 changes: 32 additions & 34 deletions NodeBase/generate_config
Original file line number Diff line number Diff line change
@@ -1,81 +1,79 @@
#!/bin/bash

function short_version() {
local __long_version=$1
local __version_split=( ${__long_version//./ } )
local __major=${__version_split[0]}
local __minor=${__version_split[1]}
echo "${__major}.${__minor:0:1}"
local __long_version=$1
local __version_split=(${__long_version//./ })
local __major=${__version_split[0]}
local __minor=${__version_split[1]}
echo "${__major}.${__minor:0:1}"
}

if [[ -z "$CONFIG_FILE" ]]; then
FILENAME="/opt/selenium/config.toml"
FILENAME="/opt/selenium/config.toml"
else
FILENAME="$CONFIG_FILE"
FILENAME="$CONFIG_FILE"
fi

echo "[events]
publish = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_PUBLISH_PORT}\"
subscribe = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_SUBSCRIBE_PORT}\"
" > "$FILENAME"
" >"$FILENAME"

if [[ -z "${SE_NODE_HOST}" ]] && [[ -z "${SE_NODE_PORT}" ]]; then
echo "Configuring server..."
echo "Configuring server..."
else
echo "[server]" >> "$FILENAME"
echo "[server]" >>"$FILENAME"
fi

if [[ -z "${SE_NODE_HOST}" ]]; then
echo "Setting up SE_NODE_HOST..."
echo "Setting up SE_NODE_HOST..."
else
echo "host = \"${SE_NODE_HOST}\"" >> "$FILENAME"
echo "host = \"${SE_NODE_HOST}\"" >>"$FILENAME"
fi

if [[ -z "${SE_NODE_PORT}" ]]; then
echo "Setting up SE_NODE_PORT..."
echo "Setting up SE_NODE_PORT..."
else
echo "port = \"${SE_NODE_PORT}\"" >> "$FILENAME"
echo "port = \"${SE_NODE_PORT}\"" >>"$FILENAME"
fi

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

if [ -f /opt/selenium/browser_name ]; then
SE_NODE_BROWSER_NAME=$(cat /opt/selenium/browser_name)
SE_NODE_BROWSER_NAME=$(cat /opt/selenium/browser_name)
fi
if [ -f /opt/selenium/browser_version ]; then
SE_NODE_BROWSER_VERSION=$(short_version $(cat /opt/selenium/browser_version))
SE_NODE_BROWSER_VERSION=$(short_version $(cat /opt/selenium/browser_version))
fi
if [ -f /opt/selenium/browser_binary_location ]; then
SE__BROWSER_BINARY_LOCATION=$(cat /opt/selenium/browser_binary_location)
SE__BROWSER_BINARY_LOCATION=$(cat /opt/selenium/browser_binary_location)
fi

# 'browserName' is mandatory for default stereotype
if [[ -z "${SE_NODE_STEREOTYPE}" ]] && [[ -n "${SE_NODE_BROWSER_NAME}" ]]; then
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}\"}"
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}\"}"
else
SE_NODE_STEREOTYPE="${SE_NODE_STEREOTYPE}"
SE_NODE_STEREOTYPE="${SE_NODE_STEREOTYPE}"
fi

# 'stereotype' setting is mandatory
if [[ -n "${SE_NODE_STEREOTYPE}" ]]; then
echo "[[node.driver-configuration]]" >> "$FILENAME"
echo "display-name = \"${SE_NODE_BROWSER_NAME}\"" >> "$FILENAME"
echo "stereotype = '${SE_NODE_STEREOTYPE}'" >> "$FILENAME"
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
" >> "$FILENAME"
echo "[[node.driver-configuration]]" >>"$FILENAME"
echo "display-name = \"${SE_NODE_BROWSER_NAME}\"" >>"$FILENAME"
echo "stereotype = '${SE_NODE_STEREOTYPE}'" >>"$FILENAME"
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
" >>"$FILENAME"
fi


28 changes: 14 additions & 14 deletions NodeBase/generate_relay_config
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/bin/bash

if [[ -z "$CONFIG_FILE" ]]; then
FILENAME="/opt/selenium/config.toml"
FILENAME="/opt/selenium/config.toml"
else
FILENAME="$CONFIG_FILE"
FILENAME="$CONFIG_FILE"
fi

if [[ -n "${SE_NODE_RELAY_URL}" ]]; then
echo "[relay]" >> "$FILENAME"
echo "url = \"${SE_NODE_RELAY_URL}\"" >> "$FILENAME"
if [[ -z "${SE_NODE_RELAY_STATUS_ENDPOINT}" ]]; then
echo "status-endpoint = \"/status\"" >> "$FILENAME"
else
echo "status-endpoint = \"${SE_NODE_RELAY_STATUS_ENDPOINT}\"" >> "$FILENAME"
fi
if [[ -n "${SE_NODE_RELAY_PROTOCOL_VERSION}" ]]; then
echo "protocol-version = \"${SE_NODE_RELAY_PROTOCOL_VERSION}\"" >> "$FILENAME"
fi
echo "configs = [
echo "[relay]" >>"$FILENAME"
echo "url = \"${SE_NODE_RELAY_URL}\"" >>"$FILENAME"
if [[ -z "${SE_NODE_RELAY_STATUS_ENDPOINT}" ]]; then
echo "status-endpoint = \"/status\"" >>"$FILENAME"
else
echo "status-endpoint = \"${SE_NODE_RELAY_STATUS_ENDPOINT}\"" >>"$FILENAME"
fi
if [[ -n "${SE_NODE_RELAY_PROTOCOL_VERSION}" ]]; then
echo "protocol-version = \"${SE_NODE_RELAY_PROTOCOL_VERSION}\"" >>"$FILENAME"
fi
echo "configs = [
\"${SE_NODE_RELAY_MAX_SESSIONS}\", \"{\\\"browserName\\\": \\\"${SE_NODE_RELAY_BROWSER_NAME}\\\", \\\"platformName\\\": \\\"${SE_NODE_RELAY_PLATFORM_NAME}\\\", \\\"appium:platformVersion\\\": \\\"${SE_NODE_RELAY_PLATFORM_VERSION}\\\"}\"
]
" >> "$FILENAME"
" >>"$FILENAME"
fi
6 changes: 3 additions & 3 deletions NodeBase/start-novnc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#
# IMPORTANT: Change this file only in directory NodeBase!

if [ "${START_XVFB:-$SE_START_XVFB}" = true ] ; then
if [ "${START_VNC:-$SE_START_VNC}" = true ] ; then
if [ "${START_NO_VNC:-$SE_START_NO_VNC}" = true ] ; then
if [ "${START_XVFB:-$SE_START_XVFB}" = true ]; then
if [ "${START_VNC:-$SE_START_VNC}" = true ]; then
if [ "${START_NO_VNC:-$SE_START_NO_VNC}" = true ]; then

# Guard against unreasonably high nofile limits. See https://github.com/SeleniumHQ/docker-selenium/issues/2045
# Try to set a new limit if the current limit is too high, or the user explicitly specified a custom limit
Expand Down
6 changes: 3 additions & 3 deletions NodeBase/start-selenium-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ function append_se_opts() {
local log_message="${3:-true}"
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
if [ "${log_message}" = "true" ]; then
echo "Appending Selenium option: ${option} ${value}"
echo "Appending Selenium option: ${option} ${value}"
else
echo "Appending Selenium option: ${option} $(mask ${value})"
echo "Appending Selenium option: ${option} $(mask ${value})"
fi
SE_OPTS="${SE_OPTS} ${option}"
if [ ! -z "${value}" ]; then
SE_OPTS="${SE_OPTS} ${value}"
SE_OPTS="${SE_OPTS} ${value}"
fi
else
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"
Expand Down
24 changes: 11 additions & 13 deletions NodeBase/start-vnc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@
#
# IMPORTANT: Change this file only in directory NodeBase!

if [ "${START_XVFB:-$SE_START_XVFB}" = true ] ; then
if [ "${START_VNC:-$SE_START_VNC}" = true ] ; then
if [ "${START_XVFB:-$SE_START_XVFB}" = true ]; then
if [ "${START_VNC:-$SE_START_VNC}" = true ]; then
# Centering wallpaper
for i in $(seq 1 10)
do
for i in $(seq 1 10); do
sleep 0.5
echo "Centering wallpaper"
/usr/bin/fbsetbg -u Esetroot -c /usr/share/images/fluxbox/ubuntu-light.png
if [ $? -eq 0 ]; then
break
fi
done
fi
done
VNC_NO_PASSWORD=${VNC_NO_PASSWORD:-$SE_VNC_NO_PASSWORD}
if [ ! -z $VNC_NO_PASSWORD ]; then
echo "Starting VNC server without password authentication"
X11VNC_OPTS=
echo "Starting VNC server without password authentication"
X11VNC_OPTS=
else
X11VNC_OPTS=-usepw
X11VNC_OPTS=-usepw
fi

VNC_VIEW_ONLY=${VNC_VIEW_ONLY:-$SE_VNC_VIEW_ONLY}
if [ ! -z $VNC_VIEW_ONLY ]; then
echo "Starting VNC server with viewonly option"
X11VNC_OPTS="${X11VNC_OPTS} -viewonly"
echo "Starting VNC server with viewonly option"
X11VNC_OPTS="${X11VNC_OPTS} -viewonly"
fi

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

for i in $(seq 1 10)
do
for i in $(seq 1 10); do
sleep 1
xdpyinfo -display ${DISPLAY} >/dev/null 2>&1
if [ $? -eq 0 ]; then
Expand Down
Loading

0 comments on commit 59397b1

Please sign in to comment.