Architecture dans le cas d'un serveur sous Ubuntu.
[progfou.git] / sysadmin / sysadmin-check-version-arch
1 #!/bin/sh
2 # sysadmin-check-version-arch - vérifie la version et l'architecture système
3 # Copyright ©2011  Agence universitaire de la Francophonie
4 #                  http://www.auf.org/
5 # Licence : GNU General Public License, version 3
6 # Auteur : Progfou <jean-christophe.andre@auf.org>
7 # Création : 2011-04-26
8 # Mise à jour : 2011-04-28
9
10 EXPECTED_DEBIAN_VERSION="6.0.1"
11 ACCEPTED_DEBIAN_VERSION="5.0.8"
12 if grep -qE ' Intel.* Xeon| AMD.* Opteron' /proc/cpuinfo ; then
13   EXPECTED_DEBIAN_ARCH="x86_64"
14   ACCEPTED_DEBIAN_ARCH="i686"
15 else
16   EXPECTED_DEBIAN_ARCH="i686"
17   ACCEPTED_DEBIAN_ARCH="i686"
18 fi
19
20 EXPECTED_UBUNTU_VERSION="10.04"
21 ACCEPTED_UBUNTU_VERSION="10.04"
22 if dpkg -l ubuntu-desktop >/dev/null 2>&1 ; then
23   EXPECTED_UBUNTU_ARCH="i686"
24   ACCEPTED_UBUNTU_ARCH="i686"
25 else # serveur sous Ubuntu
26   EXPECTED_UBUNTU_ARCH="${EXPECTED_DEBIAN_ARCH}"
27   ACCEPTED_UBUNTU_ARCH="${ACCEPTED_DEBIAN_ARCH}"
28 fi
29
30 colorize() {
31   color="$1" ; shift ; data="$@"
32   if [ "${color}" = "green" ] ; then
33     data="\033[1;32m${data}\033[m"
34   elif [ "${color}" = "red" ] ; then
35     data="\033[1;31m${data}\033[m"
36   fi
37   printf "${data}"
38 }
39
40 display_host() {
41   name="$1" ; dist="$2" ; version="$3" ; arch="$4"
42   if [ "${dist}" = "Ubuntu" ] ; then
43     expected_version="${EXPECTED_UBUNTU_VERSION}"
44     accepted_version="${ACCEPTED_UBUNTU_VERSION}"
45     expected_arch="${EXPECTED_UBUNTU_ARCH}"
46     accepted_arch="${ACCEPTED_UBUNTU_ARCH}"
47   elif [ "${dist}" = "Debian" ] ; then
48     expected_version="${EXPECTED_DEBIAN_VERSION}"
49     accepted_version="${ACCEPTED_DEBIAN_VERSION}"
50     expected_arch="${EXPECTED_DEBIAN_ARCH}"
51     accepted_arch="${ACCEPTED_DEBIAN_ARCH}"
52   else
53     dist="`colorize red "${dist}"`"
54   fi
55   if [ "${version}" = "${expected_version}" ] ; then
56     version="`colorize green "${version}"`"
57   elif [ "${version}" != "${accepted_version}" ] ; then
58     version="`colorize red "${version}"`"
59   fi
60   if [ "${arch}" = "${expected_arch}" ] ; then
61     arch="`colorize green "${arch}"`"
62   elif [ "${arch}" != "${accepted_arch}" ] ; then
63     arch="`colorize red "${arch}"`"
64   fi
65   printf "%-25s: %s %s (%s)\n" "${name}" "${dist}" "${version}" "${arch}"
66 }
67
68 display_host "CT 0 (host)" "`lsb_release -si`" "`lsb_release -sr`" "`uname -m`"
69 if test -x /usr/sbin/vzctl
70 then
71   IDS="`vzlist -H -o ctid`"
72   if [ -n "${IDS}" ] ; then
73     for id in ${IDS}
74     do
75       name="`sed -n '/^NAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
76       if [ -z "${name}" ] ; then
77         name="`sed -n '/^HOSTNAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
78       fi
79       dist="`vzctl exec ${id} lsb_release -si 2>/dev/null`"
80       if [ -n "${dist}" ] ; then
81         version="`vzctl exec ${id} lsb_release -sr 2>/dev/null`"
82       else
83         dist="(paquet lsb-release manquant)"
84         version="???"
85       fi
86       arch="`vzctl exec ${id} uname -m`"
87       display_host "CT ${id} (${name})" "${dist}" "${version}" "${arch}"
88     done
89   fi
90 fi