]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Fixing postinstall-scripts/create-motd
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 12 Oct 2023 14:17:03 +0000 (16:17 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 12 Oct 2023 14:17:03 +0000 (16:17 +0200)
postinstall-scripts/create-motd

index 7a3d4aedf97907ae0ef9085840b112e5c57c05f4..ed4e86f592c20efe55e6232d7c673c064a179eeb 100755 (executable)
@@ -21,7 +21,7 @@ NORMAL=""
 HAS_TTY='y'
 HAS_COLORS="n"
 
-VERSION="0.6"
+VERSION="0.7"
 
 BASENAME="$(basename ${0})"
 BASE_DIR="$(dirname ${0})"
@@ -103,11 +103,12 @@ get_ip() {
 
 NODENAME=$(hostname -s)
 PURPOSE="Customer project"
+FQDN=$( hostname --fqdn )
 DOMAIN=$(hostname --fqdn | cut -d. -f 2- )
 LOCATION="L105 / VMWare"
 get_ip
 HARDWARE=$( uname -p )
-OWNER="Publicis Pixelpark GmbH"
+OWNER="Digitas Pixelpark GmbH"
 CONTACT="8x5@pixelpark.com"
 COMMENTS=
 ZONE="N/A"
@@ -362,36 +363,92 @@ empty_line() {
     fi
     echo
 }
+#------------------------------------------------------------------------------
+set_locale() {
+
+    local new_locale="$1"
+    local loc=
+    local found="n"
+
+    local oifs="${IFS}"
+    IFS="
+"
+    for loc in $( locale -a ); do
+        if [[ "${loc}" == "${new_locale}" ]] ; then
+            found="y"
+            break
+        fi
+    done
+    IFS="${oifs}"
+
+    if [[ "${found}" != "y" ]] ; then
+        error "Locale '${RED}${new_locale}${NORMAL}' not found."
+    else
+        LANG="${new_locale}"
+        LC_ALL=
+        LC_CTYPE="${new_locale}"
+        LC_NUMERIC="${new_locale}"
+        LC_TIME="${new_locale}"
+        LC_COLLATE="${new_locale}"
+        LC_MONETARY="${new_locale}"
+        LC_MESSAGES="${new_locale}"
+        # shellcheck disable=SC2034
+        LC_PAPER="${new_locale}"
+        # shellcheck disable=SC2034
+        LC_NAME="${new_locale}"
+        # shellcheck disable=SC2034
+        LC_ADDRESS="${new_locale}"
+        # shellcheck disable=SC2034
+        LC_TELEPHONE="${new_locale}"
+        # shellcheck disable=SC2034
+        LC_MEASUREMENT="${new_locale}"
+        # shellcheck disable=SC2034
+        LC_IDENTIFICATION="${new_locale}"
+    fi
+
+}
 
 #------------------------------------------------------------------------------
 
 generate() {
 
+    set_locale 'C.utf8'
+
     local -a left=()
     local -a right=()
     local -a lines=()
 
+    if [[ -x /opt/puppetlabs/bin/facter ]] ; then
+        MY_VIRTUAL=$( /opt/puppetlabs/bin/facter virtual )
+        CPU_VENDOR=$( /opt/puppetlabs/bin/facter processors.models | head -n 2 | tail -n 1 | sed -e 's/^ *"//' -e 's/[(  ].*//' )
+        MY_ARCH=$( /opt/puppetlabs/bin/facter os.architecture )
+    else
+        MY_VIRTUAL='vmware'
+        CPU_VENDOR=$( lscpu | grep '^Model name' | sed -e 's/^[^:]*://' -e 's/^ *//' -e 's/[( ].*//' )
+        MY_ARCH=$( lscpu | grep '^Architecture:' | sed -e 's/^[^:]*://' -e 's/^ *//' )
+    fi
+
     local text=
 
     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}"
+    text="Domain     : ${DOMAIN}"
     left+=("${text}")
 
-    text="Network:     ${IP}"
+    text="Network    : ${IP}"
     left+=("${text}")
 
-    text="Hardware:    ${HARDWARE}"
+    text="Hardware   : ${MY_VIRTUAL} (${MY_ARCH} ${CPU_VENDOR})"
     left+=("${text}")
 
-    text="OS:          ${OS_NAME}"
+    text="OS         : ${OS_NAME}"
     left+=("${text}")
 
-    text="Puppet Env ${PUPPET_ENV}"
+    text="Puppet Env : ${PUPPET_ENV}"
     left+=("${text}")
 
     text="Puppet Role: ${PUPPET_ROLE}"
@@ -400,26 +457,29 @@ generate() {
     text="Puppet Tier: ${PUPPET_TIER}"
     left+=("${text}")
 
+    text="Puppet-Cert: ${FQDN}"
+    left+=("${text}")
+
     # Texte rechte Spalte
-    text="Purpose:   ${PURPOSE}"
+    text="Purpose  : ${PURPOSE}"
     right+=("${text}")
 
-    text="Location ${LOCATION}"
+    text="Location : ${LOCATION}"
     right+=("${text}")
 
-    text="Owner:     ${OWNER}"
+    text="Owner    : ${OWNER}"
     right+=("${text}")
 
-    text="Contact:   ${CONTACT}"
+    text="Contact  : ${CONTACT}"
     right+=("${text}")
 
     text="Zone-Host: ${ZONE}"
     right+=("${text}")
 
-    text="Customer ${PUPPET_CUSTOMER}"
+    text="Customer : ${PUPPET_CUSTOMER}"
     right+=("${text}")
 
-    text="Project:   ${PUPPET_PROJECT}"
+    text="Project  : ${PUPPET_PROJECT}"
     right+=("${text}")
 
     local length=