sysadmin : ajout d'un affichage des objectifs.
[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 29
3c2d786c
P
30color_name_to_code() {
31 case "$1" in
32 black) printf "0" ;;
33 red) printf "1" ;;
34 green) printf "2" ;;
35 yellow) printf "3" ;;
36 blue) printf "4" ;;
37 magenta) printf "5" ;;
38 cyan) printf "6" ;;
39 white) printf "7" ;;
40 *) printf "" ;;
41 esac
42}
43
3dfbcf57 44colorize() {
3c2d786c
P
45 # syntax: colorize [bright] [bg color_name] color_name text
46 ansi_seq=""
47 if [ "$1" = "bright" ] ; then
48 shift ; ansi_seq="${ansi_seq}1;"
49 fi
50 if [ "$1" = "bg" ] ; then
51 shift ; bg="`color_name_to_code "$1"`" ; shift
52 if [ "${bg}" != "" ] ; then
53 ansi_seq="${ansi_seq}4${bg};"
54 fi
55 fi
56 fg="`color_name_to_code "$1"`" ; shift
57 if [ "${fg}" != "" ] ; then
58 ansi_seq="${ansi_seq}3${fg}"
59 fi
60 text="$@"
61 if [ "${ansi_seq}" != "" ] ; then
62 text="\033[${ansi_seq}m${text}\033[m"
3dfbcf57 63 fi
3c2d786c 64 printf "${text}"
3dfbcf57
P
65}
66
67display_host() {
32b05cd2 68 name="$1" ; dist="$2" ; version="$3" ; arch="$4" ; note="$5"
3c2d786c 69 goals=""
3dfbcf57
P
70 if [ "${dist}" = "Ubuntu" ] ; then
71 expected_version="${EXPECTED_UBUNTU_VERSION}"
72 accepted_version="${ACCEPTED_UBUNTU_VERSION}"
73 expected_arch="${EXPECTED_UBUNTU_ARCH}"
74 accepted_arch="${ACCEPTED_UBUNTU_ARCH}"
75 elif [ "${dist}" = "Debian" ] ; then
76 expected_version="${EXPECTED_DEBIAN_VERSION}"
77 accepted_version="${ACCEPTED_DEBIAN_VERSION}"
78 expected_arch="${EXPECTED_DEBIAN_ARCH}"
79 accepted_arch="${ACCEPTED_DEBIAN_ARCH}"
80 else
3c2d786c
P
81 dist="`colorize bright red "${dist}"`"
82 goals="${goals} Debian"
3dfbcf57
P
83 fi
84 if [ "${version}" = "${expected_version}" ] ; then
3c2d786c
P
85 version="`colorize bright green "${version}"`"
86 else
87 goals="${goals} ${expected_version}"
88 if [ "${version}" != "${accepted_version}" ] ; then
89 version="`colorize bright red "${version}"`"
90 fi
3dfbcf57 91 fi
dcb997da 92 if [ "${arch}" = "${expected_arch}" ] ; then
3c2d786c
P
93 arch="`colorize bright green "${arch}"`"
94 else
95 goals="${goals} ${expected_arch}"
96 if [ "${arch}" != "${accepted_arch}" ] ; then
97 arch="`colorize bright red "${arch}"`"
98 fi
3dfbcf57 99 fi
32b05cd2
P
100 if [ "${note}" = "voip" ] ; then
101 if [ "${version}" = "${accepted_version}" ] ; then
3c2d786c 102 version="`colorize bright green "${version}"`"
32b05cd2 103 fi
3c2d786c 104 goals=""
32b05cd2
P
105 note='ne pas migrer vers Squeeze !'
106 fi
107 if expr match "${note}" '.*!' >/dev/null ; then
3c2d786c
P
108 note="`colorize bright red "${note}"`"
109 fi
110 if [ "${goals}" != "" ] ; then
111 goals="`colorize bright blue "${goals}"`"
112 note="${note} (but :${goals})"
32b05cd2
P
113 fi
114 printf "%-25s: %s %s (%s) %s\n" "${name}" "${dist}" "${version}" "${arch}" "${note}"
3dfbcf57
P
115}
116
32b05cd2 117display_host "host" "`lsb_release -si`" "`lsb_release -sr`" "`uname -m`"
3dfbcf57
P
118if test -x /usr/sbin/vzctl
119then
120 IDS="`vzlist -H -o ctid`"
dcb997da
P
121 if [ -n "${IDS}" ] ; then
122 for id in ${IDS}
3dfbcf57 123 do
32b05cd2 124 note=""
3dfbcf57 125 name="`sed -n '/^NAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
d13e6214 126 if [ -z "${name}" ] ; then
3dfbcf57
P
127 name="`sed -n '/^HOSTNAME=/s/^.*="\?\([^"]*\)"\?.*$/\1/p' /etc/vz/conf/${id}.conf`"
128 fi
d13e6214 129 dist="`vzctl exec ${id} lsb_release -si 2>/dev/null`"
dcb997da
P
130 if [ -n "${dist}" ] ; then
131 version="`vzctl exec ${id} lsb_release -sr 2>/dev/null`"
132 else
32b05cd2
P
133 dist="------"
134 version="-----"
135 note='paquet lsb-release manquant !'
dcb997da 136 fi
d13e6214 137 arch="`vzctl exec ${id} uname -m`"
32b05cd2
P
138 if [ -x "/var/lib/vz/private/${id}/usr/sbin/asterisk" ] ; then
139 note="voip"
140 fi
141 display_host "CT ${id} (${name})" "${dist}" "${version}" "${arch}" "${note}"
3dfbcf57
P
142 done
143 fi
144fi