From: Frank Brehm Date: Mon, 21 Nov 2022 14:11:56 +0000 (+0100) Subject: Adding possibility to give additional opptions for executing puppet agent in scripts... X-Git-Tag: 0.7.3^2~2^2~1 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=0998da1f475467f1d9448e5351a1fe602c498e75;p=pixelpark%2Fpp-admin-tools.git Adding possibility to give additional opptions for executing puppet agent in scripts/exec-puppet-agent --- diff --git a/scripts/exec-puppet-agent b/scripts/exec-puppet-agent index b310664..d03d8d6 100755 --- a/scripts/exec-puppet-agent +++ b/scripts/exec-puppet-agent @@ -22,6 +22,9 @@ else exit 5 fi +declare -a ADD_PUPPET_AGENT_ARGS=() +TIMINGS="n" + detect_color DESCRIPTION=$( cat <<-EOF @@ -33,10 +36,13 @@ DESCRIPTION=$( cat <<-EOF #------------------------------------------------------------------------------ usage() { cat <<-EOF - Usage: ${BASE_NAME} [Common Options] + Usage: ${BASE_NAME} [Common Options] [-t|--timing] [-- ADDITIIONAL_OPTION_FOR_PUPPET ...] ${BASE_NAME} [-h|--help] ${BASE_NAME} [-V|--version] + Special Options: + -t|--timing Display statistics about real, user and system time on execution of puppet agent. + Common Options: ${STD_USAGE_MSG} EOF @@ -48,9 +54,12 @@ get_options() { local tmp= local base_dir= + local arg= set +e - tmp=$( getopt -o ${STD_SHORT_OPTIONS} --long ${STD_LONG_OPTIONS} -n "${BASE_NAME}" -- "$@" ) + tmp=$( getopt -o ${STD_SHORT_OPTIONS}t \ + --long ${STD_LONG_OPTIONS},timing \ + -n "${BASE_NAME}" -- "$@" ) if [[ $? != 0 ]] ; then echo "" >&2 usage >&2 @@ -66,18 +75,33 @@ get_options() { declare -p REMAINING_ARGS fi - if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then - error "Unknown options: ${REMAINING_OPTS[*]}" - echo >&2 - usage >&2 - exit 2 - fi + local len="${#REMAINING_OPTS[*]}" + local i="0" + while [[ "$i" -lt "${len}" ]] ; do + + arg="${REMAINING_OPTS[$i]}" + + case "${arg}" in + -t|--timing) + TIMINGS="y" + i=$(( $i + 1 )) + ;; + *) echo -e "Internal error - option '${RED}${arg}${NORMAL} was wrong!" + exit 1 + ;; + esac + + done if [[ "${#REMAINING_ARGS[@]}" != "0" ]] ; then - error "Invalig arguments given: ${REMAINING_ARGS[*]}" - echo >&2 - usage >&2 - exit 2 + i="0" + for arg in "${REMAINING_ARGS[@]}" ; do + if [[ "${i}" == "0" && "${arg}" == '--' ]] ; then + continue + fi + i=$(( $i + 1 )) + ADD_PUPPET_AGENT_ARGS+=( "${arg}" ) + done fi if [[ $(id -u -n) != "root" ]] ; then @@ -110,10 +134,17 @@ exec_puppet_agent() { i=$(( $1 + 1 )) done - local cmd="${PUPPET_BIN} agent --test" + local cmd="" + if [[ "${TIMINGS}" == "y" ]] ; then + cmd="time " + fi + cmd+="${PUPPET_BIN} agent --test" if [[ "${SIMULATE}" == "y" ]] ; then cmd+=" --noop" fi + if [[ "${#ADD_PUPPET_AGENT_ARGS[@]}" != "0" ]] ; then + cmd+=" ${ADD_PUPPET_AGENT_ARGS[@]}" + fi debug "Executing: ${cmd}" set +e eval ${cmd}