Mise à jour d'outils système.
[progfou.git] / sysadmin / sysadmin-check-version-arch
index 04b24b8..165bb86 100755 (executable)
@@ -5,17 +5,27 @@
 # Licence : GNU General Public License, version 3
 # Auteur : Progfou <jean-christophe.andre@auf.org>
 # Création : 2011-04-26
-# Mise à jour : 2011-04-27
+# Mise à jour : 2011-08-23
 
-EXPECTED_DEBIAN_VERSION="6.0.1"
+EXPECTED_DEBIAN_VERSION="6.0.2"
 ACCEPTED_DEBIAN_VERSION="5.0.8"
-EXPECTED_DEBIAN_ARCH="x86_64"
-ACCEPTED_DEBIAN_ARCH="i686"
+if grep -q '^flags.* lm ' /proc/cpuinfo ; then
+  EXPECTED_DEBIAN_ARCH="x86_64"
+  ACCEPTED_DEBIAN_ARCH="i686"
+else
+  EXPECTED_DEBIAN_ARCH="i686"
+  ACCEPTED_DEBIAN_ARCH="i686"
+fi
 
 EXPECTED_UBUNTU_VERSION="10.04"
 ACCEPTED_UBUNTU_VERSION="10.04"
-EXPECTED_UBUNTU_ARCH="i686"
-ACCEPTED_UBUNTU_ARCH="i686"
+if dpkg -l ubuntu-desktop >/dev/null 2>&1 ; then
+  EXPECTED_UBUNTU_ARCH="i686"
+  ACCEPTED_UBUNTU_ARCH="i686"
+else # serveur sous Ubuntu
+  EXPECTED_UBUNTU_ARCH="${EXPECTED_DEBIAN_ARCH}"
+  ACCEPTED_UBUNTU_ARCH="${ACCEPTED_DEBIAN_ARCH}"
+fi
 
 colorize() {
   color="$1" ; shift ; data="$@"
@@ -24,11 +34,11 @@ colorize() {
   elif [ "${color}" = "red" ] ; then
     data="\033[1;31m${data}\033[m"
   fi
-  echo "${data}"
+  printf "${data}"
 }
 
 display_host() {
-  name="$1" ; dist="$2" ; version="$3" ; arch="$4"
+  name="$1" ; dist="$2" ; version="$3" ; arch="$4" ; note="$5"
   if [ "${dist}" = "Ubuntu" ] ; then
     expected_version="${EXPECTED_UBUNTU_VERSION}"
     accepted_version="${ACCEPTED_UBUNTU_VERSION}"
@@ -40,33 +50,55 @@ display_host() {
     expected_arch="${EXPECTED_DEBIAN_ARCH}"
     accepted_arch="${ACCEPTED_DEBIAN_ARCH}"
   else
-    echo 'Système non reconnu !'
+    dist="`colorize red "${dist}"`"
   fi
   if [ "${version}" = "${expected_version}" ] ; then
-    version="`colorize green "$version"`"
+    version="`colorize green "${version}"`"
   elif [ "${version}" != "${accepted_version}" ] ; then
-    version="`colorize red "$version"`"
+    version="`colorize red "${version}"`"
+  fi
+  if [ "${arch}" = "${expected_arch}" ] ; then
+    arch="`colorize green "${arch}"`"
+  elif [ "${arch}" != "${accepted_arch}" ] ; then
+    arch="`colorize red "${arch}"`"
   fi
-  if [ "$arch" = "${expected_arch}" ] ; then
-    arch="`colorize green "$arch"`"
-  elif [ "$arch" != "${accepted_arch}" ] ; then
-    arch="`colorize red "$arch"`"
+  if [ "${note}" = "voip" ] ; then
+    if [ "${version}" = "${accepted_version}" ] ; then
+      version="`colorize green "${version}"`"
+    fi
+    note='ne pas migrer vers Squeeze !'
   fi
-  printf "%-25s: %s %s (%s)\n" "${name}" "${dist}" "${version}" "${arch}"
+  if expr match "${note}" '.*!' >/dev/null ; then
+    note="`colorize red "${note}"`"
+  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
+  if [ -n "${IDS}" ] ; then
+    for id in ${IDS}
     do
+      note=""
       name="`sed -n '/^NAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
-      if [ -n "${name}" ] ; then
+      if [ -z "${name}" ] ; then
         name="`sed -n '/^HOSTNAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
       fi
-      display_host "CT ${id} (${name})" "`vzctl exec ${id} lsb_release -si`" "`vzctl exec ${id} lsb_release -sr`" "`vzctl exec ${id} uname -m`"
+      dist="`vzctl exec ${id} lsb_release -si 2>/dev/null`"
+      if [ -n "${dist}" ] ; then
+        version="`vzctl exec ${id} lsb_release -sr 2>/dev/null`"
+      else
+        dist="------"
+        version="-----"
+        note='paquet lsb-release manquant !'
+      fi
+      arch="`vzctl exec ${id} uname -m`"
+      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