Mise à jour du script de vérification version/arch.
[progfou.git] / sysadmin / sysadmin-check-version-arch
CommitLineData
3dfbcf57
P
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
d13e6214 8# Mise à jour : 2011-04-28
3dfbcf57
P
9
10EXPECTED_DEBIAN_VERSION="6.0.1"
11ACCEPTED_DEBIAN_VERSION="5.0.8"
d13e6214
P
12if grep -qE ' Intel.* Xeon| AMD.* Opteron' /proc/cpuinfo ; then
13 EXPECTED_DEBIAN_ARCH="x86_64"
14 ACCEPTED_DEBIAN_ARCH="i686"
15else
16 EXPECTED_DEBIAN_ARCH="i686"
17 ACCEPTED_DEBIAN_ARCH="i686"
18fi
3dfbcf57
P
19
20EXPECTED_UBUNTU_VERSION="10.04"
21ACCEPTED_UBUNTU_VERSION="10.04"
22EXPECTED_UBUNTU_ARCH="i686"
23ACCEPTED_UBUNTU_ARCH="i686"
24
25colorize() {
26 color="$1" ; shift ; data="$@"
27 if [ "${color}" = "green" ] ; then
28 data="\033[1;32m${data}\033[m"
29 elif [ "${color}" = "red" ] ; then
30 data="\033[1;31m${data}\033[m"
31 fi
d13e6214 32 printf "${data}"
3dfbcf57
P
33}
34
35display_host() {
36 name="$1" ; dist="$2" ; version="$3" ; arch="$4"
37 if [ "${dist}" = "Ubuntu" ] ; then
38 expected_version="${EXPECTED_UBUNTU_VERSION}"
39 accepted_version="${ACCEPTED_UBUNTU_VERSION}"
40 expected_arch="${EXPECTED_UBUNTU_ARCH}"
41 accepted_arch="${ACCEPTED_UBUNTU_ARCH}"
42 elif [ "${dist}" = "Debian" ] ; then
43 expected_version="${EXPECTED_DEBIAN_VERSION}"
44 accepted_version="${ACCEPTED_DEBIAN_VERSION}"
45 expected_arch="${EXPECTED_DEBIAN_ARCH}"
46 accepted_arch="${ACCEPTED_DEBIAN_ARCH}"
47 else
dcb997da 48 dist="`colorize red "${dist}"`"
3dfbcf57
P
49 fi
50 if [ "${version}" = "${expected_version}" ] ; then
dcb997da 51 version="`colorize green "${version}"`"
3dfbcf57 52 elif [ "${version}" != "${accepted_version}" ] ; then
dcb997da 53 version="`colorize red "${version}"`"
3dfbcf57 54 fi
dcb997da
P
55 if [ "${arch}" = "${expected_arch}" ] ; then
56 arch="`colorize green "${arch}"`"
57 elif [ "${arch}" != "${accepted_arch}" ] ; then
58 arch="`colorize red "${arch}"`"
3dfbcf57
P
59 fi
60 printf "%-25s: %s %s (%s)\n" "${name}" "${dist}" "${version}" "${arch}"
61}
62
63display_host "CT 0 (host)" "`lsb_release -si`" "`lsb_release -sr`" "`uname -m`"
64if test -x /usr/sbin/vzctl
65then
66 IDS="`vzlist -H -o ctid`"
dcb997da
P
67 if [ -n "${IDS}" ] ; then
68 for id in ${IDS}
3dfbcf57
P
69 do
70 name="`sed -n '/^NAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
d13e6214 71 if [ -z "${name}" ] ; then
3dfbcf57
P
72 name="`sed -n '/^HOSTNAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
73 fi
d13e6214 74 dist="`vzctl exec ${id} lsb_release -si 2>/dev/null`"
dcb997da
P
75 if [ -n "${dist}" ] ; then
76 version="`vzctl exec ${id} lsb_release -sr 2>/dev/null`"
77 else
78 dist="(paquet lsb-release manquant)"
79 version="???"
80 fi
d13e6214
P
81 arch="`vzctl exec ${id} uname -m`"
82 display_host "CT ${id} (${name})" "${dist}" "${version}" "${arch}"
3dfbcf57
P
83 done
84 fi
85fi