sysadmin : ajout d'un affichage des objectifs.
authorProgfou <jean-christophe.andre@auf.org>
Fri, 9 Sep 2011 05:34:01 +0000 (12:34 +0700)
committerProgfou <jean-christophe.andre@auf.org>
Fri, 9 Sep 2011 05:34:01 +0000 (12:34 +0700)
sysadmin/sysadmin-check-version-arch

index 165bb86..d24fe76 100755 (executable)
@@ -27,18 +27,46 @@ else # serveur sous Ubuntu
   ACCEPTED_UBUNTU_ARCH="${ACCEPTED_DEBIAN_ARCH}"
 fi
 
+color_name_to_code() {
+  case "$1" in
+    black)   printf "0" ;;
+    red)     printf "1" ;;
+    green)   printf "2" ;;
+    yellow)  printf "3" ;;
+    blue)    printf "4" ;;
+    magenta) printf "5" ;;
+    cyan)    printf "6" ;;
+    white)   printf "7" ;;
+    *)       printf ""  ;;
+  esac
+}
+
 colorize() {
-  color="$1" ; shift ; data="$@"
-  if [ "${color}" = "green" ] ; then
-    data="\033[1;32m${data}\033[m"
-  elif [ "${color}" = "red" ] ; then
-    data="\033[1;31m${data}\033[m"
+  # syntax: colorize [bright] [bg color_name] color_name text
+  ansi_seq=""
+  if [ "$1" = "bright" ] ; then
+    shift ; ansi_seq="${ansi_seq}1;"
+  fi
+  if [ "$1" = "bg" ] ; then
+    shift ; bg="`color_name_to_code "$1"`" ; shift
+    if [ "${bg}" != "" ] ; then
+      ansi_seq="${ansi_seq}4${bg};"
+    fi
+  fi
+  fg="`color_name_to_code "$1"`" ; shift
+  if [ "${fg}" != "" ] ; then
+      ansi_seq="${ansi_seq}3${fg}"
+  fi
+  text="$@"
+  if [ "${ansi_seq}" != "" ] ; then
+    text="\033[${ansi_seq}m${text}\033[m"
   fi
-  printf "${data}"
+  printf "${text}"
 }
 
 display_host() {
   name="$1" ; dist="$2" ; version="$3" ; arch="$4" ; note="$5"
+  goals=""
   if [ "${dist}" = "Ubuntu" ] ; then
     expected_version="${EXPECTED_UBUNTU_VERSION}"
     accepted_version="${ACCEPTED_UBUNTU_VERSION}"
@@ -50,26 +78,38 @@ display_host() {
     expected_arch="${EXPECTED_DEBIAN_ARCH}"
     accepted_arch="${ACCEPTED_DEBIAN_ARCH}"
   else
-    dist="`colorize red "${dist}"`"
+    dist="`colorize bright red "${dist}"`"
+    goals="${goals} Debian"
   fi
   if [ "${version}" = "${expected_version}" ] ; then
-    version="`colorize green "${version}"`"
-  elif [ "${version}" != "${accepted_version}" ] ; then
-    version="`colorize red "${version}"`"
+    version="`colorize bright green "${version}"`"
+  else
+    goals="${goals} ${expected_version}"
+    if [ "${version}" != "${accepted_version}" ] ; then
+      version="`colorize bright red "${version}"`"
+    fi
   fi
   if [ "${arch}" = "${expected_arch}" ] ; then
-    arch="`colorize green "${arch}"`"
-  elif [ "${arch}" != "${accepted_arch}" ] ; then
-    arch="`colorize red "${arch}"`"
+    arch="`colorize bright green "${arch}"`"
+  else
+    goals="${goals} ${expected_arch}"
+    if [ "${arch}" != "${accepted_arch}" ] ; then
+      arch="`colorize bright red "${arch}"`"
+    fi
   fi
   if [ "${note}" = "voip" ] ; then
     if [ "${version}" = "${accepted_version}" ] ; then
-      version="`colorize green "${version}"`"
+      version="`colorize bright green "${version}"`"
     fi
+    goals=""
     note='ne pas migrer vers Squeeze !'
   fi
   if expr match "${note}" '.*!' >/dev/null ; then
-    note="`colorize red "${note}"`"
+    note="`colorize bright red "${note}"`"
+  fi
+  if [ "${goals}" != "" ] ; then
+    goals="`colorize bright blue "${goals}"`"
+    note="${note} (but :${goals})"
   fi
   printf "%-25s: %s %s (%s) %s\n" "${name}" "${dist}" "${version}" "${arch}" "${note}"
 }