create and use func consoleError
This commit is contained in:
parent
30bb38672b
commit
a77b73e835
@ -7,6 +7,12 @@
|
|||||||
|
|
||||||
|
|
||||||
### functions
|
### functions
|
||||||
|
consoleError () {
|
||||||
|
printf "%s\n%s\n" "$err" "$2"
|
||||||
|
printf "Exiting.\n\n%s" "$norm"
|
||||||
|
exit "$1"
|
||||||
|
}
|
||||||
|
|
||||||
textblock () {
|
textblock () {
|
||||||
printf "%s\n" "$1" | fold -w "$width" -s
|
printf "%s\n" "$1" | fold -w "$width" -s
|
||||||
}
|
}
|
||||||
@ -85,14 +91,13 @@ scriptHelp () {
|
|||||||
# is user root or in the docker group?
|
# is user root or in the docker group?
|
||||||
if [ ! "$( id -u )" -eq 0 ]; then
|
if [ ! "$( id -u )" -eq 0 ]; then
|
||||||
if ! id -Gn | grep docker > /dev/null; then
|
if ! id -Gn | grep docker > /dev/null; then
|
||||||
printf "%s\nYou must either be root or in the 'docker' group to run this script since you must be able to actually start the container! Exiting.\n%s" "$err" "$norm"
|
consoleError '2' "You must either be root or in the 'docker' group to run this script since you must be able to actually start the container!"
|
||||||
exit 2
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# does the params file exist?
|
# does the params file exist?
|
||||||
if [ ! -f "./ab-openldap.params" ]; then
|
if [ ! -f "./ab-openldap.params" ]; then
|
||||||
printf "%s\nCannot find 'ab-openldap.params' file in the same directory as this script. Exiting.\n%s" "$err" "$norm"
|
consoleError '3' "Cannot find 'ab-openldap.params' file in the same directory as this script."
|
||||||
exit 3
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -102,19 +107,13 @@ fi
|
|||||||
# check for certs if using TLS
|
# check for certs if using TLS
|
||||||
if [ "$TLS_CERT" ]; then
|
if [ "$TLS_CERT" ]; then
|
||||||
if [ ! -f "$TLS_CERT" ]; then
|
if [ ! -f "$TLS_CERT" ]; then
|
||||||
printf "%s\nCannot find specified TLS certificate file. Exiting.%s\n" \
|
consoleError '5' 'Cannot find specified TLS certificate file.'
|
||||||
"$err" "$norm"
|
|
||||||
exit 5
|
|
||||||
fi
|
fi
|
||||||
if [ ! -f "$TLS_KEY" ]; then
|
if [ ! -f "$TLS_KEY" ]; then
|
||||||
printf "%s\nCannot find specified TLS private key file. Exiting.%s\n" \
|
consoleError '5' 'Cannot find specified TLS private key file.'
|
||||||
"$err" "$norm"
|
|
||||||
exit 5
|
|
||||||
fi
|
fi
|
||||||
if [ ! -f "$TLS_CHAIN" ]; then
|
if [ ! -f "$TLS_CHAIN" ]; then
|
||||||
printf "%s\nCannot find specified TLS certificate chain file. Exiting.%s\n" \
|
consoleError '5' 'Cannot find specified TLS certificate chain file.'
|
||||||
"$err" "$norm"
|
|
||||||
exit 5
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -145,9 +144,7 @@ while [ $# -gt 0 ]; do
|
|||||||
-n|--name)
|
-n|--name)
|
||||||
# container name
|
# container name
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
printf "%s\nNo container name specified. Exiting.\n%s" \
|
consoleError '1' 'No container name specified.'
|
||||||
"$err" "$norm"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
container_name="$2"
|
container_name="$2"
|
||||||
shift
|
shift
|
||||||
@ -155,9 +152,7 @@ while [ $# -gt 0 ]; do
|
|||||||
--data)
|
--data)
|
||||||
# data volume name
|
# data volume name
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
printf "%s\nNo name specified for data volume. Exiting.\n%s" \
|
consoleError '1' 'No name specified for data volume.'
|
||||||
"$err" "$norm"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
volume_data="$2"
|
volume_data="$2"
|
||||||
shift
|
shift
|
||||||
@ -165,9 +160,7 @@ while [ $# -gt 0 ]; do
|
|||||||
--ldif)
|
--ldif)
|
||||||
# ldif volume name
|
# ldif volume name
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
printf "%s\nNo name specified for LDIF volume. Exiting.\n%s" \
|
consoleError '1' 'No name specified for LDIF volume.'
|
||||||
"$err" "$norm"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
volume_ldif="$2"
|
volume_ldif="$2"
|
||||||
shift
|
shift
|
||||||
@ -175,9 +168,7 @@ while [ $# -gt 0 ]; do
|
|||||||
--backupdir)
|
--backupdir)
|
||||||
# location of backup files to restore
|
# location of backup files to restore
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
printf "%s\nLocation of your backup files not provided. Exiting.\n%s" \
|
consoleError '1' 'Location of your backup files not provided.'
|
||||||
"$err" "$norm"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
backup_dir="$2"
|
backup_dir="$2"
|
||||||
shift
|
shift
|
||||||
@ -185,9 +176,7 @@ while [ $# -gt 0 ]; do
|
|||||||
-t|--tag)
|
-t|--tag)
|
||||||
# specify container tag
|
# specify container tag
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
printf "%s\nNo tag specified. Exiting.\n%s" \
|
consoleError '1' 'No tag specified.'
|
||||||
"$err" "$norm"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
tag="$2"
|
tag="$2"
|
||||||
shift
|
shift
|
||||||
@ -233,9 +222,7 @@ if [ $clean = true ]; then
|
|||||||
containers=$(docker ps -a --no-trunc --filter "label=org.label-schema.name=ab-openldap" --format "{{ .Names }}")
|
containers=$(docker ps -a --no-trunc --filter "label=org.label-schema.name=ab-openldap" --format "{{ .Names }}")
|
||||||
# check for null value -- no containers to remove
|
# check for null value -- no containers to remove
|
||||||
if [ -z "$containers" ]; then
|
if [ -z "$containers" ]; then
|
||||||
printf "%sNo openldap containers to remove. Exiting.%s\n\n" \
|
consoleError '0' 'No openldap containers to remove.'
|
||||||
"$err" "$norm"
|
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# iterate containers, stop them and remove straggling volumes
|
# iterate containers, stop them and remove straggling volumes
|
||||||
|
Loading…
Reference in New Issue
Block a user