script-install.sh 30.9 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 8 / 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 24
##   "su"
##   "apt-get install sudo"
25
##   "usermod -aG sudo [MAINUSER]"
26 27 28
##   then completely close session and open it again
## 3 for installing on virtual machine: check that 
##   /etc/apt/sources.list contains contrib
29
## 4 get the script ("sudo apt-get install git" &
30
##   "git clone https://gitlab.in2p3.fr/CCThomX/installation.git")
31
## 5 check if setxkbmap is well configured if necessary
32 33 34
## 6 configure the INSTALLATION PARAMETERS in the script including 
##   ARCHIVING_DIR
## 7 launch the script with tangoserver name as parameter
35
##   ("cd ThomX-Config ; sudo script-install.sh [TANGOSERVER]")
36
## 8 on distant host, install xauth package (sudo apt-get install xauth)
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
## 9 test:
##   * DOWNLOAD_ONLY: launching the script with the same configuration
##     should work offline 
##   * VIRTUALBOX: increasing the size of virtualbox window should 
##     increase the size of virtual screen
##   * DATABASE: connection to MariaDB (Debian 9) or MySQL (Debian 8) 
##     should work
##     `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)`
##     
##   * TANGO_DB: 
##     + in a terminal different from the one used to execute 
##       `./script-install.sh`, `echo ${TANGO_HOST}` should return the 
##       Fully Qualified Domain Name (FQDN) of the computer
##     + 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: 
##     + TANGO_DB tests should be completed
90 91 92
##     + yat & yat4tango installation : check presence of /usr/include/yat &
##       /usr/include/yat4tango directories and libraries /usr/lib/libyat.so &
##       /usr/lib/libyat4tango.so
93
##     + test GUI:
94 95 96 97 98 99 100 101
##       - add 
##         ```
##         [extensions]
##         # Hg-Git plugin for Mercurial
##         hgext.bookmarks =
##         hggit = 
##         ``` into `~/.hgrc`
##       - 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 121
### INSTALLATION PARAMETERS
## 1 if to install, 0 otherwise
gauron's avatar
gauron committed
122

123
## Downloading packages only
124
DOWNLOAD_ONLY=0
125 126
## Checking and activating dependencies
DEPENDENCIES=1
127
## VirtualBox
128
VIRTUALBOX=0
129
## Database server and PHPMyAdmin
130
DATABASE=0
131
## TANGO base tools
132
TANGO=0
133
## TANGO DB (depends on TANGO and DATABASE)
134
TANGO_DB=0
135
## Archiving (depends on DATABASE)
136
ARCHIVING=0
137

138 139
## Directory where to install 
ARCHIVING_DIR="/var/archivage"
140

141 142
#############################################################

143 144


145 146
## Errors
E_INCORRECT_ARGS=1
147
E_NONROOT=2
148 149
E_INCORRECT_TANGOSERVER=3
E_INCORRECT_HOSTNAME=4
150
E_INCORRECT_SYSTEM=5
151

152 153
E_PARAM_ERROR=11
E_PARAM_WARNING=12
154 155
E_PARAM_INFO=13

156 157
E_ABORT_SCRIPT=21

158
E_ALREADY_INSTALLED=31
159

160
## Default variables
161
DEFAULTTANGOSERVER=${HOSTNAME}
162

gauron's avatar
gauron committed
163
## Colors
164 165 166 167 168 169 170 171 172 173 174 175
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"

176
##  Initialise text attributes to standard without flushing the screen
177
alias init="tput sgr0"
178

179
## Other variables
180
UID_ROOT=0
181 182
REPO_DIR=${PWD}
HOME_DIR="/home/${SUDO_USER}"
183 184


185 186
#############################################################

187
### Printing functions
188

189 190
## error
## Prints a error message and exit from the script with given error code.
191
##
192
## parameters :
193
##   msg : message printed in ${RED}
194
##   code : error code
195

196
function error
197
{
198
  if [ "$#" -eq "2" ]
199
  then
200
    echo -e "${BOLD}${RED}Error: $1!${END_FORMATING}"
201
    exit "$2"
202
  else
203
    echo -e "${BOLD}${RED}Error : incorrect number of parameters $# for function 'error'!${END_FORMATING}"
204
    exit ${E_PARAM_ERROR}
205 206 207 208
  fi
}


209 210
## alerte
## Prints a warning message.
211 212
##
## paramètres :
213
##   msg : message printed in ${YELLOW}
214

215
function warning
216
{
217
  if [ "$#" -eq "1" ]
218
  then
219
    echo -e "${BOLD}${YELLOW}Warning : $1.${END_FORMATING}"
220
  else
221
    error "Incorrect number of parameters $#  for function 'alerte'" ${E_PARAM_WARNING}
222 223 224
  fi
}

225 226
## info
## Prints an information message.
227
##
228
## parameters :
229
##   msg : message printed in ${GREEN}
230 231 232

function info
{
233
  if [ "$#" -eq "1" ]
234
  then
235
    echo -e "${BOLD}${GREEN}Information : $1.${END_FORMATING}"
236
  else
237
    error "Incorrect number of parameters $# for function 'info'" ${E_PARAM_INFO}
238 239 240 241
  fi
}


242
### EXECUTION ###
243
## 
244
## This script must be launched with sudo (or type password when asked)
245

246
## Stop this script at first error
247 248 249
set -e


250
#############################################################
251 252


253
### Checking parameters
254

255
## To launch as root of course
256
if [ "${EUID}" -ne "${UID_ROOT}" ]
257
then
258
  error "You must be root to launch this script" ${E_NONROOT}
259 260
fi  

261
## To launch with 1 parameter maximum
262
if [ "$#" -gt "1" ]
263
then
264
  error "To much parameters.\n\nUsage: $(basename "$0") [TANGOSERVER_name]" ${E_INCORRECT_ARGS}
265 266 267
fi


268
## Debian version
269
if [ "$(/usr/bin/lsb_release -is)" == "Debian" ]
270 271 272 273 274 275 276 277 278 279 280
then
  DEBIAN_VERSION=$(/usr/bin/lsb_release -cs)
  case ${DEBIAN_VERSION} in
    stretch*) DEBIAN_VERSION=9;;
    jessie*) DEBIAN_VERSION=8;;
    *) error "Operating System is not a Debian 8/9!" ${E_INCORRECT_SYSTEM};;
  esac
  echo "Debian version : ${DEBIAN_VERSION}"
else
  error "Operating System is not a Debian 8/9!" ${E_INCORRECT_SYSTEM}
fi
281

282 283
## Definition of the hostname (also used as user's group name)
SERVERNAME=${HOSTNAME}
284

285
info "server will be installed with name '${SERVERNAME}'"
286

287
## Definition of user's group
288
SUDO_GROUP=$(id -g -n "${SUDO_USER}")
289 290 291 292




293 294 295
## Definition of TANGOSERVER name:
## - "tangoserver" as default
## - from given parameter
296
TANGOSERVER=${1-${DEFAULTTANGOSERVER}}
297 298


299
if [ "${TANGOSERVER}" != "${SERVERNAME}" ] && [ "${TANGO_DB}" -eq "1" ]
300
then
301
  error "installation of TANGO_DB is asked but TANGOSERVER (='${TANGOSERVER}') has another name than SERVERNAME (='${SERVERNAME}')" ${E_INCORRECT_TANGOSERVER}
302 303
fi

304
info "server will be installed with TANGOSERVER '${TANGOSERVER}'"
305 306


307

308 309 310

### Checking and correcting of initial configuration

311 312 313
## ${SERVERNAME} == ${TANGOSERVER} -> TANGO-DB=1
if [ "${DEPENDENCIES}" == "1" ] && [ "${SERVERNAME}" == "${TANGOSERVER}" ] \
   && [ "${TANGO_DB}" -eq "0" ]
314
then
315
  warning "${SERVERNAME} == ${TANGOSERVER}, TANGO_DB will be installed."
316 317 318
  TANGO_DB=1
fi

319
## ARCHIVING=1 -> DATABASE=1
320
if [ "${DEPENDENCIES}" == "1" ] && [ "${DATABASE}" -eq "0" ] && [ "${ARCHIVING}" -eq "1" ]
321
then
322 323
  warning "installation of ARCHIVING asked, DATABASE will be installed."
  DATABASE=1
324 325 326
fi


327
## TANGO_DB=1 -> TANGO=1 & DATABASE=1
328
if [ "${DEPENDENCIES}" == "1" ] && [ "${TANGO}" -eq "0" ] && [ "${TANGO_DB}" -eq "1" ]
329
then
330
  ##warning "installation of TANGO_DB asked, TANGO will be installed."
331
  TANGO=1
332
  DATABASE=1
333 334 335
fi


336
## Prints final corrected configuration
337
echo ""
338
echo "Final configuration  to install: "
339
if [ "${VIRTUALBOX}" -eq "1" ]
340
then
341
  echo "VIRTUALBOX"
342
fi
343
if [ "${DATABASE}" -eq "1" ]
344
then
345
  echo "Database server and PHPMyAdmin"
346
fi
347
if [ "${TANGO}" -eq "1" ]
348 349 350
then
  echo "TANGO base tools"
fi
351
if [ "${TANGO_DB}" -eq "1" ]
352 353 354
then
  echo "TANGO DB"
fi
355
if [ "${ARCHIVING}" -eq "1" ]
356 357 358 359
then
  echo "ArchivingRoot"
fi

360

361 362


363
if [ "${DOWNLOAD_ONLY}" -eq "1" ]
364
then
365 366 367
  warning "installation will only download software and will not install anything"
else
  ## Exit if user does not confirm configuration
368 369
  read -p "Do you want to install this configuration? ([Yy]Nn) " CHOICE
  case "${CHOICE}" in
370
    y|Y ) info "Begining installation...";;
371 372
    n|N ) info "Abort installation"; exit ${E_ABORT_SCRIPT};;
    * ) info "Abort installation (invalid answer)"; exit ${E_ABORT_SCRIPT};;
373 374
  esac

375
  if [ "${DATABASE}" -eq "1" ] || [ "${TANGO_DB}" -eq "1" ] || [ "${ARCHIVING}" -eq "1" ]
376 377 378
  then
    ## Get Database root password
    echo "Please enter root password for DATABASE: "
379
    read -s DB_ROOT_PASSWORD
380 381 382
    echo "Please enter tango password for DATABASE: "
    read -s DB_TANGO_PASSWORD
    MYSQL_USER=tango
383
    MYSQL_PASSWORD=${DB_TANGO_PASSWORD}
384
  fi
385

386
fi
387

388

389
## configuration AZERTY (equivalent of
gauron's avatar
gauron committed
390
## "dpkg-reconfigure keyboard-configuration", but in non-interactive mode)
391
## for PC-tower keyboard
392
#sudo setxkbmap -model pc105 -layout fr -variant latin9
393
## for flat USB Mac
394
#setxkbmap -model macintosh -layout fr
395 396
## for DELL latitude laptop
#sudo setxkbmap -model latitude -layout us
397 398 399 400




401
### Preparation of installation tools ###
402

403
## temporarly unactivate of listchanges
404
APT_LISTCHANGES_FRONTEND=none
405 406

## update of packages before installation
407
sudo apt-get update
408

409
## to install packages in non-interactive mode
410
DEBIAN_FRONTEND=noninteractive
411 412 413 414
sudo apt-get install --assume-yes debconf 

## to install keys for additionnal packages repository
sudo apt-get install --assume-yes dirmngr
415

416 417
# creating temporary directory for installation
mkdir -p "${REPO_DIR}/tmp"
418 419


420 421 422
#############################################################

### Downloading packages
423

424
if [ "${VIRTUALBOX}" -eq "1" ]
425
then
426
  info "downloading software for VIRTUALBOX"
427

428 429 430 431 432 433 434 435
  if [ "${DEBIAN_VERSION}" -gt "8" ]
  then
    ## Debian 9+/MariaDB
    sudo apt-get install -d modules-assistant
  else
    ## Debian 8-/MySQL
    sudo apt-get install -d --assume-yes debconf xserver-xorg-core virtualbox-guest-x11
  fi
436 437
fi

438
if [ "${DATABASE}" -eq "1" ]
439
then
Philippe Gauron's avatar
Philippe Gauron committed
440
  info "downloading software for Database server and PHPMyAdmin"
441 442 443 444

  if [ "${DEBIAN_VERSION}" -gt "8" ]
  then
    ## Debian 9+/MariaDB
445
    sudo apt-get install -d --assume-yes mariadb-client mariadb-server phpmyadmin expect
446 447
  else
    ## Debian 8-/MySQL
448
    sudo apt-get install -d --assume-yes --force-yes mysql-client mysql-server phpmyadmin
449 450 451
  fi
fi

452
if [ "${TANGO_DB}" -eq "1" ]
453
then
Philippe Gauron's avatar
Philippe Gauron committed
454
  info "downloading software for TANGO DB"
455

456
  sudo apt-get install -d --assume-yes tango-db
457 458
fi

459
if [ "${ARCHIVING}" -eq "1" ]
460
then
Philippe Gauron's avatar
Philippe Gauron committed
461
  info "downloading software for ArchivingRoot"
462

463
  sudo apt-get install -d --assume-yes unzip
464 465
  cd "${REPO_DIR}/tmp"
  if [ ! -f "${REPO_DIR}/tmp/ArchivingRoot-last.zip" ]
466
    then
467
      wget -c "https://owncloud.lal.in2p3.fr/public.php?service=files&t=47ceb87fca676922732a3f5d34d4306d&download" -P "${REPO_DIR}/tmp" -O ArchivingRoot-last.zip
468 469
  fi
  cd ..
470 471
fi

472
if [ "${TANGO}" -eq "1" ] 
473
then
Philippe Gauron's avatar
Philippe Gauron committed
474
  info "downloading software for TANGO base tools"
475 476 477 478

  if [ "${DEBIAN_VERSION}" -gt "8" ]
  then
  ## Debian 9
479 480 481
    ## Install python package manager
    sudo apt install --assume-yes python-pip

482 483
    ## Install Oracle Java
    if ! [ -e /etc/apt/sources.list.d/webupd8team-java.list ] \
484 485
       || [[ "$(grep -q 'deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main' /etc/apt/sources.list.d/webupd8team-java.list)" -eq "1" ]] \
       || [[ "$(grep -q 'deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main' /etc/apt/sources.list.d/webupd8team-java.list)" -eq "1" ]]
486 487 488 489 490 491 492 493 494
    then
      echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
      echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
      sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
      sudo apt-get update
    fi
    ## Accept automatically Oracle license
    echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | sudo debconf-set-selections
    #echo "oracle-java8-installer shared/accepted-oracle-licence-v1-1 boolean true" | sudo debconf-set-selections
495 496
    sudo apt-get install --assume-yes --allow-downgrades --allow-change-held-packages oracle-java8-installer
    sudo apt-get install -d --assume-yes oracle-java8-set-default
497
    ## needed to replace OpenJDK by Oracle Java
498
    sudo apt-get install -d --assume-yes libxrender1 libxtst6
499 500

    ## TANGO packages
501
    sudo apt-get install -d --assume-yes tango-starter tango-test python-pytango libtango-doc libtango-dev liblog4j1.2-java
502
    LIBTANGO_JAVA=libtango-java_9.2.5a-1_all.deb
503 504 505 506 507 508 509 510

    ## Development packages
    sudo apt install -d --assume-yes gcc g++ make xemacs21 git mercurial man

    ## GUI packages
    sudo apt install -d --assume-yes python-dulwich python-dev python-pip python-qt4 python-qwt5-qt4 python-qtpy qt4-designer pyqt4-dev-tools

    ## GUI pip packages
511
    if [ ! -d "${REPO_DIR}/tmp" ]
512
    then
513
      mkdir "${REPO_DIR}/tmp"
514
    fi
515
    pip download -d "${REPO_DIR}/tmp" fandango==13.9.0 taurus==4.4.0 PyYAML==3.13 QtPy==1.2.1
516

517 518
    ## Hggit configuration
    sudo apt install -d --assume-yes python-dulwich python-dev
519 520 521 522 523
    mkdir -p "${REPO_DIR}/tmp/hgext"
    if [ ! -d "${REPO_DIR}/tmp/hgext/hg-git" ]
    then
      hg clone https://bitbucket.org/durin42/hg-git tmp/hgext/hg-git
    fi
524

525
    ## yat & yat4tango libraries
526
    cd tmp
527 528
    sudo apt install --assume-yes subversion 
    sudo apt install --assume-yes -d pkg-config cmake
529 530 531 532 533 534 535 536 537 538
    
    if [ ! -d "${REPO_DIR}/tmp/yat" ]
    then
      svn checkout https://svn.code.sf.net/p/tango-cs/code/share/yat/trunk yat
    fi
    if [ ! -d "${REPO_DIR}/tmp/yat4tango" ]
    then
      svn checkout https://svn.code.sf.net/p/tango-cs/code/share/yat4tango/trunk yat4tango
    fi
    cd ..
539

540 541
  else
  ## Debian 8
542
    if ! [ -e /etc/apt/sources.list.d/webupd8team-java.list ] \
543 544
         || [[ "$(grep -q 'deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main' /etc/apt/sources.list.d/webupd8team-java.list)" -eq "1" ]] \
         || [[ "$(grep -q 'deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main' /etc/apt/sources.list.d/webupd8team-java.list)" -eq "1" ]]
545 546 547 548 549 550 551 552 553
    then
      echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
      echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
      sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
      sudo apt-get update
    fi
    ## Accept automatically Oracle license
    echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | sudo debconf-set-selections
    #echo "oracle-java8-installer shared/accepted-oracle-licence-v1-1 boolean true" | sudo debconf-set-selections
554 555
    sudo apt-get install --assume-yes --force-yes oracle-java8-installer
    sudo apt-get install -d --assume-yes --force-yes oracle-java8-set-default
556
    ## needed to replace OpenJDK by Oracle Java
557
    sudo apt-get install -d --assume-yes libxrender1 libxtst6
558 559

    ## TANGO packages
560
    sudo apt-get install -d --assume-yes --force-yes tango-common tango-starter tango-test python-pytango libtango8-doc libtango8-dev liblog4j1.2-java
561 562 563 564
    LIBTANGO_JAVA=libtango-java_8.1.2.c-1_all.deb
  fi
  if ! ( sudo apt-get install -f libtango-java )
  then
565
    if [ ! -f "${REPO_DIR}/tmp/${LIBTANGO_JAVA}" ]
566
    then
567
      wget -c "https://people.debian.org/~picca/${LIBTANGO_JAVA}" -P "${REPO_DIR}/tmp"
568 569 570
    fi
  fi
fi
571

572 573 574

info "downloading software for offline installation finished with success"

575
if [ "${DOWNLOAD_ONLY}" -eq "1" ]
576 577 578 579 580 581 582 583 584
then
  exit 0
fi





#############################################################
585

586
### Specific installation for virtual machines (big screen and copy/paste) 
587
if [ "${VIRTUALBOX}" -eq "1" ]
588
then
589
  info "installation of VIRTUALBOX options"
590

591
## Disable screensaver which can block VIRTUALBOX
592 593 594
  sudo apt-get remove --assume-yes light-locker


595
## Installation of VirtualBox addons for bigger resolutions
596 597 598 599 600 601 602 603 604 605 606
  if [ "${DEBIAN_VERSION}" -gt "8" ]
  then
    ## Debian 9+
    sudo apt-get install modules-assistant
    sudo m-a prepare
    sudo sh /media/cdrom/VBoxLinuxAdditions.run
  else
    ## Debian 8-
    sudo apt-get install --assume-yes xserver-xorg-core
    sudo apt-get install -f --assume-yes virtualbox-guest-x11
  fi
Philippe Gauron's avatar
Philippe Gauron committed
607

608 609 610 611 612 613
fi





614
### Installation of DATABASE DB server ###
615
if [ "${DATABASE}" -eq "1" ]
616
then
617 618 619
  info "installation of Database"

  ## check if Database is already installed
620 621
  DATABASE_INSTALLED=0
  dpkg -l mysql-server &> /dev/null && DATABASE_INSTALLED=1
622 623 624 625 626 627 628 629 630 631

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

    ## configuration of Database server
    if [ "${DEBIAN_VERSION}" -gt "8" ]
    then
      ## Debian 9+/MariaDB
632 633
      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
634 635

      sudo apt-get install --assume-yes mariadb-client mariadb-server
636 637 638 639 640 641 642 643
      ## package expect is used to answer non-interactively to questions asked 
      ## by mysql_secure_installation
      sudo apt-get install --assume-yes expect
      ## questions and answers for mysql_secure_installation
      SECURE_MYSQL=$(expect -c "
          set timeout 10
          spawn mysql_secure_installation
          expect \"Enter current password for root (enter for none):\"
644
          send \"${DB_ROOT_PASSWORD}\r\"
645 646 647 648 649 650 651 652 653 654 655 656
          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
          ")
657
      echo "${SECURE_MYSQL}"
658
      sudo apt-get purge --assume-yes expect
659 660
    else
      ## Debian 8-/MySQL
661 662
      echo "mysql-server mysql-server/root_password password ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
      echo "mysql-server mysql-server/root_password_again password ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
663

664
      sudo apt-get install --assume-yes --force-yes mysql-server mysql-client
665 666 667
    fi

  fi
668

669
  ### Installation of PHPMyAdmin
670

671 672 673 674 675 676
  ## configuration of PHPMyAdmin
  if [ "${DEBIAN_VERSION}" -gt "8" ]
  then
  ## Debian 9+/MariaDB
    echo 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | sudo debconf-set-selections
    echo 'phpmyadmin phpmyadmin/dbconfig-install boolean true' | sudo debconf-set-selections
677
    ## Access to PHPMyAdmin for user tango
678 679
    echo "phpmyadmin phpmyadmin/mysql/app-pass password ${DB_TANGO_PASSWORD}" | sudo debconf-set-selections
    #echo "phpmyadmin phpmyadmin/app-password-confirm password ${DB_TANGO_PASSWORD}" | sudo debconf-set-selections
680

681
    #echo "phpmyadmin phpmyadmin/mysql/admin-pass string ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
682 683 684 685 686 687 688 689

    ## installation of PHPMyAdmin server
    sudo apt-get install --assume-yes --quiet phpmyadmin

  else
  ## Debian 8-/MySQL
    echo 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | sudo debconf-set-selections
    echo 'phpmyadmin phpmyadmin/dbconfig-install boolean true' | sudo debconf-set-selections
690

691
    ## root password for Database
692 693
    #echo "phpmyadmin phpmyadmin/setup-password password ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
    #echo "phpmyadmin phpmyadmin/password-confirm password ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
694 695

    ## password for phpmyadmin application
696 697
    echo "phpmyadmin phpmyadmin/mysql/app-pass password ${DB_TANGO_PASSWORD}" | sudo debconf-set-selections
    echo "phpmyadmin phpmyadmin/app-password-confirm password ${DB_TANGO_PASSWORD}" | sudo debconf-set-selections
698 699

    ## root password for Database
700 701
    echo "phpmyadmin phpmyadmin/mysql/admin-pass password ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
#    echo "phpmyadmin phpmyadmin/mysql/app-password-confirm password ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
702

703
#    echo "phpmyadmin phpmyadmin/password-confirm password ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
704 705

    ## installation of PHPMyAdmin server
706
    sudo apt-get install --assume-yes --force-yes --quiet phpmyadmin
707
  fi
708 709


710
## creation of shortcut
711 712 713 714 715
  ## if file exists
  if [ -e /var/www/phpmyadmin ]
  then
    error "file '/var/www/phpmyadmin' already exists!" ${E_ALREADY_INSTALLED}
  fi
716

717
  sudo ln -s /usr/share/phpmyadmin/ /var/www/phpmyadmin
718 719 720 721 722
fi




723

724
## configuration of network names if no DNS
725 726
#sudo sh -c "echo "192.168.1.101   ${TANGOSERVER}"  >> /etc/hosts"
#sudo sh -c 'echo "192.168.1.110   ${SERVERNAME}" >> /etc/hosts'
727 728 729 730 731





732
### installation of TANGO DB for TANGO server
733
if [ "${TANGO_DB}" -eq "1" ]
734 735 736
then
  info "installation of TANGO_DB"

737
  #tango-db depends on tango-common
738 739
  echo "tango-common tango-common/tango-host string ${TANGOSERVER}:20000" | sudo debconf-set-selections

740 741 742 743
  if [ "${DEBIAN_VERSION}" -gt "8" ]
  then
  ## Debian 9+/MariaDB
    echo 'tango-db tango-db/dbconfig-install boolean true' | sudo debconf-set-selections
744 745
    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
746 747 748 749
  else
    ## Debian 8-/MySQL

    echo 'tango-db tango-db/dbconfig-install boolean true' | sudo debconf-set-selections
750 751
    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
752 753
  fi

754
  sudo apt-get install --assume-yes tango-db
755 756 757 758 759 760

fi




761

762
### Installation of TANGO base tools
763
if [ "${TANGO}" -eq "1" ]
764
then
765 766
  info "installation of TANGO base tools"
### Installation of Java
767
  sudo apt-get --assume-yes install oracle-java8-installer oracle-java8-set-default
768
  ## needed to replace OpenJDK by Oracle Java
769
  sudo apt-get install --assume-yes libxrender1 libxtst6
770

771

gauron's avatar
gauron committed
772
### configuration of TANGO
773

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

gauron's avatar
gauron committed
777
## configuration into /etc/tangorc
778 779
sudo sh -c 'echo "source /etc/tangorc" >> /etc/bash.bashrc'
sudo sh -c 'echo "export TANGO_HOST" >> /etc/bash.bashrc'
780

781
## installation of TANGO
782 783 784 785
  if [ "${DEBIAN_VERSION}" -gt "8" ]
  then
  ## Debian 9 and +
    echo "installation TANGO Debian 9+"
786 787

    ## TANGO packages
788 789
    sudo apt-get --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
790 791 792 793 794 795 796 797

    ## Development packages
    sudo apt --assume-yes install gcc g++ make xemacs21 git mercurial man

    ## GUI packages
    sudo apt --assume-yes install python-dulwich python-dev python-pip python-qt4 python-qwt5-qt4 python-qtpy qt4-designer pyqt4-dev-tools

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

800 801
    ## Hggit configuration
    sudo apt install -y python-dulwich python-dev
802
    if [ ! -d "${REPO_DIR}/tmp/hgext" ]
803 804 805
    then
      mkdir -p ~/hgext
    fi
806
    if [ ! -d "${REPO_DIR}/tmp/hgext/hg-git" ]
807
    then
808
      hg clone https://bitbucket.org/durin42/hg-git tmp/hgext/hg-git
809
    fi
810
    cd tmp/hgext/hg-git
811
    sudo python setup.py install
812
    cd ../../..
813

814 815 816
    ## yat & yat4tango libraries
    sudo apt install --assume-yes subversion 
    sudo apt install --assume-yes pkg-config cmake
817 818 819 820 821 822 823 824
    if [ ! -d "${REPO_DIR}/tmp/yat" ]
    then
      svn checkout https://svn.code.sf.net/p/tango-cs/code/share/yat/trunk tmp/yat
    fi
    if [ ! -d "${REPO_DIR}/tmp/yat4tango" ]
    then
      svn checkout https://svn.code.sf.net/p/tango-cs/code/share/yat4tango/trunk tmp/yat4tango
    fi
825
    export PKG_CONFIG_PATH=/usr/lib/pkgconfig
826
    cd tmp/yat
827