From: Frank Brehm Date: Thu, 10 Nov 2022 07:53:29 +0000 (+0100) Subject: Finished scripts/exec-puppet-agent X-Git-Tag: 0.7.1^2~2 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=6d1db9aa565f9c11dbbacca5bd332ece841be816;p=pixelpark%2Fpp-admin-tools.git Finished scripts/exec-puppet-agent --- diff --git a/scripts/chatbot-to-ldap b/scripts/chatbot-to-ldap deleted file mode 100755 index 2ead5b6..0000000 --- a/scripts/chatbot-to-ldap +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash - -if [[ $(id -u -n) != "root" ]] ; then - echo "You must be root to execute this script!" >&2 - exit 1 -fi - -declare -a ACCOUNTS_REMOVE=() -declare -A ACCOUNTS_MIGRATE=() - -SIMULATE="n" -# SIMULATE="y" - -ACCOUNTS_MIGRATE['angel.ortiz']='angel.ortiz' -ACCOUNTS_MIGRATE['bjoern.buehring']='bjoern.buehring' -ACCOUNTS_MIGRATE['daniel.quolke']='daniel.quolke' -ACCOUNTS_MIGRATE['felix.berndt']='felix.berndt' -ACCOUNTS_MIGRATE['frank.brehm']='frank.brehm' -ACCOUNTS_MIGRATE['gerstenberg']='andreas.gerstenberg' -ACCOUNTS_MIGRATE['hendrik.hoffmann']='hendrik.hoffmann' -ACCOUNTS_MIGRATE['kotschok']='andreas.glaw' -ACCOUNTS_MIGRATE['krystian.horbacz']='krystian.horbacz' -ACCOUNTS_MIGRATE['kuntz']='klaus.kuntz' -ACCOUNTS_MIGRATE['lutz.beier']='lutz.beier' -ACCOUNTS_MIGRATE['markus.haebe']='markus.haebe' -ACCOUNTS_MIGRATE['michael.krause']='michael.krause' -ACCOUNTS_MIGRATE['mustaque.siare-inidiba']='mustaque.siare-inidiba' -ACCOUNTS_MIGRATE['nils.althaus']='nils.althaus' -ACCOUNTS_MIGRATE['oliver.boettcher']='oliver.boettcher' -ACCOUNTS_MIGRATE['reinhard.schmitz']='reinhard.schmitz' -ACCOUNTS_MIGRATE['robert.waffen']='robert.waffen' -ACCOUNTS_MIGRATE['sebastian.guenther']='sebastian.guenther' -ACCOUNTS_MIGRATE['thomas.dalichow']='thomas.dalichow' -ACCOUNTS_MIGRATE['thomas.heller']='thomas.heller' -ACCOUNTS_MIGRATE['thomas.kotschok']='thomas.kotschok' -ACCOUNTS_MIGRATE['thomas.lewin']='thomas.lewin' -ACCOUNTS_MIGRATE['tobias.graul']='tobias.graul' -ACCOUNTS_MIGRATE['tony.walter']='tony.walter' - -ACCOUNTS_REMOVE+=('bettina.lanser') -ACCOUNTS_REMOVE+=('henning.malzahn') -ACCOUNTS_REMOVE+=('janeric.gaidusch') -ACCOUNTS_REMOVE+=('maik.hummel') -ACCOUNTS_REMOVE+=('matthias.schmidt') -ACCOUNTS_REMOVE+=('michael.krohmann') -ACCOUNTS_REMOVE+=('mladen.uzunov') -ACCOUNTS_REMOVE+=('paul.lindner') -ACCOUNTS_REMOVE+=('sebastian.reusse') -ACCOUNTS_REMOVE+=('tillmann.pross') -ACCOUNTS_REMOVE+=('tom.juzek') -ACCOUNTS_REMOVE+=('vasko.mihaylov') -ACCOUNTS_REMOVE+=('veselin.bochev') - -echo -echo "Executing Puppet agent ..." -echo -i=0 -while [[ -e "/opt/puppetlabs/puppet/cache/state/agent_catalog_run.lock" ]] ; do - modulus=$(( $i % 10 )) - if [[ "${modulus}" == "0" ]] ; then - echo "Waiting ..." - fi - sleep 1 - i=$(( $1 + 1 )) -done - -cmd="puppet agent --test" -if [[ "${SIMULATE}" == "y" ]] ; then - echo "Executing: ${cmd}" -else - eval ${cmd} -fi - -echo -if id kuntz >/dev/null 2>&1 ; then - echo "On this host there are still the old (hiera based) accounts active." >&2 - exit 1 -fi - -if id klaus.kuntz >/dev/null 2>&1 ; then - echo "There seems to be enabled LDAP authentication." -else - echo "There seems NOT to be LDAP authentication on this host." >&2 - exit 5 -fi - -echo -echo "Handing home directories of existing users ..." - -for old_account in "${!ACCOUNTS_MIGRATE[@]}" ; do - new_account="${ACCOUNTS_MIGRATE[${old_account}]}" - old_home="/home/${old_account}" - new_home="/home/${new_account}" - if [[ -d "${old_home}" ]] ; then - CUR_OWNER=$( stat --format "%U" "${old_home}" ) - if [[ "${CUR_OWNER}" != "${new_account}" ]] ; then - echo "Chowning \"${old_home}\" to user \"${new_account}\": ..." - cmd="chown -R \"${new_account}\": \"${old_home}\"" - if [[ "${SIMULATE}" == "y" ]] ; then - echo "Executing: ${cmd}" - else - eval ${cmd} - fi - fi - if [[ "${old_account}" != "${new_account}" ]] ; then - echo "Moving '${old_home}' => '${new_home}' ..." - if [[ -d "${new_home}" ]] ; then - echo "Cannot move '${old_home}' => '${new_home}', because the target dir is already existing." - else - echo "mv -v \"${old_home}\" \"${new_home}\"" - fi - fi - fi -done - -echo -echo "Removing home directories of non-existing users ..." - -for old_account in "${ACCOUNTS_REMOVE[@]}" ; do - old_home="/home/${old_account}" - if id "${old_account}" >/dev/null 2>&1 ; then - continue - fi - if [[ -d "${old_home}" ]] ; then - cmd="rm -rf \"${old_home}\"" - echo "Removing '${old_home}' ..." - if [[ "${SIMULATE}" == "y" ]] ; then - echo "Executing: ${cmd}" - else - eval ${cmd} - fi - fi -done - -echo -echo "Finished." diff --git a/scripts/exec-puppet-agent b/scripts/exec-puppet-agent new file mode 100755 index 0000000..2a07a86 --- /dev/null +++ b/scripts/exec-puppet-agent @@ -0,0 +1,135 @@ +#!/bin/bash + +set -e +set -u + +BASE_NAME="$( basename ${0} )" +MY_REAL_NAME=$( readlink -f $0 ) +BIN_DIR=$( dirname "${MY_REAL_NAME}" ) +BASE_DIR=$( dirname "${BIN_DIR}" ) +LIB_DIR="${BASE_DIR}/lib" +CONF_DIR="${BASE_DIR}/etc" + +PUPPET_BASE="/opt/puppetlabs" +PUPPET_BIN="${PUPPET_BASE}/bin/puppet" +PUPPET_RUN_LOCK="${PUPPET_BASE}/puppet/cache/state/agent_catalog_run.lock" + +if [[ -f "${BIN_DIR}/functions.rc" ]] ; then + . "${BIN_DIR}/functions.rc" +else + echo "Bash resource file '${BIN_DIR}/functions.rc' not found" >&2 + exit 5 +fi + +detect_color + +DESCRIPTION=$( cat <<-EOF + Executes the puppet agent in test mode. + + EOF +) + +#------------------------------------------------------------------------------ +usage() { + cat <<-EOF + Usage: ${BASE_NAME} [Common Options] + ${BASE_NAME} [-h|--help] + ${BASE_NAME} [-V|--version] + + Common Options: + ${STD_USAGE_MSG} + EOF + +} + +#------------------------------------------------------------------------------ +get_options() { + + local tmp= + local base_dir= + + set +e + tmp=$( getopt -o ${STD_SHORT_OPTIONS} --long ${STD_LONG_OPTIONS} -n "${BASE_NAME}" -- "$@" ) + if [[ $? != 0 ]] ; then + echo "" >&2 + usage >&2 + exit 1 + fi + set -e + + # Note the quotes around `$TEMP': they are essential! + eval set -- "${tmp}" + eval_common_options "$@" + if [[ "${DEBUG}" == 'y' ]] ; then + declare -p REMAINING_OPTS + declare -p REMAINING_ARGS + fi + + if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then + error "Unknown options: ${REMAINING_OPTS[*]}" + echo >&2 + usage >&2 + exit 2 + fi + + if [[ "${#REMAINING_ARGS[@]}" != "0" ]] ; then + error "Invalig arguments given: ${REMAINING_ARGS[*]}" + echo >&2 + usage >&2 + exit 2 + fi + + if [[ $(id -u -n) != "root" ]] ; then + error "You must ${RED}be root${NORMAL} to execute this script!" >&2 + exit 1 + fi + +} + +#------------------------------------------------------------------------------ +exec_puppet_agent() { + + empty_line + local msg="Executing ${CYAN}Puppet agent${NORMAL} " + if [[ "${SIMULATE}" == "y" ]] ; then + msg+="in ${CYAN}noop mode${NORMAL} " + fi + msg+="..." + info "${msg}" + empty_line + + local i=0 + local modulus= + while [[ -e "${PUPPET_RUN_LOCK}" ]] ; do + modulus=$(( $i % 10 )) + if [[ "${modulus}" == "0" ]] ; then + info "Waiting ..." + fi + sleep 1 + i=$(( $1 + 1 )) + done + + local cmd="${PUPPET_BIN} agent --test" + if [[ "${SIMULATE}" == "y" ]] ; then + cmd+=" --noop" + fi + debug "Executing: ${cmd}" + eval ${cmd} + + empty_line + info "${CYAN}Finished${NORMAL}." +} + +#------------------------------------------------------------------------------ +main() { + + get_options "$@" + umask 0022 + exec_puppet_agent + +} + +main "$@" +exit 0 + +# vim: et list diff --git a/scripts/get-dns-zonefiles b/scripts/get-dns-zonefiles index cf0bb24..1ed06a4 100755 --- a/scripts/get-dns-zonefiles +++ b/scripts/get-dns-zonefiles @@ -48,6 +48,7 @@ usage() { } +#------------------------------------------------------------------------------ get_options() { local tmp= @@ -153,9 +154,6 @@ main() { } main "$@" - - - exit 0 # vim: et list