script-install.sh 29.5 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 90
## 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
##     + test GUI:
91 92 93 94 95 96 97 98
##       - add 
##         ```
##         [extensions]
##         # Hg-Git plugin for Mercurial
##         hgext.bookmarks =
##         hggit = 
##         ``` into `~/.hgrc`
##       - get IHM repo : `hg clone https://gitlab.in2p3.fr/CCThomX/IHM.git`
99 100 101 102 103 104 105 106 107
##       - 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 
108
##       the repo `hg clone git@gitlab.in2p3.fr:CCThomX/DS-LAL.git`
109 110
##       Then build a DS.
##   * ARCHIVING: to complete by JCM
111 112 113
##
## If any issue occurs, you can check installation parameters are well 
## spelled with command debconf-get-selections from package debconf-utils.
114 115 116



117 118
### INSTALLATION PARAMETERS
## 1 if to install, 0 otherwise
gauron's avatar
gauron committed
119

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

135 136
## Directory where to install 
ARCHIVING_DIR="/var/archivage"
137

138 139
#############################################################

140 141


142 143
## Errors
E_INCORRECT_ARGS=1
144
E_NONROOT=2
145 146
E_INCORRECT_TANGOSERVER=3
E_INCORRECT_HOSTNAME=4
147
E_INCORRECT_SYSTEM=5
148

149 150
E_PARAM_ERROR=11
E_PARAM_WARNING=12
151 152
E_PARAM_INFO=13

153 154
E_ABORT_SCRIPT=21

155
E_ALREADY_INSTALLED=31
156

157
## Default variables
158
DEFAULTTANGOSERVER=${HOSTNAME}
159

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

173
##  Initialise text attributes to standard without flushing the screen
174
alias init="tput sgr0"
175

176
## Other variables
177
UID_ROOT=0
178 179
REPO_DIR=${PWD}
HOME_DIR="/home/${SUDO_USER}"
180 181


182 183
#############################################################

184
### Printing functions
185

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

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


206 207
## alerte
## Prints a warning message.
208 209
##
## paramètres :
210
##   msg : message printed in ${YELLOW}
211

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

222 223
## info
## Prints an information message.
224
##
225
## parameters :
226
##   msg : message printed in ${GREEN}
227 228 229

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


239
### EXECUTION ###
240
## 
241
## This script must be launched with sudo (or type password when asked)
242

243
## Stop this script at first error
244 245 246
set -e


247
#############################################################
248 249


250
### Checking parameters
251

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

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


265
## Debian version
266
if [ "$(/usr/bin/lsb_release -is)" == "Debian" ]
267 268 269 270 271 272 273 274 275 276 277
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
278

279 280
## Definition of the hostname (also used as user's group name)
SERVERNAME=${HOSTNAME}
281

282
info "server will be installed with name '${SERVERNAME}'"
283

284
## Definition of user's group
285
SUDO_GROUP=$(id -g -n "${SUDO_USER}")
286 287 288 289




290 291 292
## Definition of TANGOSERVER name:
## - "tangoserver" as default
## - from given parameter
293
TANGOSERVER=${1-${DEFAULTTANGOSERVER}}
294 295


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

301
info "server will be installed with TANGOSERVER '${TANGOSERVER}'"
302 303


304

305 306 307

### Checking and correcting of initial configuration

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

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


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


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

357

358 359


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

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

383
fi
384

385

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




398
### Preparation of installation tools ###
399

400
## temporarly unactivate of listchanges
401
APT_LISTCHANGES_FRONTEND=none
402 403

## update of packages before installation
404
sudo apt-get update
405

406
## to install packages in non-interactive mode
407
DEBIAN_FRONTEND=noninteractive
408 409 410 411
sudo apt-get install --assume-yes debconf 

## to install keys for additionnal packages repository
sudo apt-get install --assume-yes dirmngr
412 413 414



415 416 417
#############################################################

### Downloading packages
418

419
if [ "${VIRTUALBOX}" -eq "1" ]
420
then
421
  info "downloading software for VIRTUALBOX"
422

423 424 425 426 427 428 429 430
  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
431 432
fi

433
if [ "${DATABASE}" -eq "1" ]
434
then
Philippe Gauron's avatar
Philippe Gauron committed
435
  info "downloading software for Database server and PHPMyAdmin"
436 437 438 439

  if [ "${DEBIAN_VERSION}" -gt "8" ]
  then
    ## Debian 9+/MariaDB
440
    sudo apt-get install -d --assume-yes mariadb-client mariadb-server phpmyadmin expect
441 442
  else
    ## Debian 8-/MySQL
443
    sudo apt-get install -d --assume-yes --force-yes mysql-client mysql-server phpmyadmin
444 445 446
  fi
fi

447
if [ "${TANGO_DB}" -eq "1" ]
448
then
Philippe Gauron's avatar
Philippe Gauron committed
449
  info "downloading software for TANGO DB"
450

451
  sudo apt-get install -d --assume-yes tango-db
452 453
fi

454
if [ "${ARCHIVING}" -eq "1" ]
455
then
Philippe Gauron's avatar
Philippe Gauron committed
456
  info "downloading software for ArchivingRoot"
457

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

467
if [ "${TANGO}" -eq "1" ] 
468
then
Philippe Gauron's avatar
Philippe Gauron committed
469
  info "downloading software for TANGO base tools"
470 471 472 473

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

477 478
    ## Install Oracle Java
    if ! [ -e /etc/apt/sources.list.d/webupd8team-java.list ] \
479 480
       || [[ "$(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" ]]
481 482 483 484 485 486 487 488 489
    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
490 491
    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
492
    ## needed to replace OpenJDK by Oracle Java
493
    sudo apt-get install -d --assume-yes libxrender1 libxtst6
494 495

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

    ## 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
    if [ ! -d "${REPO_DIR}/pip-tmp" ]
    then
      mkdir "${REPO_DIR}/pip-tmp"
    fi
510
    pip download -d "${REPO_DIR}/pip-tmp" fandango==13.9.0 taurus==4.4.0 PyYAML==3.13 QtPy==1.2.1
511

512 513 514 515 516
    ## Hggit configuration
    sudo apt install -d --assume-yes python-dulwich python-dev
    mkdir -p ~/hgext && cd ~/hgext
    hg clone https://bitbucket.org/durin42/hg-git

517 518
  else
  ## Debian 8
519
    if ! [ -e /etc/apt/sources.list.d/webupd8team-java.list ] \
520 521
         || [[ "$(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" ]]
522 523 524 525 526 527 528 529 530
    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
531 532
    sudo apt-get install --assume-yes --force-yes oracle-java8-installer
    sudo apt-get install -d --assume-yes --force-yes oracle-java8-set-default
533
    ## needed to replace OpenJDK by Oracle Java
534
    sudo apt-get install -d --assume-yes libxrender1 libxtst6
535 536

    ## TANGO packages
537
    sudo apt-get install -d --assume-yes --force-yes tango-common tango-starter tango-test python-pytango libtango8-doc libtango8-dev liblog4j1.2-java
538 539 540 541
    LIBTANGO_JAVA=libtango-java_8.1.2.c-1_all.deb
  fi
  if ! ( sudo apt-get install -f libtango-java )
  then
542
    if [ ! -f "${REPO_DIR}/tmp/${LIBTANGO_JAVA}" ]
543
    then
544
      wget -c "https://people.debian.org/~picca/${LIBTANGO_JAVA}" -P "${REPO_DIR}/tmp"
545 546 547
    fi
  fi
fi
548

549 550 551

info "downloading software for offline installation finished with success"

552
if [ "${DOWNLOAD_ONLY}" -eq "1" ]
553 554 555 556 557 558 559 560 561
then
  exit 0
fi





#############################################################
562

563
### Specific installation for virtual machines (big screen and copy/paste) 
564
if [ "${VIRTUALBOX}" -eq "1" ]
565
then
566
  info "installation of VIRTUALBOX options"
567

568
## Disable screensaver which can block VIRTUALBOX
569 570 571
  sudo apt-get remove --assume-yes light-locker


572
## Installation of VirtualBox addons for bigger resolutions
573 574 575 576 577 578 579 580 581 582 583
  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
584

585 586 587 588 589 590
fi





591
### Installation of DATABASE DB server ###
592
if [ "${DATABASE}" -eq "1" ]
593
then
594 595 596
  info "installation of Database"

  ## check if Database is already installed
597 598
  DATABASE_INSTALLED=0
  dpkg -l mysql-server &> /dev/null && DATABASE_INSTALLED=1
599 600 601 602 603 604 605 606 607 608

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

    ## configuration of Database server
    if [ "${DEBIAN_VERSION}" -gt "8" ]
    then
      ## Debian 9+/MariaDB
609 610
      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
611 612

      sudo apt-get install --assume-yes mariadb-client mariadb-server
613 614 615 616 617 618 619 620
      ## 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):\"
621
          send \"${DB_ROOT_PASSWORD}\r\"
622 623 624 625 626 627 628 629 630 631 632 633
          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
          ")
634
      echo "${SECURE_MYSQL}"
635
      sudo apt-get purge --assume-yes expect
636 637
    else
      ## Debian 8-/MySQL
638 639
      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
640

641
      sudo apt-get install --assume-yes --force-yes mysql-server mysql-client
642 643 644
    fi

  fi
645

646
  ### Installation of PHPMyAdmin
647

648 649 650 651 652 653
  ## 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
654
    ## Access to PHPMyAdmin for user tango
655 656
    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
657

658
    #echo "phpmyadmin phpmyadmin/mysql/admin-pass string ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
659 660 661 662 663 664 665 666

    ## 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
667

668
    ## root password for Database
669 670
    #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
671 672

    ## password for phpmyadmin application
673 674
    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
675 676

    ## root password for Database
677 678
    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
679

680
#    echo "phpmyadmin phpmyadmin/password-confirm password ${DB_ROOT_PASSWORD}" | sudo debconf-set-selections
681 682

    ## installation of PHPMyAdmin server
683
    sudo apt-get install --assume-yes --force-yes --quiet phpmyadmin
684
  fi
685 686


687
## creation of shortcut
688 689 690 691 692
  ## if file exists
  if [ -e /var/www/phpmyadmin ]
  then
    error "file '/var/www/phpmyadmin' already exists!" ${E_ALREADY_INSTALLED}
  fi
693

694
  sudo ln -s /usr/share/phpmyadmin/ /var/www/phpmyadmin
695 696 697 698 699
fi




700

701
## configuration of network names if no DNS
702 703
#sudo sh -c "echo "192.168.1.101   ${TANGOSERVER}"  >> /etc/hosts"
#sudo sh -c 'echo "192.168.1.110   ${SERVERNAME}" >> /etc/hosts'
704 705 706 707 708





709
### installation of TANGO DB for TANGO server
710
if [ "${TANGO_DB}" -eq "1" ]
711 712 713
then
  info "installation of TANGO_DB"

714
  #tango-db depends on tango-common
715 716
  echo "tango-common tango-common/tango-host string ${TANGOSERVER}:20000" | sudo debconf-set-selections

717 718 719 720
  if [ "${DEBIAN_VERSION}" -gt "8" ]
  then
  ## Debian 9+/MariaDB
    echo 'tango-db tango-db/dbconfig-install boolean true' | sudo debconf-set-selections
721 722
    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
723 724 725 726
  else
    ## Debian 8-/MySQL

    echo 'tango-db tango-db/dbconfig-install boolean true' | sudo debconf-set-selections
727 728
    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
729 730
  fi

731
  sudo apt-get install --assume-yes tango-db
732 733 734 735 736 737

fi




738

739
### Installation of TANGO base tools
740
if [ "${TANGO}" -eq "1" ]
741
then
742 743
  info "installation of TANGO base tools"
### Installation of Java
744
  sudo apt-get --assume-yes install oracle-java8-installer oracle-java8-set-default
745
  ## needed to replace OpenJDK by Oracle Java
746
  sudo apt-get install --assume-yes libxrender1 libxtst6
747

748

gauron's avatar
gauron committed
749
### configuration of TANGO
750

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

gauron's avatar
gauron committed
754
## configuration into /etc/tangorc
755 756
sudo sh -c 'echo "source /etc/tangorc" >> /etc/bash.bashrc'
sudo sh -c 'echo "export TANGO_HOST" >> /etc/bash.bashrc'
757

758
## installation of TANGO
759 760 761 762
  if [ "${DEBIAN_VERSION}" -gt "8" ]
  then
  ## Debian 9 and +
    echo "installation TANGO Debian 9+"
763 764

    ## TANGO packages
765 766
    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
767 768 769 770 771 772 773 774

    ## 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
775
    pip install --no-index --find-links="${REPO_DIR}/pip-tmp" fandango==13.9.0 taurus==4.4.0 PyYAML==3.13 QtPy==1.2.1
776

777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
    ## Hggit configuration
    sudo apt install -y python-dulwich python-dev
    if [ ! -d "~/hgext" ]
    then
      mkdir -p ~/hgext
    fi
    cd ~/hgext
    if [ -d "~/hgext/hg-git" ]
    then
      hg clone https://bitbucket.org/durin42/hg-git
    fi
    cd hg-git
    sudo python setup.py install
    cd ../..

792 793 794 795 796 797 798 799
  else
  # Debian 8 and -
    echo "installation TANGO Debian 8-"
    sudo apt-get install --assume-yes --force-yes tango-common tango-starter tango-test python-pytango libtango8-doc libtango8-dev liblog4j1.2-java
    LIBTANGO_JAVA=libtango-java_8.1.2.c-1_all.deb
  fi
  if ! ( sudo apt-get install -f libtango-java )
  then
800
    if [ ! -f "${REPO_DIR}/tmp/${LIBTANGO_JAVA}" ]
801
    then
802
      wget -c "https://people.debian.org/~picca/${LIBTANGO_JAVA}" -P "${REPO_DIR}/tmp"
803
    fi
804
    sudo dpkg -i "${REPO_DIR}/tmp/${LIBTANGO_JAVA}"
805
  fi
806

807 808 809 810 811 812 813
fi






gauron's avatar
gauron committed
814
### installation of ArchivingRoot ###
815
if [ "${ARCHIVING}" -eq "1" ]
816
then
817
  info "installation of ARCHIVING"
818 819 820

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

822
  if [ -e "${REPO_DIR}/tmp/ArchivingRoot-last.zip" ]
823
  then
824
    cp "${REPO_DIR}/tmp/ArchivingRoot-last.zip" ./
825
  else
826
    wget -c "https://owncloud.lal.in2p3.fr/public.php?service=files&t=47ceb87fca676922732a3f5d34d4306d&download" -P "${REPO_DIR}/tmp" -O ArchivingRoot-last.zip
827
  fi
828
  sudo apt-get install unzip
829
  sudo unzip -o ArchivingRoot-last.zip
830
  sudo rm ArchivingRoot-last.zip
831
  cd "${REPO_DIR}/"
832

gauron's avatar
gauron committed
833
## configuration into /etc/tangorc
834
  sudo sh -c 'echo "ARCHIVING_ROOT=/opt/ArchivingRoot" >> /etc/tangorc'
835