From c9ae02019f3bd41bafe7ff35e8c4ac115bedbecb Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 4 Jan 2022 12:46:11 +0100 Subject: [PATCH] Fixing bin/create-motd.sh, adding display of Puppet tier --- bin/create-motd.sh | 80 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/bin/create-motd.sh b/bin/create-motd.sh index ee4fa41..369dce3 100755 --- a/bin/create-motd.sh +++ b/bin/create-motd.sh @@ -7,27 +7,28 @@ # Generating /etc/motd like: # # +----------------------------------------------------------------+ -# | Nodename: cobbler Purpose: Cobbler Install Server | -# | Domain: pixelpark.com Location: L105 | -# | Network: 192.168.88.8 Owner: Pixelpark GmbH | +# | Nodename: cobbler Purpose: VMWare Template | +# | Domain: pixelpark.com Location: L105 / VMWare | +# | Network: 192.168.88.8 Owner: Digitas Pixelpark GmbH | # | Hardware: vmware (x86_64) Contact: 8x5@pixelpark.com | -# | OS: CentOS 7.5.1804 Zone-Host: VMWare | +# | OS: CentOS 7.9.2009 Zone-Host: N/A | # | Puppet Env: test Customer: pixelpark | -# | Puppet Role: default Project: cobbler | +# | Puppet Role: default Project: | +# | Puppet Tier: production | # +----------------------------------------------------------------+ # set -e set -u -export LC_ALL="en_US.utf8" -export LANG="en_US.utf8" +export LC_ALL="en_US.UTF-8" +export LANG="en_US.UTF-8" VERBOSE="n" DEBUG="n" QUIET='n' -VERSION="0.9.9" +VERSION="0.10.0" BASENAME="$(basename ${0})" BASE_DIR="$(dirname ${0})" @@ -56,19 +57,26 @@ get_ip() { NODENAME=$(hostname -s) PURPOSE="VMWare Template" DOMAIN=$(hostname --fqdn | cut -d. -f 2- ) -LOCATION="L105" +LOCATION="L105 / VMWare" get_ip HARDWARE=$( uname -p ) OWNER="Digitas Pixelpark GmbH" -CONTACT="8x5@pixelpark.com" +CONTACT="solution@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 ) +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="${system_status:-development}" PUPPET_ROLE="default" +PUPPET_TIER="production" #------------------------------------------------------------------------------ description() { @@ -113,6 +121,7 @@ usage() { -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. -h|--help Show this output and exit. @@ -125,10 +134,10 @@ get_options() { local tmp= local base_dir= - local short_options="n:p:D:l:i:H:o:e:c:z:C:P:E:R: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:,project:,env:,environment:,role;," - long_options+="debug,verbose,help,version" + long_options+="email:,comments:,zone:,customer:,project:,env:,environment:,role:," + long_options+="tier:,debug,verbose,help,version" set +e tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASENAME}" -- "$@" ) @@ -216,6 +225,11 @@ get_options() { shift shift ;; + -T|--tier) + PUPPET_TIER="$2" + shift + shift + ;; -d|--debug) DEBUG="y" shift @@ -316,7 +330,7 @@ generate() { text="Hardware: ${HARDWARE}" left+=("${text}") - text="OS: ${OS_NAME} (${KERNEL})" + text="OS: ${OS_NAME}" left+=("${text}") text="Puppet Env: ${PUPPET_ENV}" @@ -325,6 +339,9 @@ generate() { text="Puppet Role: ${PUPPET_ROLE}" left+=("${text}") + text="Puppet Tier: ${PUPPET_TIER}" + left+=("${text}") + # Texte rechte Spalte text="Purpose: ${PURPOSE}" right+=("${text}") @@ -352,6 +369,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 @@ -373,15 +399,32 @@ generate() { fi local i= - for i in 0 1 2 3 4 5 6 ; do - text=$( printf "%-*s %-*s" "${max_left}" "${left[${i}]}" \ - "${max_right}" "${right[${i}]}" ) + 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}") @@ -390,6 +433,7 @@ generate() { max="${length}" fi fi + if [[ "${VERBOSE}" == "y" ]] ; then echo "Max. line length: ${max}" >&2 fi -- 2.39.5