33# set -e: exit asap if a command exits with a non-zero status
44set -e
55
6- echoerr () { printf " %s\n" " $* " >&3 ; }
6+ echoerr () { printf " %s\n" " $* " >&2 ; }
77
88# print error and exit
99die () {
@@ -18,13 +18,34 @@ if [ -f /var/run/secrets/kubernetes.io/serviceaccount/token ]; then
1818 export USE_KUBERNETES=true
1919fi
2020
21+ # Let's stop using sudo in K8s environments
22+ if [ " ${REMOVE_SELUSER_FROM_SUDOERS_FOR_TESTING} " == " true" ]; then
23+ # This doesn't seem to work unless you logout:
24+ # sudo gpasswd -d seluser sudo
25+ sudo rm $( which sudo)
26+ if sudo pwd > /dev/null 2>&1 ; then
27+ die " Somehow we still have sudo access despite having removed it. Quitting. $( sudo pwd) "
28+ fi
29+ fi
30+
31+ # Flag to know if we have sudo acess
32+ if sudo pwd > /dev/null 2>&1 ; then
33+ export WE_HAVE_SUDO_ACCESS=" true"
34+ else
35+ export WE_HAVE_SUDO_ACCESS=" false"
36+ fi
37+
2138# ==============================================
2239# Java blocks until kernel have enough entropy
2340# to generate the /dev/random seed
2441# ==============================================
2542# See: SeleniumHQ/docker-selenium/issues/14
2643# Added a non-sudo conditional so this works on non-sudo environments like K8s
27- (sudo haveged) || haveged
44+ if [ " ${WE_HAVE_SUDO_ACCESS} " == " true" ]; then
45+ sudo haveged
46+ else
47+ haveged || true
48+ fi
2849
2950# Workaround that might help to get dbus working in docker
3051# http://stackoverflow.com/a/38355729/511069
3354# - this works generates errors: DBUS_SESSION_BUS_ADDRESS="/dev/null"
3455# - this gives less erros: DBUS_SESSION_BUS_ADDRESS="unix:abstract=/dev/null"
3556# Added a non-sudo conditional so this works on non-sudo environments like K8s
36- (sudo rm -f /var/lib/dbus/machine-id) || (rm -f /var/lib/dbus/machine-id) || true
37- (sudo mkdir -p /var/run/dbus) || (mkdir -p /var/run/dbus) || true
38- (sudo service dbus restart > dbus_service.log) || (service dbus restart > dbus_service.log) || true
39- # Test dbus works
40- (service dbus status > dbus_service_status.log) || true
41- export $( dbus-launch) || true
42- export NSS_USE_SHARED_DB=ENABLED
43- # echo "-- INFO: DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"
44- # => e.g. DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-APZO4BE4TJ,guid=6e9c098d053d3038cb0756ae57ecc885
45- # echo "-- INFO: DBUS_SESSION_BUS_PID=${DBUS_SESSION_BUS_PID}"
46- # => e.g. DBUS_SESSION_BUS_PID=44
47- #
57+ if [ " ${WE_HAVE_SUDO_ACCESS} " == " true" ]; then
58+ sudo rm -f /var/lib/dbus/machine-id
59+ sudo mkdir -p /var/run/dbus
60+ sudo service dbus restart > dbus_service.log
61+
62+ # Test dbus works
63+ service dbus status > dbus_service_status.log
64+ export $( dbus-launch)
65+ export NSS_USE_SHARED_DB=ENABLED
66+ # echo "-- INFO: DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"
67+ # => e.g. DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-APZO4BE4TJ,guid=6e9c098d053d3038cb0756ae57ecc885
68+ # echo "-- INFO: DBUS_SESSION_BUS_PID=${DBUS_SESSION_BUS_PID}"
69+ # => e.g. DBUS_SESSION_BUS_PID=44
70+ fi
71+
4872# -----------------------------------------------
4973# Perform cleanup to support `docker restart`
5074stop > /dev/null 2>&1 || true
@@ -194,6 +218,10 @@ elif [ "${PICK_ALL_RANDOM_PORTS}" = "true" ]; then
194218 fi
195219fi
196220
221+ if [ " ${SELENIUM_NODE_CH_PORT} " == " " ]; then
222+ die " SELENIUM_NODE_CH_PORT is empty"
223+ fi
224+
197225if [ " ${SELENIUM_NODE_FF_PORT} " = " 0" ]; then
198226 export SELENIUM_NODE_FF_PORT=$( get_unused_port_from_range ${RANDOM_PORT_FROM} ${RANDOM_PORT_TO} )
199227elif [ " ${PICK_ALL_RANDOM_PORTS} " = " true" ]; then
@@ -203,6 +231,10 @@ elif [ "${PICK_ALL_RANDOM_PORTS}" = "true" ]; then
203231 fi
204232fi
205233
234+ if [ " ${SELENIUM_NODE_FF_PORT} " == " " ]; then
235+ die " SELENIUM_NODE_FF_PORT is empty"
236+ fi
237+
206238if [ " ${SELENIUM_MULTINODE_PORT} " = " 0" ]; then
207239 export SELENIUM_MULTINODE_PORT=$( get_unused_port_from_range ${RANDOM_PORT_FROM} ${RANDOM_PORT_TO} )
208240elif [ " ${PICK_ALL_RANDOM_PORTS} " = " true" ]; then
287319
288320# -ge # greater than or equal
289321if [ " ${SELENIUM_NODE_CH_PORT} " -ge " 40000" ] && \
290- [ " ${SELENIUM_NODE_CH_PORT} " != " ${DEFAULT_SELENIUM_NODE_CH_PORT} " ]; then
322+ [ " ${SELENIUM_NODE_CH_PORT} " != " ${DEFAULT_SELENIUM_NODE_CH_PORT} " ]; then
291323 SELENIUM_FIRST_NODE_PORT=${SELENIUM_NODE_CH_PORT}
292324fi
293325
294- if [ " ${SELENIUM_NODE_FF_PORT} " -ge " 40000" ] && \
295- [ " ${SELENIUM_NODE_FF_PORT} " != " ${DEFAULT_SELENIUM_NODE_FF_PORT} " ]; then
326+ if [ " ${SELENIUM_NODE_FF_PORT} " -ge " 40000" ]; then
327+ if [ " ${SELENIUM_NODE_FF_PORT} " != " ${DEFAULT_SELENIUM_NODE_FF_PORT} " ]; then
296328 export SELENIUM_FIRST_NODE_PORT=${SELENIUM_NODE_FF_PORT}
329+ fi
297330fi
298331
299332if [ " ${SELENIUM_MULTINODE_PORT} " -ge " 40000" ] && \
300- [ " ${SELENIUM_MULTINODE_PORT} " != " ${DEFAULT_SELENIUM_MULTINODE_PORT} " ]; then
333+ [ " ${SELENIUM_MULTINODE_PORT} " != " ${DEFAULT_SELENIUM_MULTINODE_PORT} " ]; then
301334 export SELENIUM_FIRST_NODE_PORT=${SELENIUM_MULTINODE_PORT}
302335fi
303336
@@ -366,21 +399,21 @@ ga_track_start () {
366399
367400# --------------------------------
368401# Improve etc/hosts and fix dirs
369- if [ " ${USE_KUBERNETES } " == " false " ]; then
402+ if [ " ${WE_HAVE_SUDO_ACCESS } " == " true " ]; then
370403 sudo improve_etc_hosts.sh
371404fi
372405
373406# -------------------------
374407# Docker alongside docker
375- if [ " ${USE_KUBERNETES } " == " false " ]; then
408+ if [ " ${WE_HAVE_SUDO_ACCESS } " == " true " ]; then
376409 docker_alongside_docker.sh
377410fi
378411
379412# -------------------------------
380413# Fix small tiny 64mb shm issue
381414# -------------------------------
382415# https://github.com/elgalu/docker-selenium/issues/20
383- if [ " ${SHM_TRY_MOUNT_UNMOUNT} " = " true" ] && [ " ${USE_KUBERNETES } " == " false " ]; then
416+ if [ " ${SHM_TRY_MOUNT_UNMOUNT} " = " true" ] && [ " ${WE_HAVE_SUDO_ACCESS } " == " true " ]; then
384417 sudo umount /dev/shm || true
385418 sudo mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=${SHM_SIZE} \
386419 tmpfs /dev/shm || true
0 commit comments