Add script 'get_list_config.sh'.
This commit is contained in:
parent
df9ba17062
commit
08feaa7762
275
get_list_config.sh
Executable file
275
get_list_config.sh
Executable file
@ -0,0 +1,275 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
script_name="$(basename $(realpath $0))"
|
||||||
|
working_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
|
LOCK_DIR="/tmp/$(basename $0).$$.LOCK"
|
||||||
|
log_file="${LOCK_DIR}/${script_name%%.*}.log"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ----------
|
||||||
|
# Base Function(s)
|
||||||
|
# ----------
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
|
||||||
|
|
||||||
|
[[ -n "$1" ]] && error "$1"
|
||||||
|
|
||||||
|
|
||||||
|
[[ $terminal ]] && echo -e "
|
||||||
|
\033[1mUsage:\033[m
|
||||||
|
|
||||||
|
$(basename $0) <fq-list-address>
|
||||||
|
|
||||||
|
\033[1mDescription\033[m
|
||||||
|
|
||||||
|
Prints out the paraameter settings for the given list.
|
||||||
|
|
||||||
|
\033[1mOptions\033[m
|
||||||
|
|
||||||
|
-h
|
||||||
|
Prints out this help.
|
||||||
|
|
||||||
|
|
||||||
|
-l name@domain
|
||||||
|
|
||||||
|
Prints out the configuration for the list \033[1mname@domain\033[m.
|
||||||
|
Then list name must be given as full qualified list address.
|
||||||
|
|
||||||
|
|
||||||
|
\033[1mExample:\033[m
|
||||||
|
|
||||||
|
Get configuration for list 'star@il-schleuder.de':
|
||||||
|
|
||||||
|
\033[1m$(basename $0) -l star@il-schleuder.de\033[m
|
||||||
|
|
||||||
|
|
||||||
|
"
|
||||||
|
|
||||||
|
clean_up 1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_up() {
|
||||||
|
|
||||||
|
# Perform program exit housekeeping
|
||||||
|
rm -rf "$LOCK_DIR"
|
||||||
|
blank_line
|
||||||
|
exit $1
|
||||||
|
}
|
||||||
|
|
||||||
|
echononl(){
|
||||||
|
if $terminal ; then
|
||||||
|
echo X\\c > /tmp/shprompt$$
|
||||||
|
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
|
||||||
|
echo -e -n " $*\\c" 1>&2
|
||||||
|
else
|
||||||
|
echo -e -n " $*" 1>&2
|
||||||
|
fi
|
||||||
|
rm /tmp/shprompt$$
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
fatal(){
|
||||||
|
echo ""
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e " [ \033[31m\033[1mFatal\033[m ] $*"
|
||||||
|
else
|
||||||
|
echo -e " [ Fatal ] $*"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e " \033[1mScript was terminated\033[m.."
|
||||||
|
else
|
||||||
|
echo -e " Script was terminated.."
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
rm -rf $LOCK_DIR
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
error (){
|
||||||
|
echo ""
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e " [ \033[31m\033[1mError\033[m ] $*"
|
||||||
|
else
|
||||||
|
echo " [ Error ] $*"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_done() {
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e "\033[75G[ \033[32mdone\033[m ]"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
echo_ok() {
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e "\033[75G[ \033[32mok\033[m ]"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
echo_failed(){
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
echo_skipped() {
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
trim() {
|
||||||
|
local var="$*"
|
||||||
|
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
|
||||||
|
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
|
||||||
|
echo -n "$var"
|
||||||
|
}
|
||||||
|
|
||||||
|
blank_line() {
|
||||||
|
if $terminal ; then
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# ----------
|
||||||
|
# - Jobhandling
|
||||||
|
# ----------
|
||||||
|
|
||||||
|
# - Run 'clean_up' for signals SIGHUP SIGINT SIGTERM
|
||||||
|
# -
|
||||||
|
trap clean_up SIGHUP SIGINT SIGTERM
|
||||||
|
|
||||||
|
# - Create lock directory '$LOCK_DIR"
|
||||||
|
#
|
||||||
|
mkdir "$LOCK_DIR"
|
||||||
|
|
||||||
|
|
||||||
|
# ----------
|
||||||
|
# - Some checks ..
|
||||||
|
# ----------
|
||||||
|
|
||||||
|
# - Running in a terminal?
|
||||||
|
# -
|
||||||
|
if [[ -t 1 ]] ; then
|
||||||
|
terminal=true
|
||||||
|
else
|
||||||
|
terminal=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
# - Print help?
|
||||||
|
# -
|
||||||
|
if [[ "$(trim $*)" =~ "--help" ]] ; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# ==========
|
||||||
|
# - Begin Main Script
|
||||||
|
# ==========
|
||||||
|
|
||||||
|
# ----------
|
||||||
|
# - Headline
|
||||||
|
# ----------
|
||||||
|
|
||||||
|
if $terminal ; then
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[1m----------\033[m"
|
||||||
|
echo -e "\033[32m\033[1mRunning script \033[m\033[1m$script_name\033[32m .. \033[m"
|
||||||
|
echo -e "\033[1m----------\033[m"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# ----------
|
||||||
|
# - Read commandline parameter
|
||||||
|
# ----------
|
||||||
|
|
||||||
|
while getopts hl: opt ; do
|
||||||
|
case $opt in
|
||||||
|
l) LIST_NAME="$OPTARG"
|
||||||
|
;;
|
||||||
|
h) usage
|
||||||
|
;;
|
||||||
|
\?) usage ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# - Print help?
|
||||||
|
# -
|
||||||
|
if [[ "$(trim $*)" =~ "--help" ]] ; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
shift $(expr $OPTIND - 1)
|
||||||
|
[[ $# -eq "0" ]] || usage "Wrong number of arguments!"
|
||||||
|
|
||||||
|
[[ -n "$LIST_NAME" ]] || usage "List address not given! Use comandline parameter '-l'."
|
||||||
|
|
||||||
|
|
||||||
|
# ----------
|
||||||
|
# - Some pre-script tasks ..
|
||||||
|
# ----------
|
||||||
|
|
||||||
|
if $terminal ; then
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo -e " \033[1mDoing some pre-script tasks ..\033[m"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echononl "Get a list of available list options .."
|
||||||
|
list_options="$(schleuder-cli lists list-options 2> "${log_file}")"
|
||||||
|
|
||||||
|
if [[ -s "$log_file" ]] ; then
|
||||||
|
echo_failed
|
||||||
|
fatal "Run this script as a user, who is allowed to maintain schleuder lists."
|
||||||
|
else
|
||||||
|
echo_done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# - List present?
|
||||||
|
# -
|
||||||
|
if ! $(schleuder-cli lists list | grep -q -E "^${LIST_NAME}$" 2>/dev/null) ; then
|
||||||
|
fatal "List '$LIST_NAME' not found at this server!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------
|
||||||
|
# - Main part of script
|
||||||
|
# ----------
|
||||||
|
|
||||||
|
if $terminal ; then
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo -e " \033[1mParameter settings for list \033[32m\033[1m$LIST_NAME\033[32m ..\033[m"
|
||||||
|
echo ""
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo " Parameter settings for list '$LIST_NAME':"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for _option in $list_options ; do
|
||||||
|
_val="$(schleuder-cli lists show $LIST_NAME $_option 2> $log_file)"
|
||||||
|
if [[ -s "${log_file}" ]]; then
|
||||||
|
error "$(cat "${log_file}")"
|
||||||
|
clean_up 1
|
||||||
|
fi
|
||||||
|
if $terminal ; then
|
||||||
|
echo -en " ${_option}:\033[50G"
|
||||||
|
if [[ -z "$_val" ]] ; then
|
||||||
|
echo -en "\033[33m-- <not set> --"
|
||||||
|
else
|
||||||
|
echo -en "\033[32m${_val}"
|
||||||
|
fi
|
||||||
|
echo -e "\033[m"
|
||||||
|
else
|
||||||
|
echo " ${_option}: ${_val}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
clean_up 1
|
Loading…
Reference in New Issue
Block a user