Mise à jour d'outils système.
[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
32b05cd2 8# Mise à jour : 2011-08-23
3dfbcf57 9
32b05cd2 10EXPECTED_DEBIAN_VERSION="6.0.2"
3dfbcf57 11ACCEPTED_DEBIAN_VERSION="5.0.8"
32b05cd2 12if grep -q '^flags.* lm ' /proc/cpuinfo ; then
d13e6214
P
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"
c95269b4
P
22if dpkg -l ubuntu-desktop >/dev/null 2>&1 ; then
23 EXPECTED_UBUNTU_ARCH="i686"
24 ACCEPTED_UBUNTU_ARCH="i686"
25else # serveur sous Ubuntu
26 EXPECTED_UBUNTU_ARCH="${EXPECTED_DEBIAN_ARCH}"
27 ACCEPTED_UBUNTU_ARCH="${ACCEPTED_DEBIAN_ARCH}"
28fi
3dfbcf57
P
29
30colorize() {
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
d13e6214 37 printf "${data}"
3dfbcf57
P
38}
39
40display_host() {
32b05cd2 41 name="$1" ; dist="$2" ; version="$3" ; arch="$4" ; note="$5"
3dfbcf57
P
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
dcb997da 53 dist="`colorize red "${dist}"`"
3dfbcf57
P
54 fi
55 if [ "${version}" = "${expected_version}" ] ; then
dcb997da 56 version="`colorize green "${version}"`"
3dfbcf57 57 elif [ "${version}" != "${accepted_version}" ] ; then
dcb997da 58 version="`colorize red "${version}"`"
3dfbcf57 59 fi
dcb997da
P
60 if [ "${arch}" = "${expected_arch}" ] ; then
61 arch="`colorize green "${arch}"`"
62 elif [ "${arch}" != "${accepted_arch}" ] ; then
63 arch="`colorize red "${arch}"`"
3dfbcf57 64 fi
32b05cd2
P
65 if [ "${note}" = "voip" ] ; then
66 if [ "${version}" = "${accepted_version}" ] ; then
67 version="`colorize green "${version}"`"
68 fi
69 note='ne pas migrer vers Squeeze !'
70 fi
71 if expr match "${note}" '.*!' >/dev/null ; then
72 note="`colorize red "${note}"`"
73 fi
74 printf "%-25s: %s %s (%s) %s\n" "${name}" "${dist}" "${version}" "${arch}" "${note}"
3dfbcf57
P
75}
76
32b05cd2 77display_host "host" "`lsb_release -si`" "`lsb_release -sr`" "`uname -m`"
3dfbcf57
P
78if test -x /usr/sbin/vzctl
79then
80 IDS="`vzlist -H -o ctid`"
dcb997da
P
81 if [ -n "${IDS}" ] ; then
82 for id in ${IDS}
3dfbcf57 83 do
32b05cd2 84 note=""
3dfbcf57 85 name="`sed -n '/^NAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
d13e6214 86 if [ -z "${name}" ] ; then
3dfbcf57
P
87 name="`sed -n '/^HOSTNAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
88 fi
d13e6214 89 dist="`vzctl exec ${id} lsb_release -si 2>/dev/null`"
dcb997da
P
90 if [ -n "${dist}" ] ; then
91 version="`vzctl exec ${id} lsb_release -sr 2>/dev/null`"
92 else
32b05cd2
P
93 dist="------"
94 version="-----"
95 note='paquet lsb-release manquant !'
dcb997da 96 fi
d13e6214 97 arch="`vzctl exec ${id} uname -m`"
32b05cd2
P
98 if [ -x "/var/lib/vz/private/${id}/usr/sbin/asterisk" ] ; then
99 note="voip"
100 fi
101 display_host "CT ${id} (${name})" "${dist}" "${version}" "${arch}" "${note}"
3dfbcf57
P
102 done
103 fi
104fi