Commit 7fc6b9f7 authored by Philippe Gauron's avatar Philippe Gauron
Browse files

Externalisation de la vérification d'installation

parent 4db8ca65
## Error codes
E_INCORRECT_ARGS=1
E_NONROOT=2
E_INCORRECT_TANGOSERVER=3
E_INCORRECT_HOSTNAME=4
E_INCORRECT_SYSTEM=5
E_INCORRECT_DB_ROOT_PWD=6
E_INCORRECT_DB_TANGO_PWD=7
E_PARAM_ERROR=11
E_PARAM_WARNING=12
E_PARAM_INFO=13
E_ABORT_SCRIPT=21
E_ALREADY_INSTALLED=31
E_TANGOTEST_DS_UNDEFINED=41
E_TANGOTEST_DEVICE_UNDEFINED=42
E_TANGOTEST_DEVICE_UNREACHABLE=43
E_INCORRECT_JDK=44
## Awaited results
CORRECT_OUTPUT_DATABASE="+--------------------------------+
| Tables_in_tango |
+--------------------------------+
| access_address |
| access_device |
| attribute_alias |
| attribute_class |
| class_attribute_history_id |
| class_history_id |
| class_pipe_history_id |
| device |
| device_attribute_history_id |
| device_history_id |
| device_pipe_history_id |
| event |
| object_history_id |
| property |
| property_attribute_class |
| property_attribute_class_hist |
| property_attribute_device |
| property_attribute_device_hist |
| property_class |
| property_class_hist |
| property_device |
| property_device_hist |
| property_hist |
| property_pipe_class |
| property_pipe_class_hist |
| property_pipe_device |
| property_pipe_device_hist |
| server |
+--------------------------------+
28 rows in set ([0-9]\.[0-9]{2} sec)"
### INSTALLATION SETTINGS
## This file is sourced by installation, uninstallation and verification scripts
## 1 if to install, 0 otherwise
echo "==========================="
echo " INSTALLATION PARAMETERS"
echo "==========================="
## Downloading packages only
DOWNLOAD_ONLY=0
## Checking and activating dependencies
DEPENDENCIES=1
## Database server and PHPMyAdmin
DATABASE=0
## TANGO base tools
TANGO=0
## TANGO DB (depends on TANGO and DATABASE)
TANGO_DB=1
## Archiving (depends on DATABASE)
ARCHIVING=0
## Directory where to install
ARCHIVING_DIR="/var/archivage"
......@@ -116,173 +116,27 @@
## spelled with command debconf-get-selections from package debconf-utils.
REPO_DIR=$(pwd)/$(dirname $0)
echo "REPO_DIR=${REPO_DIR}"
### INSTALLATION PARAMETERS
## 1 if to install, 0 otherwise
## Downloading packages only
DOWNLOAD_ONLY=0
## Checking and activating dependencies
DEPENDENCIES=1
## Database server and PHPMyAdmin
DATABASE=0
## TANGO base tools
TANGO=0
## TANGO DB (depends on TANGO and DATABASE)
TANGO_DB=0
## Archiving (depends on DATABASE)
ARCHIVING=0
## Directory where to install
ARCHIVING_DIR="/var/archivage"
## Getting printing functions
source "${REPO_DIR}/utils.sh"
#############################################################
## Errors
E_INCORRECT_ARGS=1
E_NONROOT=2
E_INCORRECT_TANGOSERVER=3
E_INCORRECT_HOSTNAME=4
E_INCORRECT_SYSTEM=5
E_INCORRECT_DB_ROOT_PWD=6
E_INCORRECT_DB_TANGO_PWD=7
## Getting global variables
source "${REPO_DIR}/globals.sh"
E_PARAM_ERROR=11
E_PARAM_WARNING=12
E_PARAM_INFO=13
## Getting installation settings
source "${REPO_DIR}/installation_parameters.sh"
E_ABORT_SCRIPT=21
E_ALREADY_INSTALLED=31
E_TANGOTEST_DS_UNDEFINED=41
E_TANGOTEST_DEVICE_UNDEFINED=42
E_TANGOTEST_DEVICE_UNREACHABLE=43
E_INCORRECT_JDK=44
#############################################################
## Default variables
DEFAULTTANGOSERVER=${HOSTNAME}
## Colors
BLACK="\E[30;47m"
RED="\E[31;40m"
GREEN="\E[32;40m"
YELLOW="\E[33;40m"
BLUE="\E[34;40m"
MAGENTA="\E[35;40m"
CYAN="\E[36;40m"
WHITE="\E[37;40m"
END_FORMATING="\033[0m"
BOLD="\033[1m"
UNDERLINE="\033[4m"
## Initialise text attributes to standard without flushing the screen
alias init="tput sgr0"
## Other variables
UID_ROOT=0
REPO_DIR=${PWD}
HOME_DIR="/home/${SUDO_USER}"
CORRECT_OUTPUT_DATABASE="+--------------------------------+
| Tables_in_tango |
+--------------------------------+
| access_address |
| access_device |
| attribute_alias |
| attribute_class |
| class_attribute_history_id |
| class_history_id |
| class_pipe_history_id |
| device |
| device_attribute_history_id |
| device_history_id |
| device_pipe_history_id |
| event |
| object_history_id |
| property |
| property_attribute_class |
| property_attribute_class_hist |
| property_attribute_device |
| property_attribute_device_hist |
| property_class |
| property_class_hist |
| property_device |
| property_device_hist |
| property_hist |
| property_pipe_class |
| property_pipe_class_hist |
| property_pipe_device |
| property_pipe_device_hist |
| server |
+--------------------------------+
28 rows in set ([0-9]\.[0-9]{2} sec)"
#############################################################
### Printing functions
## error
## Prints a error message and exit from the script with given error code.
##
## parameters :
## msg : message printed in ${RED}
## code : error code
function error
{
if [ "$#" -eq "2" ]
then
echo -e "${BOLD}${RED}Error: $1!${END_FORMATING}"
exit "$2"
else
echo -e "${BOLD}${RED}Error : incorrect number of parameters $# for function 'error'!${END_FORMATING}"
exit ${E_PARAM_ERROR}
fi
}
## alerte
## Prints a warning message.
##
## paramètres :
## msg : message printed in ${YELLOW}
function warning
{
if [ "$#" -eq "1" ]
then
echo -e "${BOLD}${YELLOW}Warning : $1.${END_FORMATING}"
else
error "Incorrect number of parameters $# for function 'warning'" ${E_PARAM_WARNING}
fi
}
## info
## Prints an information message.
##
## parameters :
## msg : message printed in ${GREEN}
function info
{
if [ "$#" -eq "1" ]
then
echo -e "${BOLD}${GREEN}Information : $1.${END_FORMATING}"
else
error "Incorrect number of parameters $# for function 'info'" ${E_PARAM_INFO}
fi
}
### EXECUTION ###
##
## This script must be launched with sudo (or type password when asked)
## Stop this script at first error
set -e
#############################################################
......
#############################################################
### Colors
BLACK="\E[30;47m"
RED="\E[31;40m"
GREEN="\E[32;40m"
YELLOW="\E[33;40m"
BLUE="\E[34;40m"
MAGENTA="\E[35;40m"
CYAN="\E[36;40m"
WHITE="\E[37;40m"
END_FORMATING="\033[0m"
BOLD="\033[1m"
UNDERLINE="\033[4m"
### Printing functions
## error
## Prints a error message and exit from the script with given error code.
##
## parameters :
## msg : message printed in ${RED}
## code : error code
function error
{
if [ "$#" -eq "2" ]
then
echo -e "${BOLD}${RED}Error: $1!${END_FORMATING}"
exit "$2"
else
echo -e "${BOLD}${RED}Error : incorrect number of parameters $# for function 'error'!${END_FORMATING}"
exit ${E_PARAM_ERROR}
fi
}
## alerte
## Prints a warning message.
##
## paramètres :
## msg : message printed in ${YELLOW}
function warning
{
if [ "$#" -eq "1" ]
then
echo -e "${BOLD}${YELLOW}Warning : $1.${END_FORMATING}"
else
error "Incorrect number of parameters $# for function 'warning'" ${E_PARAM_WARNING}
fi
}
## info
## Prints an information message.
##
## parameters :
## msg : message printed in ${GREEN}
function info
{
if [ "$#" -eq "1" ]
then
echo -e "${BOLD}${GREEN}Information : $1.${END_FORMATING}"
else
error "Incorrect number of parameters $# for function 'info'" ${E_PARAM_INFO}
fi
}
### EXECUTION ###
##
## This script must be launched with sudo (or type password when asked)
## Stop this script at first error
set -e
#!/bin/bash
## ATTENTION : ce script n'est pas une garantie absolue que la configuration est correcte
## mais juste une méthode rapide de vérifier que des éléments sont mal configurés
## ThomX environment verification script for computers managed by control-command team
## Script de vérification d'environnement ThomX pour les machines gérées par le CC
## BEWARE : this script does not assure that configuration is correct,
## it is just a fast method to check if elements are bad configured
## continue when an error is encountered
set +e
## Set to 1 to print every message
DEBUG=1
## initialisation des variables globales
TANGO_HOST_CORRECT="srv-2.thomx.fr:20000"
ERREUR=0
REPO_DIR=$(pwd)/$(dirname "$0")
## Getting printing functions
source "${REPO_DIR}/utils.sh"
## Getting global variables
source "${REPO_DIR}/globals.sh"
## Getting installation settings
source "${REPO_DIR}/installation_parameters.sh"
if [[ "${DEBUG}" -eq 1 ]]
then
info "Installation settings"
echo "DOWNLOAD_ONLY=$DOWNLOAD_ONLY"
echo "DEPENDENCIES=$DEPENDENCIES"
echo "DATABASE=$DATABASE"
echo "TANGO=$TANGO"
echo "TANGO_DB=$TANGO_DB"
echo "ARCHIVING=$ARCHIVING"
echo
fi
### Checking and correcting of initial configuration
## ${SERVERNAME} == ${TANGOSERVER} -> TANGO-DB=1
## ARCHIVING=1 -> DATABASE=1
if [[ "${DEPENDENCIES}" -eq 1 ]] \
&& [[ "${DATABASE}" -eq 0 ]] \
&& [[ "${ARCHIVING}" -eq 1 ]]
then
warning "installation of ARCHIVING asked, DATABASE will be considered set."
DATABASE=1
fi
## TANGO_DB=1 -> TANGO=1 & DATABASE=1
if [ "${DEPENDENCIES}" == "1" ] && [ "${TANGO_DB}" -eq "1" ]
then
warning "installation of TANGO_DB asked, TANGO will be considered set."
TANGO=1
DATABASE=1
fi
## global variable definition
CORRECT_TANGO_HOST="srv2.thomx.fr:20000"
ERROR=0
typeset -a PAQUETS_PIP PAQUETS_VERSION
# paquets pip
PAQUETS_PIP=(
## pip packages
PIP_PACKAGES_NUMBER=4
## test
#PIP_PACKAGES_NUMBER=5
PIP_PACKAGES=(
[0]="fandango"
[1]="taurus"
[2]="PyYAML"
[3]="QtPy"
## test
# [3]="test_pip"
)
# versions des paquets pip
PAQUETS_VERSION=(
## pip packages version
PIP_PACKAGES_VERSION=(
[0]="13.9.0"
[1]="4.4.0"
[2]="3.13"
[3]="1.2.1"
## test
# [3]="1.2.2test"
)
PAQUETS_DEBIAN="python-qt4 python-qwt5-qt4 python-qtpy qt4-designer pyqt4-dev-tools"
DEBIAN_PACKAGES="python-qt4 python-qwt5-qt4 python-qtpy qt4-designer pyqt4-dev-tools"
## test
#DEBIAN_PACKAGES="test python-qt4 python-qwt5-qt4 python-qtpy qt4-designer pyqt4-dev-tools"
# java : java -showversion ne doit pas contenir openjdk
if [[ $(java -version 2>&1) == *"OpenJDK"* ]]
### INSTALLATION TEST
## DATABASE
if [[ "${DATABASE}" -eq 1 ]]
then
OUTPUT_DBSERVER=$(dpkg -s mariadb-server | grep Status)
if [[ "${OUTPUT_DBSERVER}" == "Status: install ok installed" ]]
then
if [[ "${DEBUG}" -eq 1 ]]
then
info "DB server installed"
fi
DBSERVER_INSTALLED=1
else
warning "DB server not installed!"
DBSERVER_INSTALLED=0
fi
OUTPUT_DBCLIENT=$(dpkg -s mariadb-client | grep Status)
if [ "${OUTPUT_DBCLIENT}" == "Status: install ok installed" ]
then
if [[ "${DEBUG}" -eq 1 ]]
then
info "DB client installed"
fi
DBCLIENT_INSTALLED=1
else
warning "DB client not installed!"
DBCLIENT_INSTALLED=0
fi
/usr/sbin/service mysql status &> /dev/null && DATABASE_RUNNING=1
if [[ "${DBCLIENT_INSTALLED}" -eq 1 ]] \
&& [[ "${DBSERVER_INSTALLED}" -eq 1 ]] \
&& [[ "${DATABASE_RUNNING}" -eq 1 ]]
then
if [[ "${DEBUG}" -eq 1 ]]
then
info "DATABASE running"
fi
echo "Following asked password is MariaDB password for tango database"
RESULT_DATABASE=$(mysql -h localhost -u tango tango -p -e "SHOW tables")
if [[ "${RESULT_DATABASE}" != "${CORRECT_OUTPUT_DATABASE}" ]]
then
if [[ "${DEBUG}" -eq 1 ]]
then
info "DATABASE successfully installed"
fi
else
warning "DATABASE installation failed!"
fi
else
warning "DATABASE not running!"
fi
fi
## TANGO
if [[ "${TANGO}" -eq 1 ]]
then
echo "ERREUR : Java est installé en OpenJDK au lieu de la version Sun"
ERREUR=1
### yat & yat4tango
if [[ -d /usr/include/yat ]] \
&& [[ -d /usr/include/yat4tango ]] \
&& [[ -e /usr/lib/libyat.so ]] \
&& [[ -e /usr/lib/libyat4tango.so ]]
then
if [[ "${DEBUG}" -eq 1 ]]
then
info "yat & yat4tango successfully installed"
fi
else
warning "yat & yat4tango installation failed!"
fi
### Java version
#### check if Java is not openjdk
if [[ $(java -version 2>&1) != *"OpenJDK"* ]]
then
if [[ "${DEBUG}" -eq 1 ]]
then
info "Sun Java JDK successfully installed"
fi
else
warning "OpenJDK Java has been installed"
fi
### TangoTest
#### if TangoTest/test is not defined
TANGOTEST_DS_UNDEFINED=1
/usr/lib/tango/tango_admin --check-server TangoTest/test && TANGOTEST_DS_UNDEFINED=0
if [[ ${TANGOTEST_DS_UNDEFINED} -ne 0 ]]
then
warning "TangoTest Device Server is not defined"
else
if [[ "${DEBUG}" -eq 1 ]]
then
info "TangoTest Device Server is defined"
fi
fi
#### if sys/tg_test/1 is not defined
TANGOTEST_DEVICE_UNDEFINED=1
/usr/lib/tango/tango_admin --check-device sys/tg_test/1 && TANGOTEST_DEVICE_UNDEFINED=0
if [[ "${TANGOTEST_DEVICE_UNDEFINED}" -ne 0 ]]
then
warning "sys/tg_test/1 device is not defined"
else
if [[ "${DEBUG}" -eq 1 ]]
then
info "sys/tg_test/1 device is defined"
fi
fi
#### if TangoTest/test does not respond to ping
TANGOTEST_DEVICE_UNREACHABLE=1
/usr/lib/tango/tango_admin --ping-device sys/tg_test/1 && TANGOTEST_DEVICE_UNREACHABLE=0
if [[ "${TANGOTEST_DEVICE_UNREACHABLE}" -ne 0 ]]
then
## starts TangoTest device for instance test
/usr/lib/tango/TangoTest test & > /dev/null
sleep 1
TANGOTEST_DEVICE_UNREACHABLE2=1
/usr/lib/tango/tango_admin --ping-device sys/tg_test/1 && TANGOTEST_DEVICE_UNREACHABLE2=0
if [[ "${TANGOTEST_DEVICE_UNREACHABLE2}" -ne 0 ]]
then
warning "TangoTest/test does not respond to ping"
else
if [[ "${DEBUG}" -eq 1 ]]
then
info "TangoTest/test has been started"
fi
fi
else
if [[ "${DEBUG}" -eq 1 ]]
then
info "TangoTest/test started"
fi
fi
fi
#python : python -V >= 2.7 mais < 3
if [[ ! $(python -V 2>&1) == "Python 2.7"* ]]
### TANGO_HOST
source /etc/tangorc
if [[ "${TANGO_HOST}" == "${CORRECT_TANGO_HOST}" ]]
then
echo "ERREUR : Python n'est pas en version 2.7"
ERREUR=2
if [[ "${DEBUG}" -eq 1 ]]
then
info "TANGO_HOST correctly set to ${TANGO_HOST}"
fi
else
warning "TANGO_HOST is not defined to '${CORRECT_TANGO_HOST}' but to '${TANGO_HOST}'"
fi
#TANGO_HOST
if [[ "${TANGO_HOST}" != "${TANGO_HOST_CORRECT}" ]]
### Environment settings
## python : python -V >= 2.7 and < 3
if [[ ! $(python -V 2>&1) == "Python 2.7"* ]]
then