aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/dev/scripts/util.sh
diff options
context:
space:
mode:
authorLewis Marshall <lewis@lmars.net>2017-06-01 18:52:18 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-06-01 18:52:18 +0800
commit0036e2a74761413200ce3a8ed316ecb721895f60 (patch)
tree1ac94ec2c89a9055999056cd6d99e2955c4409fd /swarm/dev/scripts/util.sh
parent727eadacca761e4abb4273a87dc601bb79d3167d (diff)
downloaddexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar
dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar.gz
dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar.bz2
dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar.lz
dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar.xz
dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar.zst
dexon-0036e2a74761413200ce3a8ed316ecb721895f60.zip
swarm/dev: add development environment (#14332)
This PR adds a Swarm development environment which can be run in a Docker container and provides scripts for building binaries and running Swarm clusters.
Diffstat (limited to 'swarm/dev/scripts/util.sh')
-rw-r--r--swarm/dev/scripts/util.sh53
1 files changed, 53 insertions, 0 deletions
diff --git a/swarm/dev/scripts/util.sh b/swarm/dev/scripts/util.sh
new file mode 100644
index 000000000..f17a12e42
--- /dev/null
+++ b/swarm/dev/scripts/util.sh
@@ -0,0 +1,53 @@
+# shared shell functions
+
+info() {
+ local msg="$@"
+ local timestamp="$(date +%H:%M:%S)"
+ say "===> ${timestamp} ${msg}" "green"
+}
+
+warn() {
+ local msg="$@"
+ local timestamp=$(date +%H:%M:%S)
+ say "===> ${timestamp} WARN: ${msg}" "yellow" >&2
+}
+
+fail() {
+ local msg="$@"
+ say "ERROR: ${msg}" "red" >&2
+ exit 1
+}
+
+# say prints the given message to STDOUT, using the optional color if
+# STDOUT is a terminal.
+#
+# usage:
+#
+# say "foo" - prints "foo"
+# say "bar" "red" - prints "bar" in red
+# say "baz" "green" - prints "baz" in green
+# say "qux" "red" | tee - prints "qux" with no colour
+#
+say() {
+ local msg=$1
+ local color=$2
+
+ if [[ -n "${color}" ]] && [[ -t 1 ]]; then
+ case "${color}" in
+ red)
+ echo -e "\033[1;31m${msg}\033[0m"
+ ;;
+ green)
+ echo -e "\033[1;32m${msg}\033[0m"
+ ;;
+ yellow)
+ echo -e "\033[1;33m${msg}\033[0m"
+ ;;
+ *)
+ echo "${msg}"
+ ;;
+ esac
+ else
+ echo "${msg}"
+ fi
+}