docker: general improvements

* rename set_env->set_default
* fix bug with return from bash func
* make '--miningaddr' optional
This commit is contained in:
Andrey Samokhvalov authored and Olaoluwa Osuntokun committed 2017-01-17 16:56:28 -08:00
1 parent 5c6d196ff8
commit be66e039f1
4 files changed
+111 -57

No files matched your search

+25 -11
View File
@@ -1,32 +1,46 @@
#!/usr/bin/env bash
# Check env variable and in case of empty value and default value specified
# returns default value, in case of non-empty value returns value.
set_env() {
# exit from script if error was raised.
set -e
# error function is used within a bash function in order to send the error
# message directly to the stderr output and exit.
error() {
echo "$1" > /dev/stderr
exit 0
}
# return is used within bash function in order to return the value.
return() {
echo "$1"
}
# set_default function gives the ability to move the setting of default
# env variable from docker file to the script thereby giving the ability to the
# user override it durin container start.
set_default() {
# docker initialized env variables with blank string and we can't just
# use -z flag as usually.
BLANK_STRING='""'
VARIABLE="$1"
NAME="$2"
DEFAULT="$3"
DEFAULT="$2"
if [[ -z "$VARIABLE" || "$VARIABLE" == "$BLANK_STRING" ]]; then
if [ -z "$DEFAULT" ]; then
echo "You should specify '$NAME' env variable"
exit 0
error "You should specify default variable"
else
VARIABLE="$DEFAULT"
fi
fi
# echo is used as return in case if string values
echo "$VARIABLE"
return "$VARIABLE"
}
RPCUSER=$(set_env "$RPCUSER" "RPCUSER")
RPCPASS=$(set_env "$RPCPASS" "RPCPASS")
# Set default variables if needed.
RPCUSER=$(set_default "$RPCUSER" "devuser")
RPCPASS=$(set_default "$RPCPASS" "devpass")
btcctl \
--simnet \