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