04b24b88596cb236572afdfc2ed00265ba4fdf44
[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-27
9
10 EXPECTED_DEBIAN_VERSION="6.0.1"
11 ACCEPTED_DEBIAN_VERSION="5.0.8"
12 EXPECTED_DEBIAN_ARCH="x86_64"
13 ACCEPTED_DEBIAN_ARCH="i686"
14
15 EXPECTED_UBUNTU_VERSION="10.04"
16 ACCEPTED_UBUNTU_VERSION="10.04"
17 EXPECTED_UBUNTU_ARCH="i686"
18 ACCEPTED_UBUNTU_ARCH="i686"
19
20 colorize() {
21   color="$1" ; shift ; data="$@"
22   if [ "${color}" = "green" ] ; then
23     data="\033[1;32m${data}\033[m"
24   elif [ "${color}" = "red" ] ; then
25     data="\033[1;31m${data}\033[m"
26   fi
27   echo "${data}"
28 }
29
30 display_host() {
31   name="$1" ; dist="$2" ; version="$3" ; arch="$4"
32   if [ "${dist}" = "Ubuntu" ] ; then
33     expected_version="${EXPECTED_UBUNTU_VERSION}"
34     accepted_version="${ACCEPTED_UBUNTU_VERSION}"
35     expected_arch="${EXPECTED_UBUNTU_ARCH}"
36     accepted_arch="${ACCEPTED_UBUNTU_ARCH}"
37   elif [ "${dist}" = "Debian" ] ; then
38     expected_version="${EXPECTED_DEBIAN_VERSION}"
39     accepted_version="${ACCEPTED_DEBIAN_VERSION}"
40     expected_arch="${EXPECTED_DEBIAN_ARCH}"
41     accepted_arch="${ACCEPTED_DEBIAN_ARCH}"
42   else
43     echo 'Système non reconnu !'
44   fi
45   if [ "${version}" = "${expected_version}" ] ; then
46     version="`colorize green "$version"`"
47   elif [ "${version}" != "${accepted_version}" ] ; then
48     version="`colorize red "$version"`"
49   fi
50   if [ "$arch" = "${expected_arch}" ] ; then
51     arch="`colorize green "$arch"`"
52   elif [ "$arch" != "${accepted_arch}" ] ; then
53     arch="`colorize red "$arch"`"
54   fi
55   printf "%-25s: %s %s (%s)\n" "${name}" "${dist}" "${version}" "${arch}"
56 }
57
58 display_host "CT 0 (host)" "`lsb_release -si`" "`lsb_release -sr`" "`uname -m`"
59 if test -x /usr/sbin/vzctl
60 then
61   IDS="`vzlist -H -o ctid`"
62   if [ -n "$IDS" ] ; then
63     for id in $IDS
64     do
65       name="`sed -n '/^NAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
66       if [ -n "${name}" ] ; then
67         name="`sed -n '/^HOSTNAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
68       fi
69       display_host "CT ${id} (${name})" "`vzctl exec ${id} lsb_release -si`" "`vzctl exec ${id} lsb_release -sr`" "`vzctl exec ${id} uname -m`"
70     done
71   fi
72 fi