sysadmin : ajout d'un affichage des objectifs.
[progfou.git] / sysadmin / sysadmin-check-version-arch
index 5ee5e76..d24fe76 100755 (executable)
@@ -5,11 +5,11 @@
 # Licence : GNU General Public License, version 3
 # Auteur : Progfou <jean-christophe.andre@auf.org>
 # Création : 2011-04-26
-# Mise à jour : 2011-04-28
+# Mise à jour : 2011-08-23
 
-EXPECTED_DEBIAN_VERSION="6.0.1"
+EXPECTED_DEBIAN_VERSION="6.0.2"
 ACCEPTED_DEBIAN_VERSION="5.0.8"
-if grep -qE ' Intel.* Xeon| AMD.* Opteron' /proc/cpuinfo ; then
+if grep -q '^flags.* lm ' /proc/cpuinfo ; then
   EXPECTED_DEBIAN_ARCH="x86_64"
   ACCEPTED_DEBIAN_ARCH="i686"
 else
@@ -27,18 +27,46 @@ else # serveur sous Ubuntu
   ACCEPTED_UBUNTU_ARCH="${ACCEPTED_DEBIAN_ARCH}"
 fi
 
+color_name_to_code() {
+  case "$1" in
+    black)   printf "0" ;;
+    red)     printf "1" ;;
+    green)   printf "2" ;;
+    yellow)  printf "3" ;;
+    blue)    printf "4" ;;
+    magenta) printf "5" ;;
+    cyan)    printf "6" ;;
+    white)   printf "7" ;;
+    *)       printf ""  ;;
+  esac
+}
+
 colorize() {
-  color="$1" ; shift ; data="$@"
-  if [ "${color}" = "green" ] ; then
-    data="\033[1;32m${data}\033[m"
-  elif [ "${color}" = "red" ] ; then
-    data="\033[1;31m${data}\033[m"
+  # syntax: colorize [bright] [bg color_name] color_name text
+  ansi_seq=""
+  if [ "$1" = "bright" ] ; then
+    shift ; ansi_seq="${ansi_seq}1;"
+  fi
+  if [ "$1" = "bg" ] ; then
+    shift ; bg="`color_name_to_code "$1"`" ; shift
+    if [ "${bg}" != "" ] ; then
+      ansi_seq="${ansi_seq}4${bg};"
+    fi
   fi
-  printf "${data}"
+  fg="`color_name_to_code "$1"`" ; shift
+  if [ "${fg}" != "" ] ; then
+      ansi_seq="${ansi_seq}3${fg}"
+  fi
+  text="$@"
+  if [ "${ansi_seq}" != "" ] ; then
+    text="\033[${ansi_seq}m${text}\033[m"
+  fi
+  printf "${text}"
 }
 
 display_host() {
-  name="$1" ; dist="$2" ; version="$3" ; arch="$4"
+  name="$1" ; dist="$2" ; version="$3" ; arch="$4" ; note="$5"
+  goals=""
   if [ "${dist}" = "Ubuntu" ] ; then
     expected_version="${EXPECTED_UBUNTU_VERSION}"
     accepted_version="${ACCEPTED_UBUNTU_VERSION}"
@@ -50,28 +78,50 @@ display_host() {
     expected_arch="${EXPECTED_DEBIAN_ARCH}"
     accepted_arch="${ACCEPTED_DEBIAN_ARCH}"
   else
-    dist="`colorize red "${dist}"`"
+    dist="`colorize bright red "${dist}"`"
+    goals="${goals} Debian"
   fi
   if [ "${version}" = "${expected_version}" ] ; then
-    version="`colorize green "${version}"`"
-  elif [ "${version}" != "${accepted_version}" ] ; then
-    version="`colorize red "${version}"`"
+    version="`colorize bright green "${version}"`"
+  else
+    goals="${goals} ${expected_version}"
+    if [ "${version}" != "${accepted_version}" ] ; then
+      version="`colorize bright red "${version}"`"
+    fi
   fi
   if [ "${arch}" = "${expected_arch}" ] ; then
-    arch="`colorize green "${arch}"`"
-  elif [ "${arch}" != "${accepted_arch}" ] ; then
-    arch="`colorize red "${arch}"`"
+    arch="`colorize bright green "${arch}"`"
+  else
+    goals="${goals} ${expected_arch}"
+    if [ "${arch}" != "${accepted_arch}" ] ; then
+      arch="`colorize bright red "${arch}"`"
+    fi
+  fi
+  if [ "${note}" = "voip" ] ; then
+    if [ "${version}" = "${accepted_version}" ] ; then
+      version="`colorize bright green "${version}"`"
+    fi
+    goals=""
+    note='ne pas migrer vers Squeeze !'
+  fi
+  if expr match "${note}" '.*!' >/dev/null ; then
+    note="`colorize bright red "${note}"`"
   fi
-  printf "%-25s: %s %s (%s)\n" "${name}" "${dist}" "${version}" "${arch}"
+  if [ "${goals}" != "" ] ; then
+    goals="`colorize bright blue "${goals}"`"
+    note="${note} (but :${goals})"
+  fi
+  printf "%-25s: %s %s (%s) %s\n" "${name}" "${dist}" "${version}" "${arch}" "${note}"
 }
 
-display_host "CT 0 (host)" "`lsb_release -si`" "`lsb_release -sr`" "`uname -m`"
+display_host "host" "`lsb_release -si`" "`lsb_release -sr`" "`uname -m`"
 if test -x /usr/sbin/vzctl
 then
   IDS="`vzlist -H -o ctid`"
   if [ -n "${IDS}" ] ; then
     for id in ${IDS}
     do
+      note=""
       name="`sed -n '/^NAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
       if [ -z "${name}" ] ; then
         name="`sed -n '/^HOSTNAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
@@ -80,11 +130,15 @@ then
       if [ -n "${dist}" ] ; then
         version="`vzctl exec ${id} lsb_release -sr 2>/dev/null`"
       else
-        dist="(paquet lsb-release manquant)"
-        version="???"
+        dist="------"
+        version="-----"
+        note='paquet lsb-release manquant !'
       fi
       arch="`vzctl exec ${id} uname -m`"
-      display_host "CT ${id} (${name})" "${dist}" "${version}" "${arch}"
+      if [ -x "/var/lib/vz/private/${id}/usr/sbin/asterisk" ] ; then
+        note="voip"
+      fi
+      display_host "CT ${id} (${name})" "${dist}" "${version}" "${arch}" "${note}"
     done
   fi
 fi