verif_env_thomx.sh 8.08 KB
Newer Older
1 2
#!/bin/bash

3
## ThomX environment verification script for computers managed by control-command team
4

5 6
## BEWARE : this script does not assure  that configuration is correct, 
## it is just a fast method to check if elements are bad configured
7

8 9
## continue when an error is encountered
set +e
10

11 12
## Set to 1 to print every message
DEBUG=1
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
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
70
CORRECT_TANGO_HOST="srv-2.thomx.fr:20000"
71
ERROR=0
72
typeset -a PAQUETS_PIP PAQUETS_VERSION
73 74 75 76 77
## pip packages
PIP_PACKAGES_NUMBER=4
## test
#PIP_PACKAGES_NUMBER=5
PIP_PACKAGES=(
78 79 80 81
  [0]="fandango"
  [1]="taurus"
  [2]="PyYAML"
  [3]="QtPy"
82 83
## test
#   [3]="test_pip"
84
)
85 86
## pip packages version
PIP_PACKAGES_VERSION=(
87 88 89 90
  [0]="13.9.0"
  [1]="4.4.0"
  [2]="3.13"
  [3]="1.2.1"
91 92
## test
#  [3]="1.2.2test"
93
)
94 95 96 97 98
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"


99

100 101


102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163



### 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 ]]
164
then
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
  ### 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
244 245 246
fi


247 248 249 250

### TANGO_HOST
source /etc/tangorc
if [[ "${TANGO_HOST}" == "${CORRECT_TANGO_HOST}" ]]
251
then
252 253 254 255 256 257
  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}'"
258 259 260
fi


261 262 263 264 265 266 267 268 269 270






### Environment settings

## python : python -V >= 2.7 and < 3
if [[ ! $(python -V 2>&1) == "Python 2.7"* ]] 
271
then
272 273 274 275 276 277 278
  warning "Python is not installed in version 2.7"
  ERREUR=2
else
  if [[ "${DEBUG}" -eq 1 ]]
  then
    info "Python is not in version 2.7"
  fi
279 280
fi

281 282 283 284

## Check package installation of packages needed for taurus
## fandango==13.9.0 taurus==4.4.0 PyYAML==3.13 QtPy==1.2.1 python-qt4 python-qwt5-qt4 python-qtpy qt4-designer pyqt4-dev-tools
for ((package=0;package<${PIP_PACKAGES_NUMBER}; package++))
285
do
286 287 288
  PIP_PACKAGE_NOT_INSTALLED=1
  PIP_COMMAND=$(pip show "${PIP_PACKAGES[$package]}") && PIP_PACKAGE_NOT_INSTALLED=0
  if [[ "${PIP_PACKAGE_NOT_INSTALLED}" -ne 0 ]]
289
  then
290
    warning "pip package ${PIP_PACKAGES[$package]} is not installed"
291
  else
292 293 294
    COMMAND_VERSION_INCORRECT=1
    echo "${PIP_COMMAND}" | grep "${PIP_PACKAGES_VERSION[$package]}" > /dev/null && COMMAND_VERSION_INCORRECT=0
    if [[ "${COMMAND_VERSION_INCORRECT}" -ne 0 ]]
295
    then
296 297 298 299 300 301
      warning "pip package ${PIP_PACKAGES[$package]} is not installed  with version ${PIP_PACKAGES_VERSION[$package]}"
    else 
      if [[ "${DEBUG}" -eq 1 ]]
      then
        info "pip package ${PIP_PACKAGES[$package]} is installed with version ${PIP_PACKAGES_VERSION[$package]}"
      fi
302 303 304
    fi
  fi
done
305 306 307

## Checking debian packages installation
for package in ${DEBIAN_PACKAGES}
308
do
309 310
  DEBIAN_PACKAGE_NOT_INSTALLED=1
  $(dpkg -l | grep ^ii | grep "${package} " > /dev/null) && DEBIAN_PACKAGE_NOT_INSTALLED=0
311 312
  if [[ "$?" -ne 0 ]]
  then
313 314 315 316 317 318
    warning "debian package ${package} is not installed"
  else
    if [[ "${DEBUG}" -eq 1 ]]
    then
      info "debian package ${package} is installed"
    fi
319
  fi
320

321
done
322

323 324 325 326
## matlab : check that matlab is 2018b version
## toolbox : Hayg will define which version has to be installed
## Hayg will define what command can be used and what result should be returned

327

328
## tango-binding : Hayg will tell what command can be use and what result should be returned
329 330


331 332
## TANGO_HOST_PROD or TANGO_HOST_DEV : Hayg will tell what command 
## can be use and what result should be returned
333 334


335
# /etc/hosts
336
echo
337
echo "Contents of /etc/hosts/:"
338 339 340 341 342
echo "-----"
cat /etc/hosts
echo "-----"

# /etc/tangorc
343
echo
344
echo "Contents of /etc/tangorc/:"
345 346 347 348 349
echo "-----"
cat /etc/tangorc
echo "-----"

# atkpanel 
350
echo
351
echo "Starting sys/database/2 ATKPanel"
352
atkpanel sys/database/2
353

354 355