From: Frank Brehm Date: Tue, 4 Jan 2022 11:41:51 +0000 (+0100) Subject: Fixing postinstall-scripts/create-motd, adding display of Puppet tier X-Git-Tag: 1.5.11~1^2~1 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=fe91355baef30e378d0a607b676da5c5cb9e27da;p=pixelpark%2Fcreate-terraform.git Fixing postinstall-scripts/create-motd, adding display of Puppet tier --- diff --git a/postinstall-scripts/create-motd b/postinstall-scripts/create-motd index 11ddbaf..7a3d4ae 100755 --- a/postinstall-scripts/create-motd +++ b/postinstall-scripts/create-motd @@ -21,7 +21,7 @@ NORMAL="" HAS_TTY='y' HAS_COLORS="n" -VERSION="0.5" +VERSION="0.6" BASENAME="$(basename ${0})" BASE_DIR="$(dirname ${0})" @@ -102,9 +102,9 @@ get_ip() { NODENAME=$(hostname -s) -PURPOSE="Projekt Kunde" +PURPOSE="Customer project" DOMAIN=$(hostname --fqdn | cut -d. -f 2- ) -LOCATION="L105" +LOCATION="L105 / VMWare" get_ip HARDWARE=$( uname -p ) OWNER="Publicis Pixelpark GmbH" @@ -112,8 +112,18 @@ CONTACT="8x5@pixelpark.com" COMMENTS= ZONE="N/A" OS_NAME=$( cat /etc/os-release | grep '^PRETTY_NAME' | awk -F= '{print $2}' | sed -e 's/^"//' -e 's/"$//' ) -KERNEL=$( uname -r | cut -d. -f1,2,3 ) -CUSTOMER="pixelpark" +if [[ "${OS_NAME}" =~ Oracle ]] ; then + OS_NAME=$( echo "${OS_NAME}" | sed -e 's/ *Linux *Server/Linux/i' ) +elif echo "${OS_NAME}" | grep -q ' 7 ' ; then + OS_NAME=$( cat /etc/redhat-release | sed -e 's/ *Linux *release//i' -e 's/ *(Core)//i' ) +fi + +PUPPET_CUSTOMER="pixelpark" +PUPPET_PROJECT="" +PUPPET_ENV="development" +PUPPET_ROLE="default" +PUPPET_TIER="production" + #------------------------------------------------------------------------------ description() { @@ -151,8 +161,14 @@ usage() { Some additional comments to this machine. -z|--zone ZONE_HOST The containing zone host of this zone, VM or container, Default: '${ZONE}'. - -C|--customer HIERA_CUSTOMER - The hiera customer used for Puppet, Default: '${CUSTOMER}'. + -C|--customer PUPPET_CUSTOMER + The hiera customer used for Puppet, Default: '${PUPPET_CUSTOMER}'. + -P|--project PUPPET_PROJECT + The hiera project below the customer used for Puppet, Default: '${PUPPET_PROJECT}'. + -E|--env|--environment ENVIRONMENT + The Puppet Environment, Default: '${PUPPET_ENV}'. + -R|--role ROLE The Puppet Role, Default: '${PUPPET_ROLE}'. + -T|--tier TIER The Puppet Tier, Default: '${PUPPET_TIER}'. -d|--debug Debug output (bash -x). -v|--verbose Set verbosity on. --nocolor Don't use colors on display. @@ -166,9 +182,10 @@ get_options() { local tmp= local base_dir= - local short_options="n:p:D:l:i:H:o:e:c:z:C:dvhV" + local short_options="n:p:D:l:i:H:o:e:c:z:C:P:E:R:T:dvhV" local long_options="node:,purpose:,domain:,location:,ip:,hardware:,owner:," - long_options+="email:,comments:,zone:,customer:,debug,verbose,nocolor,help,version" + long_options+="email:,comments:,zone:,customer:,project:,env:,environment:,role:," + long_options+="tier:,debug,verbose,nocolor,help,version" set +e tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASENAME}" -- "$@" ) @@ -237,7 +254,27 @@ get_options() { shift ;; -C|--customer) - CUSTOMER="$2" + PUPPET_CUSTOMER="$2" + shift + shift + ;; + -P|--project) + PUPPET_PROJECT="$2" + shift + shift + ;; + -E|--env|--environment) + PUPPET_ENV="$2" + shift + shift + ;; + -R|--role) + PUPPET_ROLE="$2" + shift + shift + ;; + -T|--tier) + PUPPET_TIER="$2" shift shift ;; @@ -339,22 +376,28 @@ generate() { info "Generating a new ${GREEN}/etc/motd${NORMAL} (Message of the day) ..." >&2 # Texte linke Spalte - text="Nodename: ${NODENAME}" + text="Nodename: ${NODENAME}" + left+=("${text}") + + text="Domain: ${DOMAIN}" left+=("${text}") - text="Domain: ${DOMAIN}" + text="Network: ${IP}" left+=("${text}") - text="Network: ${IP}" + text="Hardware: ${HARDWARE}" left+=("${text}") - text="Hardware: ${HARDWARE}" + text="OS: ${OS_NAME}" left+=("${text}") - text="OS: ${OS_NAME} (${KERNEL})" + text="Puppet Env: ${PUPPET_ENV}" left+=("${text}") - text="" + text="Puppet Role: ${PUPPET_ROLE}" + left+=("${text}") + + text="Puppet Tier: ${PUPPET_TIER}" left+=("${text}") # Texte rechte Spalte @@ -373,7 +416,10 @@ generate() { text="Zone-Host: ${ZONE}" right+=("${text}") - text="Customer: ${CUSTOMER}" + text="Customer: ${PUPPET_CUSTOMER}" + right+=("${text}") + + text="Project: ${PUPPET_PROJECT}" right+=("${text}") local length= @@ -381,6 +427,15 @@ generate() { local max_right="1" local max="1" + local no_lines_left="${#left[*]}" + local no_lines_right="${#right[*]}" + local no_lines="${no_lines_left}" + if [[ "${no_lines_right}" -gt "${no_lines_left}" ]] ; then + no_lines="${no_lines_right}" + fi + local text_left= + local text_right= + for text in "${left[@]}" ; do length=$( printf "${text}" | wc -c ) if [[ "${length}" -gt "${max_left}" ]] ; then @@ -401,16 +456,33 @@ generate() { echo "Max. length right: ${max_right}" >&2 fi - local i= - for i in 0 1 2 3 4 5 ; do - text=$( printf "%-*s %-*s" "${max_left}" "${left[${i}]}" \ - "${max_right}" "${right[${i}]}" ) + local i=0 + while [[ "$i" -lt "${no_lines}" ]] ; do + + if [[ "$i" -lt "${no_lines_left}" ]] ; then + text_left="${left[${i}]}" + else + text_left="" + fi + + if [[ "$i" -lt "${no_lines_right}" ]] ; then + text_right="${right[${i}]}" + else + text_right="" + fi + + i=$(( $i + 1 )) + + text=$( printf "%-*s %-*s" "${max_left}" "${text_left}" \ + "${max_right}" "${text_right}" ) lines+=("${text}") length=$( printf "${text}" | wc -c ) if [[ "${length}" -gt "${max}" ]] ; then max="${length}" fi + done + if [[ -n "${COMMENTS}" ]] ; then text="Comments: ${COMMENTS}" lines+=("${text}") @@ -419,6 +491,7 @@ generate() { max="${length}" fi fi + if [[ "${VERBOSE}" == "y" ]] ; then echo "Max. line length: ${max}" >&2 fi