Skip to content
Browse files

Add colorized output to shell scripts

  • Loading branch information...
1 parent 5c5d471 commit 6d1905a16798ffb02089607a9c85d907b474fd8e @semperos committed
Showing with 45 additions and 10 deletions.
  1. +9 −4 script/grid-hub
  2. +9 −4 script/grid-node
  3. +6 −2 script/test
  4. +21 −0 script/util
View
13 script/grid-hub
@@ -4,6 +4,8 @@
# Usage: grid-hub {start|stop}
#
+source $(dirname $0)/util
+
EXPECTED_ARGS=1
E_BADARGS=65
@@ -16,6 +18,8 @@ if [ $# -ne $EXPECTED_ARGS ]; then
DO_showUsage
fi
+################################################################################
+
WEBDRIVER_SERVER_JAR=/opt/selenium-server-standalone.jar
WEBDRIVER_HUB_PIDFILE="/tmp/webdriver_hub.pid"
@@ -28,13 +32,14 @@ case "$1" in
start)
echo "Starting Selenium-WebDriver Grid2 hub..."
if [ -f $WEBDRIVER_HUB_PIDFILE ]; then
- echo "Selenium-WebDriver Grid2 hub already running with PID $(cat $WEBDRIVER_HUB_PIDFILE). Run 'grid-hub stop' or 'grid-hub restart'."
+ echo "${FAIL_MSG} Selenium-WebDriver Grid2 hub already running with PID $(cat $WEBDRIVER_HUB_PIDFILE). Run 'grid-hub stop' or 'grid-hub restart'."
exit 1
else
START_HUB_CMD="java -jar ${WEBDRIVER_SERVER_JAR} -role hub"
$START_HUB_CMD &
PID=$!
echo $PID > "${WEBDRIVER_HUB_PIDFILE}"
+ echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 hub started successfully."
fi
;;
stop)
@@ -45,14 +50,14 @@ case "$1" in
rm $WEBDRIVER_HUB_PIDFILE
sleep 1
if [[ $(ps -A | egrep "^${PID}") ]]; then
- echo "Tried to kill the hub with PID ${PID}, but was unsuccessful. You need to kill it with something stronger, like 'kill -9'"
+ echo "${FAIL_MSG} Tried to kill the hub with PID ${PID}, but was unsuccessful. You need to kill it with something stronger, like 'kill -9'"
exit 1
else
- echo "Selenium-WebDriver Grid2 hub stopped successfully."
+ echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 hub stopped successfully."
exit 0
fi
else
- echo "Selenium-WebDriver Grid2 hub has already been stopped."
+ echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 hub has already been stopped."
exit 0
fi
;;
View
13 script/grid-node
@@ -4,6 +4,8 @@
# Usage: grid-node {start|stop}
#
+source $(dirname $0)/util
+
EXPECTED_ARGS=1
E_BADARGS=65
@@ -16,6 +18,8 @@ if [ $# -ne $EXPECTED_ARGS ]; then
DO_showUsage
fi
+################################################################################
+
WEBDRIVER_SERVER_JAR=/opt/selenium-server-standalone.jar
WEBDRIVER_NODE_PARAMS="-role node -hubHost 127.0.0.1 -hubPort 4444"
WEBDRIVER_NODE_PIDFILE="/tmp/webdriver_node.pid"
@@ -29,13 +33,14 @@ case "$1" in
start)
echo "Starting Selenium-WebDriver Grid2 node..."
if [ -f $WEBDRIVER_NODE_PIDFILE ]; then
- echo "Selenium-WebDriver Grid2 node already running with PID $(cat $WEBDRIVER_NODE_PIDFILE). Run 'grid-node stop' or 'grid-node restart'."
+ echo "${FAIL_MSG} Selenium-WebDriver Grid2 node already running with PID $(cat $WEBDRIVER_NODE_PIDFILE). Run 'grid-node stop' or 'grid-node restart'."
exit 1
else
START_NODE_CMD="java -jar ${WEBDRIVER_SERVER_JAR} ${WEBDRIVER_NODE_PARAMS}"
$START_NODE_CMD &
PID=$!
echo $PID > "${WEBDRIVER_NODE_PIDFILE}"
+ echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 node started successfully."
fi
;;
stop)
@@ -46,14 +51,14 @@ case "$1" in
rm $WEBDRIVER_NODE_PIDFILE
sleep 1
if [[ $(ps -A | egrep "^${PID}") ]]; then
- echo "Tried to kill the node with PID ${PID}, but was unsuccessful. You need to kill it with something stronger, like 'kill -9'"
+ echo "${FAIL_MSG} Tried to kill the node with PID ${PID}, but was unsuccessful. You need to kill it with something stronger, like 'kill -9'"
exit 1
else
- echo "Selenium-WebDriver Grid2 node stopped successfully."
+ echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 node stopped successfully."
exit 0
fi
else
- echo "Selenium-WebDriver Grid2 node has already been stopped."
+ echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 node has already been stopped."
exit 0
fi
;;
View
8 script/test
@@ -4,6 +4,8 @@
# Usage: test <case>
#
+source $(dirname $0)/util
+
EXPECTED_ARGS=1
E_BADARGS=65
@@ -16,6 +18,8 @@ if [ $# -ne $EXPECTED_ARGS ]; then
DO_showUsage
fi
+################################################################################
+
GRID_HOST_DEFAULT=127.0.0.1
GRID_PORT_DEFAULT=3003
@@ -30,12 +34,12 @@ DO_testCore() {
DO_testRemote() {
lein test clj-webdriver.test.remote
- echo -n "Please enter the host on which your Grid hub is running: [${GRID_HOST_DEFAULT}] > "
+ echo -n "Please enter the ${regblu}host${txtrst} on which your Grid hub is running: [${GRID_HOST_DEFAULT}] > "
read WEBDRIVER_GRID_HOST
if [ -z $WEBDRIVER_GRID_HOST ]; then
export WEBDRIVER_GRID_HOST="${GRID_HOST_DEFAULT}"
fi
- echo -n "Please enter the port on which your Grid hub is listening: [${GRID_PORT_DEFAULT}] > "
+ echo -n "Please enter the ${regblu}port${txtrst} on which your Grid hub is listening: [${GRID_PORT_DEFAULT}] > "
read WEBDRIVER_GRID_PORT
if [ -z $WEBDRIVER_GRID_PORT ]; then
export WEBDRIVER_GRID_PORT="${GRID_PORT_DEFAULT}"
View
21 script/util
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+#
+# Sourced only
+#
+
+# Text color variables
+txtund=$(tput sgr 0 1) # Underline
+txtbld=$(tput bold) # Bold
+regred=$(tput setaf 1) # Red
+regblu=$(tput setaf 4) # Blue
+reggrn=$(tput setaf 2) # Green
+regwht=$(tput setaf 7) # White
+txtrst=$(tput sgr0) # Reset
+info=${regwht}*${txtrst} # Feedback
+pass=${regblu}*${txtrst}
+warn=${regred}*${txtrst}
+ques=${regblu}?${txtrst}
+
+FAIL_MSG="${regred}[FAILURE]${txtrst}"
+SUCCESS_MSG="${reggrn}[SUCCESS]${txtrst}"

0 comments on commit 6d1905a

Please sign in to comment.
Something went wrong with that request. Please try again.