Ajout d'un script de vérification version/arch.
authorProgfou <jean-christophe.andre@auf.org>
Tue, 26 Apr 2011 22:47:43 +0000 (05:47 +0700)
committerProgfou <jean-christophe.andre@auf.org>
Tue, 26 Apr 2011 22:47:43 +0000 (05:47 +0700)
sysadmin/sysadmin-check-version-arch [new file with mode: 0755]

diff --git a/sysadmin/sysadmin-check-version-arch b/sysadmin/sysadmin-check-version-arch
new file mode 100755 (executable)
index 0000000..04b24b8
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/sh
+# sysadmin-check-version-arch - vérifie la version et l'architecture système
+# Copyright ©2011  Agence universitaire de la Francophonie
+#                  http://www.auf.org/
+# Licence : GNU General Public License, version 3
+# Auteur : Progfou <jean-christophe.andre@auf.org>
+# Création : 2011-04-26
+# Mise à jour : 2011-04-27
+
+EXPECTED_DEBIAN_VERSION="6.0.1"
+ACCEPTED_DEBIAN_VERSION="5.0.8"
+EXPECTED_DEBIAN_ARCH="x86_64"
+ACCEPTED_DEBIAN_ARCH="i686"
+
+EXPECTED_UBUNTU_VERSION="10.04"
+ACCEPTED_UBUNTU_VERSION="10.04"
+EXPECTED_UBUNTU_ARCH="i686"
+ACCEPTED_UBUNTU_ARCH="i686"
+
+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"
+  fi
+  echo "${data}"
+}
+
+display_host() {
+  name="$1" ; dist="$2" ; version="$3" ; arch="$4"
+  if [ "${dist}" = "Ubuntu" ] ; then
+    expected_version="${EXPECTED_UBUNTU_VERSION}"
+    accepted_version="${ACCEPTED_UBUNTU_VERSION}"
+    expected_arch="${EXPECTED_UBUNTU_ARCH}"
+    accepted_arch="${ACCEPTED_UBUNTU_ARCH}"
+  elif [ "${dist}" = "Debian" ] ; then
+    expected_version="${EXPECTED_DEBIAN_VERSION}"
+    accepted_version="${ACCEPTED_DEBIAN_VERSION}"
+    expected_arch="${EXPECTED_DEBIAN_ARCH}"
+    accepted_arch="${ACCEPTED_DEBIAN_ARCH}"
+  else
+    echo 'Système non reconnu !'
+  fi
+  if [ "${version}" = "${expected_version}" ] ; then
+    version="`colorize green "$version"`"
+  elif [ "${version}" != "${accepted_version}" ] ; then
+    version="`colorize red "$version"`"
+  fi
+  if [ "$arch" = "${expected_arch}" ] ; then
+    arch="`colorize green "$arch"`"
+  elif [ "$arch" != "${accepted_arch}" ] ; then
+    arch="`colorize red "$arch"`"
+  fi
+  printf "%-25s: %s %s (%s)\n" "${name}" "${dist}" "${version}" "${arch}"
+}
+
+display_host "CT 0 (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
+      name="`sed -n '/^NAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
+      if [ -n "${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`"
+    done
+  fi
+fi