script-install.sh 27.2 KB
Newer Older
1 2
#!/bin/bash

gauron's avatar
gauron committed
3 4 5 6 7 8 9 10 11 12
## SYNTAX ###
##
## Lignes of this script can be 3 types :
## - beginning with  "###" when line is doc title
## - beginning with  "##" when line is documentation
## - beginning with  "#" when line is a commented line for testing
## - beginning without any "#" when line is interpreted


### Installation of a TANGO server
13
## Based on a Debian 9
14
## script installation duration : ~ 9 to 15 minutes depending on the options
15

gauron's avatar
gauron committed
16 17 18

### Instructions to launch the script:
##
19
## 1 install OS, with an existing ${ARCHIVING_DIR} directory for archiving
20 21 22
##   installation, and on a distinct partition to avoid disk crashing 
##   if temporary files are not deleted
## 2 check that /etc/sudoers contains the main user, if not:
gauron's avatar
gauron committed
23
##   "su"
24
##   "apt install sudo"
25
##   "usermod -aG sudo [MAINUSER]"
26
##   then completely close session and open it again
27 28 29 30 31 32 33 34 35
## 3 for installing on virtual machine: 
##   a. check that /etc/apt/sources.list contains contrib
##   b. check that cdrom is removed/commented from this file if necessary
##   c. sudo apt update
##      sudo apt install build-essential module-assistant
##      sudo m-a prepare
##      Expand menu Devices and click on Insert Guest Additions CD image...
##      sudo sh /media/cdrom0/VBoxLinuxAdditions.run
##      Reboot
36
## 4 get the script ("sudo apt install git" &
37
##   "git clone https://gitlab.in2p3.fr/CCThomX/installation.git")
38
## 5 check if setxkbmap is well configured if necessary
39 40
## 6 configure the INSTALLATION PARAMETERS in the script including 
##   ARCHIVING_DIR
41
## 7 launch the script with TANGOSERVER name as parameter
42
##   ("cd installation ; sudo script-install.sh [TANGOSERVER]")
43
## 8 on distant host, install xauth package (sudo apt install xauth)
44 45 46
## 9 test:
##   * DOWNLOAD_ONLY: launching the script with the same configuration
##     should work offline 
47
##   * DATABASE: connection to MariaDB (Debian 9)
48
##     should work : this is automatically checked at the end of installation.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
##     `mysql -h localhost -u tango -p` followed by `USE tango` and then `SHOW tables;` 
##     should print following tables:
##     +--------------------------------+
##     | 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.00 sec)`
##     
85 86 87 88 89 90 91 92 93
##   * TANGO_DB: 
##     + in a terminal different from the one used to execute 
##       `./script-install.sh`, `echo ${TANGO_HOST}` should return the 
##       hostname of the TANGO server (not a Fully Qualified Domaine Name)
##     + launch `jive` should launch a window like
##       https://tango-controls.readthedocs.io/en/latest/tools-and-extensions/jive/index.html
##     + launch `atkpanel sys/database/2` should display a java window 
##       with a green status
##     + TANGO tests should be completed after those tests
94
##   * TANGO: 
95 96
##     + yat & yat4tango installation : check presence of /usr/include/yat &
##       /usr/include/yat4tango directories and libraries /usr/lib/libyat.so &
97 98
##       /usr/lib/libyat4tango.so : this is automatically checked at the end of 
##       installation
99
##     + `java -version` should not return openjdk
100
##     + test GUI:
101
##       - get IHM repo : `hg clone https://gitlab.in2p3.fr/CCThomX/IHM.git`
102 103 104 105 106 107 108 109 110
##       - launch `jive`, and check that into Server panel, 
##         TangoTest/test/TangoTest the `sys/tg_test/1` object contains 
##         `Exported: true`  with an accessible `port`
##       - if former step is not checked, launch on the server TangoTest 
##         device server with `/usr/lib/tango/TangoTest test` and check that 
##         terminal displays `Ready to accept request` 
##       - ` cd IHM/RFCanon and launch `./RF_Canon.py`, a window should appear 
##         while data changes every second
##     + configure SSH with a private key giving access to DS-LAL repo and get 
111
##       the repo `hg clone git@gitlab.in2p3.fr:CCThomX/DS-LAL.git`
112 113
##       Then build a DS.
##   * ARCHIVING: to complete by JCM
114 115 116
##
## If any issue occurs, you can check installation parameters are well 
## spelled with command debconf-get-selections from package debconf-utils.
117 118


119 120
REPO_DIR=$(pwd)/$(dirname $0)
echo "REPO_DIR=${REPO_DIR}"
121

122 123
## Getting printing functions
source "${REPO_DIR}/utils.sh"
gauron's avatar
gauron committed
124

125 126
## Getting global variables
source "${REPO_DIR}/globals.sh"
127

128 129
## Getting installation settings
source "${REPO_DIR}/installation_parameters.sh"
130 131 132



133
#############################################################
134

135
## Default variables
136
DEFAULTTANGOSERVER=${HOSTNAME}
137

138
## Other variables
139 140
UID_ROOT=0

141
#############################################################
142 143


144
### Checking parameters
145

146
## To launch as root of course
147
if [ "${EUID}" -ne "${UID_ROOT}" ]
148
then
149
  error "You must be root to launch this script" ${E_NONROOT}
150 151
fi  

152
## To launch with 1 parameter maximum
153
if [ "$#" -gt "1" ]
154
then
155
  error "To much parameters.\n\nUsage: $(basename "$0") [TANGOSERVER_name]" ${E_INCORRECT_ARGS}
156 157 158
fi


159
## Checks Operating System version
160
if [ "$(/usr/bin/lsb_release -is)" == "Debian" ]
161 162 163 164
then
  DEBIAN_VERSION=$(/usr/bin/lsb_release -cs)
  case ${DEBIAN_VERSION} in
    stretch*) DEBIAN_VERSION=9;;
165
    *) error "Operating System is not a Debian 9!" ${E_INCORRECT_SYSTEM};;
166 167 168
  esac
  echo "Debian version : ${DEBIAN_VERSION}"
else
169
  error "Operating System is not a Debian 9!" ${E_INCORRECT_SYSTEM}
170
fi
171

172 173
## Definition of the hostname (also used as user's group name)
SERVERNAME=${HOSTNAME}
174

175
info "server will be installed with name '${SERVERNAME}'"
176

177
## Definition of user's group
178
SUDO_GROUP=$(id -g -n "${SUDO_USER}")
179 180 181 182




183
## Definition of TANGOSERVER name:
184
## - "${HOSTNAME}" as default
185
## - from given parameter
186
TANGOSERVER=${1-${DEFAULTTANGOSERVER}}
187 188


189
if [ "${TANGOSERVER}" != "${SERVERNAME}" ] && [ "${TANGO_DB}" -eq "1" ]
190
then
191
  error "installation of TANGO_DB is asked but TANGOSERVER (='${TANGOSERVER}') has another name than SERVERNAME (='${SERVERNAME}')" ${E_INCORRECT_TANGOSERVER}
192 193
fi

194
info "server will be installed with TANGOSERVER '${TANGOSERVER}'"
195 196


197

198 199 200

### Checking and correcting of initial configuration

201
## ${SERVERNAME} == ${TANGOSERVER} -> TANGO-DB=1
202
if [ "${DEPENDENCIES}" -eq "1" ] \
203
   && [ "${SERVERNAME}" == "${TANGOSERVER}" ] \
204
   && [ "${TANGO_DB}" -eq "0" ]
205
then
206
  warning "${SERVERNAME} == ${TANGOSERVER}, TANGO_DB will be installed."
207 208 209
  TANGO_DB=1
fi

210
## ARCHIVING=1 -> DATABASE=1
211
if [ "${DEPENDENCIES}" -eq "1" ] && [ "${DATABASE}" -eq "0" ] && [ "${ARCHIVING}" -eq "1" ]
212
then
213 214
  warning "installation of ARCHIVING asked, DATABASE will be installed."
  DATABASE=1
215 216 217
fi


218
## TANGO_DB=1 -> TANGO=1 & DATABASE=1
219
if [ "${DEPENDENCIES}" -eq "1" ] && [ "${TANGO_DB}" -eq "1" ]
220
then
221 222 223 224 225 226 227 228 229 230
  if [ "${TANGO}" -eq "0" ]
  then
    warning "installation of TANGO_DB asked, TANGO will be installed."
    TANGO=1
  fi
  if [ "${DATABASE}" -eq "0" ]
  then
    warning "installation of TANGO_DB asked, DATABASE will be installed."
    DATABASE=1
  fi
231 232 233
fi


234
## Prints final corrected configuration
235
echo ""
236
echo "Final configuration  to install: "
237
if [ "${DATABASE}" -eq "1" ]
238
then
239
  echo "Database server and PHPMyAdmin"
240
fi
241
if [ "${TANGO}" -eq "1" ]
242 243 244
then
  echo "TANGO base tools"
fi
245
if [ "${TANGO_DB}" -eq "1" ]
246 247 248
then
  echo "TANGO DB"
fi
249
if [ "${ARCHIVING}" -eq "1" ]
250 251 252 253
then
  echo "ArchivingRoot"
fi

254

255 256


257
if [ "${DOWNLOAD_ONLY}" -eq "1" ]
258
then
259 260 261
  warning "installation will only download software and will not install anything"
else
  ## Exit if user does not confirm configuration
262 263
  read -p "Do you want to install this configuration? ([Yy]Nn) " CHOICE
  case "${CHOICE}" in
264
    y|Y ) info "Begining installation...";;
265 266
    n|N ) info "Abort installation"; exit ${E_ABORT_SCRIPT};;
    * ) info "Abort installation (invalid answer)"; exit ${E_ABORT_SCRIPT};;
267 268
  esac

269
  if [ "${DATABASE}" -eq "1" ] || [ "${TANGO_DB}" -eq "1" ] || [ "${ARCHIVING}" -eq "1" ]
270 271 272
  then
    ## Get Database root password
    echo "Please enter root password for DATABASE: "
273
    read -s DB_ROOT_PASSWORD
274 275 276
    echo "Please confirm root password for DATABASE: "
    read -s DB_ROOT_PASSWORD2
    while test "${DB_ROOT_PASSWORD}" != "${DB_ROOT_PASSWORD2}"
277
    do warning "Passwords are not equals."
278 279 280 281 282 283 284
       echo "Please enter root password for DATABASE: "
       read -s DB_ROOT_PASSWORD
       echo "Please confirm root password for DATABASE: "
       read -s DB_ROOT_PASSWORD2
    done
    echo

285 286
    echo "Please enter tango password for DATABASE: "
    read -s DB_TANGO_PASSWORD
287 288 289
    echo "Please confirm tango password for DATABASE: "
    read -s DB_TANGO_PASSWORD2
    while test "${DB_TANGO_PASSWORD}" != "${DB_TANGO_PASSWORD2}"
290
    do warning "Passwords are not equals."
291 292 293 294 295
       echo "Please enter tango password for DATABASE: "
       read -s DB_TANGO_PASSWORD
       echo "Please confirm tango password for DATABASE: "
       read -s DB_TANGO_PASSWORD2
    done
296
    MYSQL_USER=tango
297
    MYSQL_PASSWORD=${DB_TANGO_PASSWORD}
298
  fi
299

300
fi
301

302

303
## configuration AZERTY (equivalent of
gauron's avatar
gauron committed
304
## "dpkg-reconfigure keyboard-configuration", but in non-interactive mode)
305
## for PC-tower keyboard
306
#sudo setxkbmap -model pc105 -layout fr -variant latin9
307
## for flat USB Mac
308
#setxkbmap -model macintosh -layout fr
309 310
## for DELL latitude laptop
#sudo setxkbmap -model latitude -layout us
311 312 313 314




315
### Preparation of installation tools ###
316

317
## temporarly unactivate of listchanges
318
APT_LISTCHANGES_FRONTEND=none
319 320

## update of packages before installation
321
sudo apt update
322

323
## to install packages in non-interactive mode
324
DEBIAN_FRONTEND=noninteractive
325
sudo apt install --assume-yes debconf 
326 327

## to install keys for additionnal packages repository
328
sudo apt install --assume-yes dirmngr
329

330 331
# creating temporary directory for installation
mkdir -p "${REPO_DIR}/tmp"
332 333


334 335 336
#############################################################

### Downloading packages
337

Philippe Gauron's avatar
Philippe Gauron committed
338
## Common tools for all installations
339
# host, to find offline IP hosts
Philippe Gauron's avatar
Philippe Gauron committed
340
sudo apt install -d host
341 342
# git mercurial
sudo apt install --assume-yes git mercurial
343 344
# pip
sudo apt install --assume-yes python-pip
Philippe Gauron's avatar
Philippe Gauron committed
345

346
if [ "${DATABASE}" -eq "1" ]
347
then
348
  echo
Philippe Gauron's avatar
Philippe Gauron committed
349
  info "downloading software for Database server and PHPMyAdmin"
350

351
  sudo apt install -d --assume-yes mariadb-client mariadb-server phpmyadmin expect
352 353
fi

354
if [ "${TANGO_DB}" -eq "1" ]
355
then
356
  echo
Philippe Gauron's avatar
Philippe Gauron committed
357
  info "downloading software for TANGO DB"
358

359
  sudo apt install -d --assume-yes tango-db
360 361
fi

362
if [ "${ARCHIVING}" -eq "1" ]
363
then
364
  echo
Philippe Gauron's avatar
Philippe Gauron committed
365
  info "downloading software for ArchivingRoot"
366

367
  sudo apt install -d --assume-yes unzip
368
  if [ ! -f "${REPO_DIR}/tmp/ArchivingRoot-last.zip" ]
369
    then
370
      wget -c "https://owncloud.lal.in2p3.fr/public.php?service=files&t=47ceb87fca676922732a3f5d34d4306d&download" -P "${REPO_DIR}/tmp" -O ArchivingRoot-last.zip
371
  fi
372 373
fi

374
if [ "${TANGO}" -eq "1" ] 
375
then
376
  echo
Philippe Gauron's avatar
Philippe Gauron committed
377
  info "downloading software for TANGO base tools"
378

379
  ## Install Oracle Java 8
380 381 382 383
  echo "${REPO_DIR}/tmp/jdk-8u212-linux-x64.tar.gz"
  if [ ! -f "${REPO_DIR}/tmp/jdk-8u212-linux-x64.tar.gz" ]
  then 
    wget -c https://owncloud.lal.in2p3.fr/index.php/s/eIYoobHNPld4j34/download -O "${REPO_DIR}/tmp/jdk-8u212-linux-x64.tar.gz"
384
  fi
385

386 387 388
  ## TANGO packages
  sudo apt install -d --assume-yes tango-common tango-starter tango-test python-pytango libtango-doc libtango-dev liblog4j1.2-java
  LIBTANGO_JAVA=libtango-java_9.2.5a-1_all.deb
389

390 391 392 393 394 395 396
  ## Development packages
  sudo apt install -d --assume-yes python-dev
  sudo apt install -d --assume-yes gcc g++ make xemacs21 man

  ## GUI packages
  sudo apt install -d --assume-yes python-pytango python-qtpy python-qwt5-qt4 python-guiqwt python-pymca5 python-ply spyder python-lxml
  sudo apt install -d --assume-yes python-qt4 qt4-designer pyqt4-dev-tools
397

398 399 400 401 402 403 404 405 406
  ## GUI pip packages
  if [ ! -d "${REPO_DIR}/tmp" ]
  then
    mkdir "${REPO_DIR}/tmp"
  fi
  if [ "${DOWNLOAD_ONLY}" -eq "1" ]
  then
    ## If Download mode, internet connection is mandatory
    PIP_OPTION=""
407
  else
408 409
    ## Else, pip download can fail
    PIP_OPTION=" --exists-action i"
410
  fi
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
  if [ ! -f "${REPO_DIR}/tmp/fandango-13.9.0.tar.gz" ]
  then 
    pip ${PIP_OPTION} download -d ${REPO_DIR}/tmp fandango==13.9.0
  fi
  if [ ! -f "${REPO_DIR}/tmp/taurus-4.4.0-py2-none-any.whl" ]
  then 
    pip ${PIP_OPTION} download -d ${REPO_DIR}/tmp taurus==4.4.0
  fi
  if [ ! -f "${REPO_DIR}/tmp/PyYAML-3.13.tar.gz" ]
  then 
    pip ${PIP_OPTION} download -d ${REPO_DIR}/tmp PyYAML==3.13
  fi
  if [ ! -f "${REPO_DIR}/tmp/QtPy-1.2.1-py2.py3-none-any.whl" ]
  then 
    pip ${PIP_OPTION} download -d ${REPO_DIR}/tmp QtPy==1.2.1
  fi
  ## Hggit configuration
  if [ -z `find "${REPO_DIR}/tmp/" -maxdepth 1 -type f -name "dulwich-*.tar.gz" -printf 1 -quit` ]
  then 
    pip ${PIP_OPTION} download -d ${REPO_DIR}/tmp "dulwich>=0.19.0"
  fi

  mkdir -p "${REPO_DIR}/tmp/hgext"
  if [ ! -d "${REPO_DIR}/tmp/hgext/hg-git" ]
435
  then
436 437 438 439 440 441 442
    hg clone https://bitbucket.org/durin42/hg-git "${REPO_DIR}/tmp/hgext/hg-git"
  fi

  ## yat & yat4tango libraries
  sudo apt install --assume-yes subversion 
  sudo apt install --assume-yes -d pkg-config cmake
    
443
  if [ ! -d "${REPO_DIR}/tmp/YAT-1.14.5" ]
444 445 446
  then
    svn checkout https://svn.code.sf.net/p/tango-cs/code/share/yat/tags/YAT-1.14.5 "${REPO_DIR}/tmp/YAT-1.14.5"
  fi
447
  if [ ! -d "${REPO_DIR}/tmp/YAT4Tango-1.11.4" ]
448 449
  then
    svn checkout https://svn.code.sf.net/p/tango-cs/code/share/yat4tango/tags/YAT4Tango-1.11.4 "${REPO_DIR}/tmp/YAT4Tango-1.11.4"
450
  fi
451

452 453 454 455
  if [ ! -e "${REPO_DIR}/tmp/${LIBTANGO_JAVA}" ]
  then
    wget -c "https://people.debian.org/~picca/${LIBTANGO_JAVA}" -P "${REPO_DIR}/tmp"
  fi
456
fi
457

458

459 460
echo
echo
461
info "downloading software for offline installation finished with success"
462 463 464
echo "==================================================================="
echo
echo
465

466
if [ "${DOWNLOAD_ONLY}" -eq "1" ]
467 468 469 470 471 472 473 474 475
then
  exit 0
fi





#############################################################
476

Philippe Gauron's avatar
Philippe Gauron committed
477 478 479 480 481
## Common tools for all installations
# host, to find 
sudo apt install --assume-yes host


482
### Installation of DATABASE DB server ###
483
if [ "${DATABASE}" -eq "1" ]
484
then
485
  echo
486 487 488
  info "installation of Database"

  ## check if Database is already installed
489 490
  DATABASE_INSTALLED=0
  dpkg -l mysql-server &> /dev/null && DATABASE_INSTALLED=1
491 492 493 494 495 496 497

  if [ "${DATABASE_INSTALLED}" -eq "1" ]
  then
    info "Database already installed."
  else

    ## configuration of Database server
498 499 500 501 502 503 504 505 506
    echo "mariadb-server mysql-server/root_password password ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
    echo "mariadb-server mysql-server/root_password_again password ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections

    sudo apt install --assume-yes mariadb-client mariadb-server
    ## package expect is used to answer non-interactively to questions asked 
    ## by mysql_secure_installation
    sudo apt install --assume-yes expect
    ## questions and answers for mysql_secure_installation
    SECURE_MYSQL=$(expect -c "
507 508 509
          set timeout 10
          spawn mysql_secure_installation
          expect \"Enter current password for root (enter for none):\"
510
          send \"${DB_ROOT_PASSWORD}\r\"
511 512 513 514 515 516 517 518 519 520 521 522
          expect \"Change the root password?\"
          send \"n\r\"
          expect \"Remove anonymous users?\"
          send \"y\r\"
          expect \"Disallow root login remotely?\"
          send \"y\r\"
          expect \"Remove test database and access to it?\"
          send \"y\r\"
          expect \"Reload privilege tables now?\"
          send \"y\r\"
          expect eof
          ")
523 524
    echo "${SECURE_MYSQL}"
    sudo apt purge --assume-yes expect
525
  fi
526

527
  ### Installation of PHPMyAdmin
528

529
  ## configuration of PHPMyAdmin
530 531 532 533
  echo 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | sudo debconf-set-selections
  echo 'phpmyadmin phpmyadmin/dbconfig-install boolean true' | sudo debconf-set-selections
  ## Access to PHPMyAdmin for user tango
  echo "phpmyadmin phpmyadmin/mysql/app-pass password ${DB_TANGO_PASSWORD}" | sudo debconf-set-selections
534

535 536
  ## installation of PHPMyAdmin server
  sudo apt install --assume-yes --quiet phpmyadmin
537

538
## creation of shortcut
539 540 541 542 543
  ## if file exists
  if [ -e /var/www/phpmyadmin ]
  then
    error "file '/var/www/phpmyadmin' already exists!" ${E_ALREADY_INSTALLED}
  fi
544

545
  sudo ln -s /usr/share/phpmyadmin/ /var/www/phpmyadmin
546 547 548 549 550
fi




551

552
## configuration of network names if no DNS
553 554
#sudo sh -c "echo "192.168.1.101   ${TANGOSERVER}"  >> /etc/hosts"
#sudo sh -c 'echo "192.168.1.110   ${SERVERNAME}" >> /etc/hosts'
555 556 557 558 559





560
### installation of TANGO DB for TANGO server
561
if [ "${TANGO_DB}" -eq "1" ]
562
then
563
  echo
564 565
  info "installation of TANGO_DB"

566
  #tango-db depends on tango-common
567 568
  echo "tango-common tango-common/tango-host string ${TANGOSERVER}:20000" | sudo debconf-set-selections

569 570 571
  echo 'tango-db tango-db/dbconfig-install boolean true' | sudo debconf-set-selections
  echo "tango-db tango-db/mysql/admin-pass string ${DB_ROOT_PASSWORD}"  | sudo debconf-set-selections
  echo "tango-db tango-db/mysql/app-pass password ${DB_TANGO_PASSWORD}" | sudo debconf-set-selections
572

573
  sudo apt install --assume-yes tango-db
574 575 576 577 578
fi




579

580
### Installation of TANGO base tools
581
if [ "${TANGO}" -eq "1" ]
582
then
583
  echo
584
  info "installation of TANGO base tools"
585 586 587 588 589 590
### Installation of Oracle Java
  tar xvfz "${REPO_DIR}/tmp/jdk-8u212-linux-x64.tar.gz" -C "${REPO_DIR}/tmp/"
  sudo mkdir /opt/java
  sudo mv "${REPO_DIR}/tmp/jdk1.8.0_212" /opt/java/
  sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.8.*/bin/java 2
  sudo update-alternatives --set java /opt/java/jdk1.8.0_212/bin/java
591

592

gauron's avatar
gauron committed
593
### configuration of TANGO
594

gauron's avatar
gauron committed
595
## configuration tango-common
596
  echo "tango-common tango-common/tango-host string ${TANGOSERVER}:20000" | sudo debconf-set-selections
597

gauron's avatar
gauron committed
598
## configuration into /etc/tangorc
599 600
sudo sh -c 'echo "source /etc/tangorc" >> /etc/bash.bashrc'
sudo sh -c 'echo "export TANGO_HOST" >> /etc/bash.bashrc'
601

602
## installation of TANGO
603
  info "installation TANGO"
604

605 606 607
  ## TANGO packages
  sudo apt --assume-yes install tango-common tango-starter tango-test python-pytango libtango-doc libtango-dev liblog4j1.2-java
  LIBTANGO_JAVA=libtango-java_9.2.5a-1_all.deb
608

609 610 611
  ## Development packages
  sudo apt --assume-yes install python-pip
  sudo apt --assume-yes install gcc g++ make xemacs21 man
612

613 614 615
  ## GUI packages
  sudo apt --assume-yes install python-pytango python-qtpy python-qwt5-qt4 python-guiqwt python-pymca5 python-ply spyder python-lxml
  sudo apt --assume-yes install python-qt4 qt4-designer pyqt4-dev-tools
616

617 618
  ## GUI pip packages
  pip install --no-index --find-links="${REPO_DIR}/tmp" fandango==13.9.0 taurus==4.4.0 PyYAML==3.13 QtPy==1.2.1
619

620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
  ## Hggit configuration
  pip install --no-index --find-links="${REPO_DIR}/tmp" "dulwich>=0.19.0"
  if [ ! -d "${REPO_DIR}/tmp/hgext" ]
  then
    mkdir -p "${REPO_DIR}/tmp/hgext"
  fi
  if [ ! -d "${REPO_DIR}/tmp/hgext/hg-git" ]
  then
    hg clone https://bitbucket.org/durin42/hg-git "${REPO_DIR}tmp/hgext/hg-git"
  fi
  cd "${REPO_DIR}/tmp/hgext/hg-git"
  sudo python setup.py install
  cd "${REPO_DIR}"
  sudo sh -c 'echo "[extensions]" >> /etc/mercurial/hgrc'
  sudo sh -c 'echo "# Hg-Git plugin for Mercurial" >> /etc/mercurial/hgrc'
  sudo sh -c 'echo "hgext.bookmarks =" >> /etc/mercurial/hgrc'
  sudo sh -c 'echo "hggit =" >> /etc/mercurial/hgrc'

  ## yat & yat4tango libraries
  sudo apt install --assume-yes subversion 
  sudo apt install --assume-yes pkg-config cmake
  if [ ! -d "${REPO_DIR}/tmp/YAT-1.14.5" ]
  then
    svn checkout https://svn.code.sf.net/p/tango-cs/code/share/yat/tags/YAT-1.14.5 tmp/YAT-1.14.5
  fi
  if [ ! -d "${REPO_DIR}/tmp/YAT4Tango-1.11.4" ]
  then
    svn checkout https://svn.code.sf.net/p/tango-cs/code/share/yat4tango/tags/YAT4Tango-1.11.4 tmp/YAT4Tango-1.11.4
648
  fi
649 650 651 652 653 654 655 656 657 658 659
  export PKG_CONFIG_PATH=/usr/lib/pkgconfig
  cd "${REPO_DIR}/tmp/YAT-1.14.5"
  cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr
  make
  sudo make install
  cd "${REPO_DIR}/tmp/YAT4Tango-1.11.4"
  cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr
  make
  sudo make install
  cd "${REPO_DIR}"
    
660
  if ! ( sudo apt install -f libtango-java )
661
  then
662
    sudo dpkg -i "${REPO_DIR}/tmp/${LIBTANGO_JAVA}"
663
  fi
664

665 666 667 668 669 670 671
fi






gauron's avatar
gauron committed
672
### installation of ArchivingRoot ###
673
if [ "${ARCHIVING}" -eq "1" ]
674
then
675
  echo
676
  info "installation of ARCHIVING"
677 678 679

  sudo mkdir -p /opt/ArchivingRoot
  cd /opt/ArchivingRoot
680

681
  if [ -f "${REPO_DIR}/tmp/ArchivingRoot-last.zip" ]
682
  then
683
    cp "${REPO_DIR}/tmp/ArchivingRoot-last.zip" ./
684
  else
685
    wget -c "https://owncloud.lal.in2p3.fr/public.php?service=files&t=47ceb87fca676922732a3f5d34d4306d&download" -P "${REPO_DIR}/tmp" -O ArchivingRoot-last.zip
686
  fi
687
  sudo apt install unzip
688
  sudo unzip -o ArchivingRoot-last.zip
689
  sudo rm ArchivingRoot-last.zip
690
  cd "${REPO_DIR}"
691

gauron's avatar
gauron committed
692
## configuration into /etc/tangorc
693
  sudo sh -c 'echo "ARCHIVING_ROOT=/opt/ArchivingRoot" >> /etc/tangorc'
694
  sudo sh -c 'echo "export ARCHIVING_ROOT" >> /etc/bash.bashrc'
695 696


697
## configuration of ArchivingRoot
698

699
## creates TDB and HDB databases into Database
700 701
  mysql -h localhost -u root -p"${DB_ROOT_PASSWORD}" < /opt/ArchivingRoot/db/create-TDB-MyISAM.sql
  mysql -h localhost -u root -p"${DB_ROOT_PASSWORD}" < /opt/ArchivingRoot/db/create-HDB-MyISAM.sql
702
  mysql -h localhost -u root -p"${DB_ROOT_PASSWORD}" < "${REPO_DIR}/archive1/create-SNAPDB-MyISAM.sql"
703

704

gauron's avatar
gauron committed
705
## Declaration of Archiving Device Servers into TANGO DB from TANGOSERVER 
706
## if installation of TANGO-DB server and ARCHIVING
707
  if [ "${SERVERNAME}" == "${TANGOSERVER}" ]
708
  then
709
    warning "installation of Archiving Device Servers : non installed"
710
    warning "Archiving DS have to be installed locally on server. through '127.0.0.1' host"
711 712
#    mysql -h "${TANGOSERVER}" -u tango -p"${DB_TANGO_PASSWORD}" < "${REPO_DIR}/swthomx2/essai-hdb-device-installation.sql"
#    mysql -h "${TANGOSERVER}" -u tango -p"${DB_TANGO_PASSWORD}" < "${REPO_DIR}/swthomx2/essai-tdb-device-installation.sql"
713 714
  fi

gauron's avatar
gauron committed
715
## Giving execution rights and changing owner of archiving files to user
716
  sudo chmod u+x /opt/ArchivingRoot/device/linux/*
717
  sudo chown -R "${SUDO_USER}:${SUDO_GROUP}" /opt/ArchivingRoot/*
718 719 720
  sudo chmod u+x -R /opt/ArchivingRoot/bin/linux/


721
## using SHELL bash instead of dash to avoid errors when launching
gauron's avatar
gauron committed
722
## /opt/ArchivingRoot/device/linux/HdbArchiver
723 724 725
  echo 'dash dash/sh boolean false' | sudo debconf-set-selections
  sudo dpkg-reconfigure -p critical dash
## alias bashrc
726
  ## if file already exists
727
  if [ -h /etc/bashrc ]
728
  then
729
    warning "file '/etc/bashrc' already exists!" ${E_ALREADY_INSTALLED}
730
  fi
731 732
  sudo ln -s /etc/bash.bashrc /etc/bashrc

733

734 735
## Giving read/write rights and ownership to user for ${ARCHIVING_DIR}
  if [ ! -d "${ARCHIVING_DIR}" ]
736
  then
737
    warning "${ARCHIVING_DIR} does not exist, creation of this directory."
738
    mkdir "${ARCHIVING_DIR}"
739
  fi
740 741
  sudo chown -R "${SUDO_USER}:${SUDO_GROUP}" "${ARCHIVING_DIR}"
  sudo chmod u+x -R "${ARCHIVING_DIR}"
742

743
  ## if directory already exists
744
  if [ -d "${ARCHIVING_DIR}/tdb" ]
745
  then
746
    error "file \'${ARCHIVING_DIR}/tdb\' already exists!" ${E_ALREADY_INSTALLED}
747 748
  fi

749
  if [ -d "$ARCHIVING_DIR/hdb" ]
750
  then
751
    error "file '${ARCHIVING_DIR}/hdb' already exists!" ${E_ALREADY_INSTALLED}
752 753
  fi

754 755
  sudo mkdir "${ARCHIVING_DIR}/tdb" "${ARCHIVING_DIR}/hdb"
  sudo chmod ugo+rw "${ARCHIVING_DIR}/tdb" "${ARCHIVING_DIR}/hdb"
756 757 758

  ## Update of /etc/mysql/my.cnf to allow external connections:
  ## comment bind-address and skip-networking into my.cnf file
759
  ## bind-address force DB server to listen only several hosts
gauron's avatar
gauron committed
760
  sed -i -e "s/\(^bind-address[ ]*=.*$\)/#\1/g" /etc/mysql/my.cnf
761
  ## skip-networking force DB Server to not listen TCP/IP connections
gauron's avatar
gauron committed
762
  sudo service mysql restart
763 764 765

  ## cleaning temporary archive files 
  ## giving the rights to use crontab
766
  sudo sh -c 'echo '"${SUDO_USER}"' >> /etc/cron.allow' 
767
  ## enter cleaning into crontab
768
  echo "0 2 * * * ${REPO_DIR}/archive1/delete_unmodified_since.sh > ${ARCHIVING_DIR}/hdbtdb_delete_data_and_diary_files.log" | sudo tee --append "/var/spool/cron/crontabs/${USERNAME}"
769 770
  ## starting activating cleaning now 
  sudo service cron restart
771 772 773 774 775
fi




776

777
## Reactivating apt-listchanges
778
APT_LISTCHANGES_FRONTEND=pager
779
## Cleaning unused packages
780
sudo apt autoremove --assume-yes
781
rm -rf "${REPO_DIR}/tmp" 
782 783
source /etc/bash.bashrc
source ~/.bashrc
784

785

786 787
echo 
echo 
788
info "installation finished with success"
789 790 791
echo "=================================="
echo 
echo 
792

793
## TODO
794
## using /var/www/html/img/logo.ico and /var/www/html/img/logo.png
gauron's avatar
gauron committed
795 796
## phpmyadmin password to change manually after installation
## configuring DS with Jive
797 798 799 800 801


### INSTALLATION TEST

## DATABASE
802
if [ "${DATABASE}" -eq "1" ]
803
then
804 805 806 807 808 809 810 811
  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}" !=