20035: Improves the connector script in various ways.
[arvados.git] / tools / salt-install / provision.sh
1 #!/bin/bash
2
3 # Copyright (C) The Arvados Authors. All rights reserved.
4 #
5 # SPDX-License-Identifier: CC-BY-SA-3.0
6
7 # If you want to test arvados in a single host, you can run this script, which
8 # will install it using salt masterless
9 # This script is run by the Vagrant file when you run it with
10 #
11 # vagrant up
12
13 set -o pipefail
14
15 # capture the directory that the script is running from
16 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
17
18 usage() {
19   echo >&2
20   echo >&2 "Usage: ${0} [-h] [-h]"
21   echo >&2
22   echo >&2 "${0} options:"
23   echo >&2 "  -d, --debug                                 Run salt installation in debug mode"
24   echo >&2 "  -c <local.params>, --config <local.params>  Path to the local.params config file"
25   echo >&2 "  -t, --test                                  Test installation running a CWL workflow"
26   echo >&2 "  -r, --roles                                 List of Arvados roles to apply to the host, comma separated"
27   echo >&2 "                                              Possible values are:"
28   echo >&2 "                                                api"
29   echo >&2 "                                                controller"
30   echo >&2 "                                                dispatcher"
31   echo >&2 "                                                keepproxy"
32   echo >&2 "                                                keepbalance"
33   echo >&2 "                                                keepstore"
34   echo >&2 "                                                keepweb"
35   echo >&2 "                                                shell"
36   echo >&2 "                                                webshell"
37   echo >&2 "                                                websocket"
38   echo >&2 "                                                workbench"
39   echo >&2 "                                                workbench2"
40   echo >&2 "                                              Defaults to applying them all"
41   echo >&2 "  -h, --help                                  Display this help and exit"
42   echo >&2 "  --dump-config <dest_dir>                    Dumps the pillars and states to a directory"
43   echo >&2 "                                              This parameter does not perform any installation at all. It's"
44   echo >&2 "                                              intended to give you a parsed set of configuration files so"
45   echo >&2 "                                              you can inspect them or use them in you Saltstack infrastructure."
46   echo >&2 "                                              It"
47   echo >&2 "                                                - parses the pillar and states templates,"
48   echo >&2 "                                                - downloads the helper formulas with their desired versions,"
49   echo >&2 "                                                - prepares the 'top.sls' files both for pillars and states"
50   echo >&2 "                                                  for the selected role(s)"
51   echo >&2 "                                                - writes the resulting files into <dest_dir>"
52   echo >&2 "  -v, --vagrant                               Run in vagrant and use the /vagrant shared dir"
53   echo >&2 "  --development                               Run in dev mode, using snakeoil certs"
54   echo >&2
55 }
56
57 arguments() {
58   # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
59   if ! which getopt > /dev/null; then
60     echo >&2 "GNU getopt is required to run this script. Please install it and re-reun it"
61     exit 1
62   fi
63
64   TEMP=$(getopt -o c:dhp:r:tv \
65     --long config:,debug,development,dump-config:,help,roles:,test,vagrant \
66     -n "${0}" -- "${@}")
67
68   if [ ${?} != 0 ];
69     then echo "Please check the parameters you entered and re-run again"
70     exit 1
71   fi
72   # Note the quotes around `$TEMP': they are essential!
73   eval set -- "$TEMP"
74
75   while [ ${#} -ge 1 ]; do
76     case ${1} in
77       -c | --config)
78         CONFIG_FILE=${2}
79         shift 2
80         ;;
81       -d | --debug)
82         LOG_LEVEL="debug"
83         shift
84         set -x
85         ;;
86       --dump-config)
87         if [[ ${2} = /* ]]; then
88           DUMP_SALT_CONFIG_DIR=${2}
89         else
90           DUMP_SALT_CONFIG_DIR=${PWD}/${2}
91         fi
92         ## states
93         S_DIR="${DUMP_SALT_CONFIG_DIR}/salt"
94         ## formulas
95         F_DIR="${DUMP_SALT_CONFIG_DIR}/formulas"
96         ## pillars
97         P_DIR="${DUMP_SALT_CONFIG_DIR}/pillars"
98         ## tests
99         T_DIR="${DUMP_SALT_CONFIG_DIR}/tests"
100         DUMP_CONFIG="yes"
101         shift 2
102         ;;
103       --development)
104         DEV_MODE="yes"
105         shift 1
106         ;;
107       -r | --roles)
108         for i in ${2//,/ }
109           do
110             # Verify the role exists
111             if [[ ! "database,api,controller,keepstore,websocket,keepweb,workbench2,webshell,keepbalance,keepproxy,shell,workbench,dispatcher" == *"$i"* ]]; then
112               echo "The role '${i}' is not a valid role"
113               usage
114               exit 1
115             fi
116             ROLES="${ROLES} ${i}"
117           done
118           shift 2
119         ;;
120       -t | --test)
121         TEST="yes"
122         shift
123         ;;
124       -v | --vagrant)
125         VAGRANT="yes"
126         shift
127         ;;
128       --)
129         shift
130         break
131         ;;
132       *)
133         usage
134         exit 1
135         ;;
136     esac
137   done
138 }
139
140 copy_custom_cert() {
141   cert_dir=${1}
142   cert_name=${2}
143
144   mkdir -p /srv/salt/certs
145   chmod 700 /srv/salt/certs
146
147   if [ -f ${cert_dir}/${cert_name}.crt ]; then
148     cp -v ${cert_dir}/${cert_name}.crt /srv/salt/certs/arvados-${cert_name}.pem
149     chmod 600 /srv/salt/certs/arvados-${cert_name}.pem
150   else
151     echo "${cert_dir}/${cert_name}.crt does not exist. Exiting"
152     exit 1
153   fi
154   if [ -f ${cert_dir}/${cert_name}.key ]; then
155     cp -v ${cert_dir}/${cert_name}.key /srv/salt/certs/arvados-${cert_name}.key
156     chmod 600 /srv/salt/certs/arvados-${cert_name}.key
157   else
158     echo "${cert_dir}/${cert_name}.key does not exist. Exiting"
159     exit 1
160   fi
161 }
162
163 DEV_MODE="no"
164 CONFIG_FILE="${SCRIPT_DIR}/local.params"
165 CONFIG_DIR="local_config_dir"
166 DUMP_CONFIG="no"
167 LOG_LEVEL="info"
168 CONTROLLER_EXT_SSL_PORT=443
169 TESTS_DIR="tests"
170
171 NGINX_INSTALL_SOURCE="install_from_repo"
172
173 CLUSTER=""
174 DOMAIN=""
175
176 # Hostnames/IPs used for single-host deploys
177 IP_INT="127.0.1.1"
178
179 # Initial user setup
180 INITIAL_USER=""
181 INITIAL_USER_EMAIL=""
182 INITIAL_USER_PASSWORD=""
183
184 CONTROLLER_EXT_SSL_PORT=8000
185 KEEP_EXT_SSL_PORT=25101
186 # Both for collections and downloads
187 KEEPWEB_EXT_SSL_PORT=9002
188 WEBSHELL_EXT_SSL_PORT=4202
189 WEBSOCKET_EXT_SSL_PORT=8002
190 WORKBENCH1_EXT_SSL_PORT=443
191 WORKBENCH2_EXT_SSL_PORT=3001
192
193 SSL_MODE="self-signed"
194 USE_LETSENCRYPT_ROUTE53="no"
195 CUSTOM_CERTS_DIR="${SCRIPT_DIR}/local_config_dir/certs"
196
197 ## These are ARVADOS-related parameters
198 # For a stable release, change RELEASE "production" and VERSION to the
199 # package version (including the iteration, e.g. X.Y.Z-1) of the
200 # release.
201 # The "local.params.example.*" files already set "RELEASE=production"
202 # to deploy  production-ready packages
203 RELEASE="development"
204 VERSION="latest"
205
206 # These are arvados-formula-related parameters
207 # An arvados-formula tag. For a stable release, this should be a
208 # branch name (e.g. X.Y-dev) or tag for the release.
209 # ARVADOS_TAG="2.2.0"
210 # BRANCH="main"
211
212 # We pin the salt version to avoid potential incompatibilities when a new
213 # stable version is released.
214 SALT_VERSION="3004"
215
216 # Other formula versions we depend on
217 #POSTGRES_TAG="v0.44.0"
218 #POSTGRES_URL="https://github.com/saltstack-formulas/postgres-formula.git"
219 POSTGRES_TAG="0.45.0-bugfix327"
220 POSTGRES_URL="https://github.com/arvados/postgres-formula.git"
221 NGINX_TAG="v2.8.1"
222 DOCKER_TAG="v2.4.2"
223 LOCALE_TAG="v0.3.4"
224 LETSENCRYPT_TAG="v2.1.0"
225 LOGROTATE_TAG="v0.14.0"
226
227 # Salt's dir
228 DUMP_SALT_CONFIG_DIR=""
229 ## states
230 S_DIR="/srv/salt"
231 ## formulas
232 F_DIR="/srv/formulas"
233 ## pillars
234 P_DIR="/srv/pillars"
235 ## tests
236 T_DIR="/tmp/cluster_tests"
237
238 arguments ${@}
239
240 declare -A NODES
241
242 if [ -s ${CONFIG_FILE} ]; then
243   source ${CONFIG_FILE}
244 else
245   echo >&2 "You don't seem to have a config file with initial values."
246   echo >&2 "Please create a '${CONFIG_FILE}' file as described in"
247   echo >&2 "  * https://doc.arvados.org/install/salt-single-host.html#single_host, or"
248   echo >&2 "  * https://doc.arvados.org/install/salt-multi-host.html#multi_host_multi_hostnames"
249   exit 1
250 fi
251
252 if [ ! -d ${CONFIG_DIR} ]; then
253   echo >&2 "You don't seem to have a config directory with pillars and states."
254   echo >&2 "Please create a '${CONFIG_DIR}' directory (as configured in your '${CONFIG_FILE}'). Please see"
255   echo >&2 "  * https://doc.arvados.org/install/salt-single-host.html#single_host, or"
256   echo >&2 "  * https://doc.arvados.org/install/salt-multi-host.html#multi_host_multi_hostnames"
257   exit 1
258 fi
259
260 if grep -rni 'fixme' ${CONFIG_FILE} ${CONFIG_DIR} ; then
261   echo >&2 "The config file ${CONFIG_FILE} has some parameters that need to be modified."
262   echo >&2 "Please, fix them and re-run the provision script."
263   exit 1
264 fi
265
266 if ! grep -qE '^[[:alnum:]]{5}$' <<<${CLUSTER} ; then
267   echo >&2 "ERROR: <CLUSTER> must be exactly 5 lowercase alphanumeric characters long"
268   echo >&2 "Fix the cluster name in the 'local.params' file and re-run the provision script"
269   exit 1
270 fi
271
272 # Only used in single_host/single_name deploys
273 if [ ! -z "${HOSTNAME_EXT}" ] ; then
274   # We need to add some extra control vars to manage a single certificate vs. multiple
275   USE_SINGLE_HOSTNAME="yes"
276   # Make sure that the value configured as IP_INT is a real IP on the system.
277   # If we don't error out early here when there is a mismatch, the formula will
278   # fail with hard to interpret nginx errors later on.
279   ip addr list |grep "${IP_INT}/" >/dev/null
280   if [[ $? -ne 0 ]]; then
281     echo "Unable to find the IP_INT address '${IP_INT}' on the system, please correct the value in local.params. Exiting..."
282     exit 1
283   fi
284 else
285   USE_SINGLE_HOSTNAME="no"
286   # We set this variable, anyway, so sed lines do not fail and we don't need to add more
287   # conditionals
288   HOSTNAME_EXT="${CLUSTER}.${DOMAIN}"
289 fi
290
291 if [ "${DUMP_CONFIG}" = "yes" ]; then
292   echo "The provision installer will just dump a config under ${DUMP_SALT_CONFIG_DIR} and exit"
293 else
294   # Install a few dependency packages
295   # First, let's figure out the OS we're working on
296   OS_ID=$(grep ^ID= /etc/os-release |cut -f 2 -d=  |cut -f 2 -d \")
297   echo "Detected distro: ${OS_ID}"
298
299   case ${OS_ID} in
300     "centos")
301       echo "WARNING! Disabling SELinux, see https://dev.arvados.org/issues/18019"
302       sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/sysconfig/selinux
303       setenforce permissive
304       yum install -y  curl git jq
305       ;;
306     "debian"|"ubuntu")
307       # Wait 2 minutes for any apt locks to clear
308       # This option is supported from apt 1.9.1 and ignored in older apt versions.
309       # Cf. https://blog.sinjakli.co.uk/2021/10/25/waiting-for-apt-locks-without-the-hacky-bash-scripts/
310       DEBIAN_FRONTEND=noninteractive apt -o DPkg::Lock::Timeout=120 update
311       DEBIAN_FRONTEND=noninteractive apt install -y curl git jq
312       ;;
313   esac
314
315   if which salt-call; then
316     echo "Salt already installed"
317   else
318     curl -L https://bootstrap.saltstack.com -o /tmp/bootstrap_salt.sh
319     sh /tmp/bootstrap_salt.sh -XdfP -x python3 stable ${SALT_VERSION}
320     /bin/systemctl stop salt-minion.service
321     /bin/systemctl disable salt-minion.service
322   fi
323
324   # Set salt to masterless mode
325   cat > /etc/salt/minion << EOFSM
326 failhard: "True"
327
328 file_client: local
329 file_roots:
330   base:
331     - ${S_DIR}
332     - ${F_DIR}/*
333
334 pillar_roots:
335   base:
336     - ${P_DIR}
337 EOFSM
338 fi
339
340 mkdir -p ${S_DIR} ${F_DIR} ${P_DIR} ${T_DIR}
341
342 # Get the formula and dependencies
343 cd ${F_DIR} || exit 1
344 echo "Cloning formulas"
345 test -d docker && ( cd docker && git fetch ) \
346   || git clone --quiet https://github.com/saltstack-formulas/docker-formula.git ${F_DIR}/docker
347 ( cd docker && git checkout --quiet tags/"${DOCKER_TAG}" )
348
349 echo "...locale"
350 test -d locale && ( cd locale && git fetch ) \
351   || git clone --quiet https://github.com/saltstack-formulas/locale-formula.git ${F_DIR}/locale
352 ( cd locale && git checkout --quiet tags/"${LOCALE_TAG}" )
353
354 echo "...nginx"
355 test -d nginx && ( cd nginx && git fetch ) \
356   || git clone --quiet https://github.com/saltstack-formulas/nginx-formula.git ${F_DIR}/nginx
357 ( cd nginx && git checkout --quiet tags/"${NGINX_TAG}" )
358
359 echo "...postgres"
360 test -d postgres && ( cd postgres && git fetch ) \
361   || git clone --quiet ${POSTGRES_URL} ${F_DIR}/postgres
362 ( cd postgres && git checkout --quiet tags/"${POSTGRES_TAG}" )
363
364 echo "...letsencrypt"
365 test -d letsencrypt && ( cd letsencrypt && git fetch ) \
366   || git clone --quiet https://github.com/saltstack-formulas/letsencrypt-formula.git ${F_DIR}/letsencrypt
367 ( cd letsencrypt && git checkout --quiet tags/"${LETSENCRYPT_TAG}" )
368
369 echo "...logrotate"
370 test -d logrotate && ( cd logrotate && git fetch ) \
371   || git clone --quiet https://github.com/saltstack-formulas/logrotate-formula.git ${F_DIR}/logrotate
372 ( cd logrotate && git checkout --quiet tags/"${LOGROTATE_TAG}" )
373
374 echo "...arvados"
375 test -d arvados || git clone --quiet https://git.arvados.org/arvados-formula.git ${F_DIR}/arvados
376
377 # If we want to try a specific branch of the formula
378 if [ "x${BRANCH}" != "x" ]; then
379   ( cd ${F_DIR}/arvados && git checkout --quiet -t origin/"${BRANCH}" -b "${BRANCH}" )
380 elif [ "x${ARVADOS_TAG}" != "x" ]; then
381   ( cd ${F_DIR}/arvados && git checkout --quiet tags/"${ARVADOS_TAG}" -b "${ARVADOS_TAG}" )
382 fi
383
384 if [ "x${VAGRANT}" = "xyes" ]; then
385   EXTRA_STATES_DIR="/home/vagrant/${CONFIG_DIR}/states"
386   SOURCE_PILLARS_DIR="/home/vagrant/${CONFIG_DIR}/pillars"
387   SOURCE_TESTS_DIR="/home/vagrant/${TESTS_DIR}"
388 else
389   EXTRA_STATES_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/states"
390   SOURCE_PILLARS_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/pillars"
391   SOURCE_TESTS_DIR="${SCRIPT_DIR}/${TESTS_DIR}"
392 fi
393
394 SOURCE_STATES_DIR="${EXTRA_STATES_DIR}"
395
396 echo "Writing pillars and states"
397
398 # Replace variables (cluster,  domain, etc) in the pillars, states and tests
399 # to ease deployment for newcomers
400 if [ ! -d "${SOURCE_PILLARS_DIR}" ]; then
401   echo "${SOURCE_PILLARS_DIR} does not exist or is not a directory. Exiting."
402   exit 1
403 fi
404 for f in $(ls "${SOURCE_PILLARS_DIR}"/*); do
405   sed "s#__ANONYMOUS_USER_TOKEN__#${ANONYMOUS_USER_TOKEN}#g;
406        s#__BLOB_SIGNING_KEY__#${BLOB_SIGNING_KEY}#g;
407        s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
408        s#__CLUSTER__#${CLUSTER}#g;
409        s#__DOMAIN__#${DOMAIN}#g;
410        s#__HOSTNAME_EXT__#${HOSTNAME_EXT}#g;
411        s#__IP_INT__#${IP_INT}#g;
412        s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
413        s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g;
414        s#__INITIAL_USER__#${INITIAL_USER}#g;
415        s#__LE_AWS_REGION__#${LE_AWS_REGION}#g;
416        s#__LE_AWS_SECRET_ACCESS_KEY__#${LE_AWS_SECRET_ACCESS_KEY}#g;
417        s#__LE_AWS_ACCESS_KEY_ID__#${LE_AWS_ACCESS_KEY_ID}#g;
418        s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
419        s#__KEEPWEB_EXT_SSL_PORT__#${KEEPWEB_EXT_SSL_PORT}#g;
420        s#__KEEP_EXT_SSL_PORT__#${KEEP_EXT_SSL_PORT}#g;
421        s#__MANAGEMENT_TOKEN__#${MANAGEMENT_TOKEN}#g;
422        s#__RELEASE__#${RELEASE}#g;
423        s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g;
424        s#__VERSION__#${VERSION}#g;
425        s#__WEBSHELL_EXT_SSL_PORT__#${WEBSHELL_EXT_SSL_PORT}#g;
426        s#__WEBSOCKET_EXT_SSL_PORT__#${WEBSOCKET_EXT_SSL_PORT}#g;
427        s#__WORKBENCH1_EXT_SSL_PORT__#${WORKBENCH1_EXT_SSL_PORT}#g;
428        s#__WORKBENCH2_EXT_SSL_PORT__#${WORKBENCH2_EXT_SSL_PORT}#g;
429        s#__CLUSTER_INT_CIDR__#${CLUSTER_INT_CIDR}#g;
430        s#__CONTROLLER_INT_IP__#${CONTROLLER_INT_IP}#g;
431        s#__WEBSOCKET_INT_IP__#${WEBSOCKET_INT_IP}#g;
432        s#__KEEP_INT_IP__#${KEEP_INT_IP}#g;
433        s#__KEEPSTORE0_INT_IP__#${KEEPSTORE0_INT_IP}#g;
434        s#__KEEPSTORE1_INT_IP__#${KEEPSTORE1_INT_IP}#g;
435        s#__KEEPWEB_INT_IP__#${KEEPWEB_INT_IP}#g;
436        s#__WEBSHELL_INT_IP__#${WEBSHELL_INT_IP}#g;
437        s#__SHELL_INT_IP__#${SHELL_INT_IP}#g;
438        s#__WORKBENCH1_INT_IP__#${WORKBENCH1_INT_IP}#g;
439        s#__WORKBENCH2_INT_IP__#${WORKBENCH2_INT_IP}#g;
440        s#__DATABASE_INT_IP__#${DATABASE_INT_IP}#g;
441        s#__WORKBENCH_SECRET_KEY__#${WORKBENCH_SECRET_KEY}#g;
442        s#__SSL_KEY_ENCRYPTED__#${SSL_KEY_ENCRYPTED}#g;
443        s#__SSL_KEY_AWS_REGION__#${SSL_KEY_AWS_REGION}#g;
444        s#__SSL_KEY_AWS_SECRET_NAME__#${SSL_KEY_AWS_SECRET_NAME}#g" \
445   "${f}" > "${P_DIR}"/$(basename "${f}")
446 done
447
448 if [ ! -d "${SOURCE_TESTS_DIR}" ]; then
449   echo "WARNING: The tests directory was not copied to \"${SOURCE_TESTS_DIR}\"."
450   if [ "x${TEST}" = "xyes" ]; then
451     echo "WARNING: Disabling tests for this installation."
452   fi
453   TEST="no"
454 else
455   mkdir -p ${T_DIR}
456   # Replace cluster and domain name in the test files
457   for f in $(ls "${SOURCE_TESTS_DIR}"/*); do
458     FILTERS="s#__CLUSTER__#${CLUSTER}#g;
459          s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
460          s#__DOMAIN__#${DOMAIN}#g;
461          s#__IP_INT__#${IP_INT}#g;
462          s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
463          s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g
464          s#__INITIAL_USER__#${INITIAL_USER}#g;
465          s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
466          s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g"
467     if [ "$USE_SINGLE_HOSTNAME" = "yes" ]; then
468       FILTERS="s#__CLUSTER__.__DOMAIN__#${HOSTNAME_EXT}#g;
469          $FILTERS"
470     fi
471     sed "$FILTERS" \
472       "${f}" > ${T_DIR}/$(basename "${f}")
473   done
474   chmod 755 ${T_DIR}/run-test.sh
475 fi
476
477 # Replace helper state files that differ from the formula's examples
478 if [ -d "${SOURCE_STATES_DIR}" ]; then
479   mkdir -p "${F_DIR}"/extra/extra
480
481   for f in $(ls "${SOURCE_STATES_DIR}"/*); do
482     sed "s#__ANONYMOUS_USER_TOKEN__#${ANONYMOUS_USER_TOKEN}#g;
483          s#__CLUSTER__#${CLUSTER}#g;
484          s#__BLOB_SIGNING_KEY__#${BLOB_SIGNING_KEY}#g;
485          s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
486          s#__DOMAIN__#${DOMAIN}#g;
487          s#__HOSTNAME_EXT__#${HOSTNAME_EXT}#g;
488          s#__IP_INT__#${IP_INT}#g;
489          s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
490          s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g;
491          s#__INITIAL_USER__#${INITIAL_USER}#g;
492          s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
493          s#__KEEPWEB_EXT_SSL_PORT__#${KEEPWEB_EXT_SSL_PORT}#g;
494          s#__KEEP_EXT_SSL_PORT__#${KEEP_EXT_SSL_PORT}#g;
495          s#__MANAGEMENT_TOKEN__#${MANAGEMENT_TOKEN}#g;
496          s#__RELEASE__#${RELEASE}#g;
497          s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g;
498          s#__VERSION__#${VERSION}#g;
499          s#__CLUSTER_INT_CIDR__#${CLUSTER_INT_CIDR}#g;
500          s#__CONTROLLER_INT_IP__#${CONTROLLER_INT_IP}#g;
501          s#__WEBSOCKET_INT_IP__#${WEBSOCKET_INT_IP}#g;
502          s#__KEEP_INT_IP__#${KEEP_INT_IP}#g;
503          s#__KEEPSTORE0_INT_IP__#${KEEPSTORE0_INT_IP}#g;
504          s#__KEEPSTORE1_INT_IP__#${KEEPSTORE1_INT_IP}#g;
505          s#__KEEPWEB_INT_IP__#${KEEPWEB_INT_IP}#g;
506          s#__WEBSHELL_INT_IP__#${WEBSHELL_INT_IP}#g;
507          s#__WORKBENCH1_INT_IP__#${WORKBENCH1_INT_IP}#g;
508          s#__WORKBENCH2_INT_IP__#${WORKBENCH2_INT_IP}#g;
509          s#__DATABASE_INT_IP__#${DATABASE_INT_IP}#g;
510          s#__WEBSHELL_EXT_SSL_PORT__#${WEBSHELL_EXT_SSL_PORT}#g;
511          s#__SHELL_INT_IP__#${SHELL_INT_IP}#g;
512          s#__WEBSOCKET_EXT_SSL_PORT__#${WEBSOCKET_EXT_SSL_PORT}#g;
513          s#__WORKBENCH1_EXT_SSL_PORT__#${WORKBENCH1_EXT_SSL_PORT}#g;
514          s#__WORKBENCH2_EXT_SSL_PORT__#${WORKBENCH2_EXT_SSL_PORT}#g;
515          s#__WORKBENCH_SECRET_KEY__#${WORKBENCH_SECRET_KEY}#g;
516          s#__SSL_KEY_ENCRYPTED__#${SSL_KEY_ENCRYPTED}#g;
517          s#__SSL_KEY_AWS_REGION__#${SSL_KEY_AWS_REGION}#g;
518          s#__SSL_KEY_AWS_SECRET_NAME__#${SSL_KEY_AWS_SECRET_NAME}#g" \
519     "${f}" > "${F_DIR}/extra/extra"/$(basename "${f}")
520   done
521 fi
522
523 # Now, we build the SALT states/pillars trees
524 # As we need to separate both states and pillars in case we want specific
525 # roles, we iterate on both at the same time
526
527 # States
528 cat > ${S_DIR}/top.sls << EOFTSLS
529 base:
530   '*':
531     - locale
532 EOFTSLS
533
534 # Pillars
535 cat > ${P_DIR}/top.sls << EOFPSLS
536 base:
537   '*':
538     - locale
539     - arvados
540 EOFPSLS
541
542 # States, extra states
543 if [ -d "${F_DIR}"/extra/extra ]; then
544   SKIP_SNAKE_OIL="snakeoil_certs"
545
546   if [[ "$DEV_MODE" = "yes" || "${SSL_MODE}" == "self-signed" ]] ; then
547     # In dev mode, we create some snake oil certs that we'll
548     # use as CUSTOM_CERTS, so we don't skip the states file.
549     # Same when using self-signed certificates.
550     SKIP_SNAKE_OIL="dont_add_snakeoil_certs"
551   fi
552   for f in $(ls "${F_DIR}"/extra/extra/*.sls | egrep -v "${SKIP_SNAKE_OIL}|shell_"); do
553   echo "    - extra.$(basename ${f} | sed 's/.sls$//g')" >> ${S_DIR}/top.sls
554   done
555   # Use byo or self-signed certificates
556   if [ "${SSL_MODE}" != "lets-encrypt" ]; then
557     mkdir -p "${F_DIR}"/extra/extra/files
558   fi
559 fi
560
561 # If we want specific roles for a node, just add the desired states
562 # and its dependencies
563 if [ -z "${ROLES}" ]; then
564   # States
565   echo "    - nginx.passenger" >> ${S_DIR}/top.sls
566   if [ "${SSL_MODE}" = "lets-encrypt" ]; then
567     if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
568       grep -q "aws_credentials" ${S_DIR}/top.sls || echo "    - extra.aws_credentials" >> ${S_DIR}/top.sls
569     fi
570     grep -q "letsencrypt" ${S_DIR}/top.sls || echo "    - letsencrypt" >> ${S_DIR}/top.sls
571   else
572     mkdir -p /srv/salt/certs
573     chmod 700 /srv/salt/certs
574     if [ "${SSL_MODE}" = "bring-your-own" ]; then
575       # Copy certs to formula extra/files
576       cp -rv ${CUSTOM_CERTS_DIR}/* /srv/salt/certs/
577       chmod 600 /srv/salt/certs/*
578       # We add the custom_certs state
579       grep -q "custom_certs" ${S_DIR}/top.sls || echo "    - extra.custom_certs" >> ${S_DIR}/top.sls
580       if [ "${SSL_KEY_ENCRYPTED}" = "yes" ]; then
581         grep -q "ssl_key_encrypted" ${S_DIR}/top.sls || echo "    - extra.ssl_key_encrypted" >> ${S_DIR}/top.sls
582       fi
583     fi
584     # In self-signed mode, the certificate files will be created and put in the
585     # destination directory by the snakeoil_certs.sls state file
586   fi
587
588   echo "    - postgres" >> ${S_DIR}/top.sls
589   echo "    - logrotate" >> ${S_DIR}/top.sls
590   echo "    - docker.software" >> ${S_DIR}/top.sls
591   echo "    - arvados" >> ${S_DIR}/top.sls
592   echo "    - extra.shell_sudo_passwordless" >> ${S_DIR}/top.sls
593   echo "    - extra.shell_cron_add_login_sync" >> ${S_DIR}/top.sls
594   echo "    - extra.passenger_rvm" >> ${S_DIR}/top.sls
595
596   # Pillars
597   echo "    - docker" >> ${P_DIR}/top.sls
598   echo "    - nginx_api_configuration" >> ${P_DIR}/top.sls
599   echo "    - logrotate_api" >> ${P_DIR}/top.sls
600   echo "    - nginx_controller_configuration" >> ${P_DIR}/top.sls
601   echo "    - nginx_keepproxy_configuration" >> ${P_DIR}/top.sls
602   echo "    - nginx_keepweb_configuration" >> ${P_DIR}/top.sls
603   echo "    - nginx_passenger" >> ${P_DIR}/top.sls
604   echo "    - nginx_websocket_configuration" >> ${P_DIR}/top.sls
605   echo "    - nginx_webshell_configuration" >> ${P_DIR}/top.sls
606   echo "    - nginx_workbench2_configuration" >> ${P_DIR}/top.sls
607   echo "    - nginx_workbench_configuration" >> ${P_DIR}/top.sls
608   echo "    - logrotate_wb1" >> ${P_DIR}/top.sls
609   echo "    - postgresql" >> ${P_DIR}/top.sls
610
611   # We need to tweak the Nginx's pillar depending whether we want plan nginx or nginx+passenger
612   NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
613   sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
614
615   if [ "${SSL_MODE}" = "lets-encrypt" ]; then
616     if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
617       grep -q "aws_credentials" ${P_DIR}/top.sls || echo "    - aws_credentials" >> ${P_DIR}/top.sls
618     fi
619     grep -q "letsencrypt" ${P_DIR}/top.sls || echo "    - letsencrypt" >> ${P_DIR}/top.sls
620
621     hosts=("controller" "websocket" "workbench" "workbench2" "webshell" "keepproxy")
622     if [ ${USE_SINGLE_HOSTNAME} = "no" ]; then
623       hosts+=("download" "collections")
624     else
625       hosts+=("keepweb")
626     fi
627
628     for c in "${hosts[@]}"; do
629       # Are we in a single-host-single-hostname env?
630       if [ "${USE_SINGLE_HOSTNAME}" = "yes" ]; then
631         # Are we in a single-host-single-hostname env?
632         CERT_NAME=${HOSTNAME_EXT}
633       else
634         # We are in a multiple-hostnames env
635         CERT_NAME=${c}.${CLUSTER}.${DOMAIN}
636       fi
637
638       # As the pillar differs whether we use LE or custom certs, we need to do a final edition on them
639       sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${CERT_NAME}*/g;
640               s#__CERT_PEM__#/etc/letsencrypt/live/${CERT_NAME}/fullchain.pem#g;
641               s#__CERT_KEY__#/etc/letsencrypt/live/${CERT_NAME}/privkey.pem#g" \
642       ${P_DIR}/nginx_${c}_configuration.sls
643     done
644   else
645     # Use custom certs (either dev mode or prod)
646     grep -q "extra_custom_certs" ${P_DIR}/top.sls || echo "    - extra_custom_certs" >> ${P_DIR}/top.sls
647     # And add the certs in the custom_certs pillar
648     echo "extra_custom_certs_dir: /srv/salt/certs" > ${P_DIR}/extra_custom_certs.sls
649     echo "extra_custom_certs:" >> ${P_DIR}/extra_custom_certs.sls
650
651     for c in controller websocket workbench workbench2 webshell keepweb keepproxy; do
652       # Are we in a single-host-single-hostname env?
653       if [ "${USE_SINGLE_HOSTNAME}" = "yes" ]; then
654         # Are we in a single-host-single-hostname env?
655         CERT_NAME=${HOSTNAME_EXT}
656       else
657         # We are in a multiple-hostnames env
658         CERT_NAME=${c}
659       fi
660
661       if [[ "$SSL_MODE" == "bring-your-own" ]]; then
662         copy_custom_cert ${CUSTOM_CERTS_DIR} ${CERT_NAME}
663       fi
664
665       grep -q ${CERT_NAME} ${P_DIR}/extra_custom_certs.sls || echo "  - ${CERT_NAME}" >> ${P_DIR}/extra_custom_certs.sls
666
667       # As the pillar differs whether we use LE or custom certs, we need to do a final edition on them
668       sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${CERT_NAME}.pem/g;
669               s#__CERT_PEM__#/etc/nginx/ssl/arvados-${CERT_NAME}.pem#g;
670               s#__CERT_KEY__#/etc/nginx/ssl/arvados-${CERT_NAME}.key#g" \
671       ${P_DIR}/nginx_${c}_configuration.sls
672     done
673   fi
674 else
675   # If we add individual roles, make sure we add the repo first
676   echo "    - arvados.repo" >> ${S_DIR}/top.sls
677   # We add the extra_custom_certs state
678   grep -q "extra.custom_certs"    ${S_DIR}/top.sls || echo "    - extra.custom_certs" >> ${S_DIR}/top.sls
679   if [ "${SSL_KEY_ENCRYPTED}" = "yes" ]; then
680     grep -q "ssl_key_encrypted" ${S_DIR}/top.sls || echo "    - extra.ssl_key_encrypted" >> ${S_DIR}/top.sls
681   fi
682
683   # And we add the basic part for the certs pillar
684   if [ "${SSL_MODE}" != "lets-encrypt" ]; then
685     # And add the certs in the custom_certs pillar
686     echo "extra_custom_certs_dir: /srv/salt/certs" > ${P_DIR}/extra_custom_certs.sls
687     echo "extra_custom_certs:" >> ${P_DIR}/extra_custom_certs.sls
688     grep -q "extra_custom_certs" ${P_DIR}/top.sls || echo "    - extra_custom_certs" >> ${P_DIR}/top.sls
689   fi
690
691   for R in ${ROLES}; do
692     case "${R}" in
693       "database")
694         # States
695         echo "    - postgres" >> ${S_DIR}/top.sls
696         # Pillars
697         echo '    - postgresql' >> ${P_DIR}/top.sls
698       ;;
699       "api")
700         # States
701         grep -q "    - logrotate" ${S_DIR}/top.sls || echo "    - logrotate" >> ${S_DIR}/top.sls
702         if grep -q "    - nginx.*$" ${S_DIR}/top.sls; then
703           sed -i s/"^    - nginx.*$"/"    - nginx.passenger"/g ${S_DIR}/top.sls
704         else
705           echo "    - nginx.passenger" >> ${S_DIR}/top.sls
706         fi
707         echo "    - extra.passenger_rvm" >> ${S_DIR}/top.sls
708         ### If we don't install and run LE before arvados-api-server, it fails and breaks everything
709         ### after it. So we add this here as we are, after all, sharing the host for api and controller
710         if [ "${SSL_MODE}" = "lets-encrypt" ]; then
711           if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
712             grep -q "aws_credentials" ${S_DIR}/top.sls || echo "    - aws_credentials" >> ${S_DIR}/top.sls
713           fi
714           grep -q "letsencrypt" ${S_DIR}/top.sls || echo "    - letsencrypt" >> ${S_DIR}/top.sls
715         else
716           # Use custom certs
717           if [ "${SSL_MODE}" = "bring-your-own" ]; then
718             copy_custom_cert ${CUSTOM_CERTS_DIR} controller
719           fi
720           grep -q controller ${P_DIR}/extra_custom_certs.sls || echo "  - controller" >> ${P_DIR}/extra_custom_certs.sls
721         fi
722         grep -q "arvados.${R}" ${S_DIR}/top.sls    || echo "    - arvados.${R}" >> ${S_DIR}/top.sls
723         # Pillars
724         grep -q "logrotate_api" ${P_DIR}/top.sls            || echo "    - logrotate_api" >> ${P_DIR}/top.sls
725         grep -q "aws_credentials" ${P_DIR}/top.sls          || echo "    - aws_credentials" >> ${P_DIR}/top.sls
726         grep -q "postgresql" ${P_DIR}/top.sls               || echo "    - postgresql" >> ${P_DIR}/top.sls
727         grep -q "nginx_passenger" ${P_DIR}/top.sls          || echo "    - nginx_passenger" >> ${P_DIR}/top.sls
728         grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo "    - nginx_${R}_configuration" >> ${P_DIR}/top.sls
729
730         # We need to tweak the Nginx's pillar depending whether we want plain nginx or nginx+passenger
731         NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
732         sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
733       ;;
734       "controller" | "websocket" | "workbench" | "workbench2" | "webshell" | "keepweb" | "keepproxy")
735         # States
736         if [ "${R}" = "workbench" ]; then
737           grep -q "    - logrotate" ${S_DIR}/top.sls || echo "    - logrotate" >> ${S_DIR}/top.sls
738           NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
739           if grep -q "    - nginx$" ${S_DIR}/top.sls; then
740             sed -i s/"^    - nginx.*$"/"    - nginx.passenger"/g ${S_DIR}/top.sls
741           else
742             echo "    - nginx.passenger" >> ${S_DIR}/top.sls
743           fi
744         else
745           grep -q "nginx" ${S_DIR}/top.sls || echo "    - nginx" >> ${S_DIR}/top.sls
746         fi
747         if [ "${SSL_MODE}" = "lets-encrypt" ]; then
748           if [ "x${USE_LETSENCRYPT_ROUTE53}" = "xyes" ]; then
749             grep -q "aws_credentials" ${S_DIR}/top.sls || echo "    - aws_credentials" >> ${S_DIR}/top.sls
750           fi
751           grep -q "letsencrypt"     ${S_DIR}/top.sls || echo "    - letsencrypt" >> ${S_DIR}/top.sls
752         else
753           # Use custom certs, special case for keepweb
754           if [ ${R} = "keepweb" ]; then
755             if [ "${SSL_MODE}" = "bring-your-own" ]; then
756               copy_custom_cert ${CUSTOM_CERTS_DIR} download
757               copy_custom_cert ${CUSTOM_CERTS_DIR} collections
758             fi
759           else
760             if [ "${SSL_MODE}" = "bring-your-own" ]; then
761               copy_custom_cert ${CUSTOM_CERTS_DIR} ${R}
762             fi
763           fi
764         fi
765         # webshell role is just a nginx vhost, so it has no state
766         if [ "${R}" != "webshell" ]; then
767           grep -q "arvados.${R}" ${S_DIR}/top.sls || echo "    - arvados.${R}" >> ${S_DIR}/top.sls
768         fi
769         # Pillars
770         if [ "${R}" = "workbench" ]; then
771           grep -q "logrotate_wb1" ${P_DIR}/top.sls || echo "    - logrotate_wb1" >> ${P_DIR}/top.sls
772         fi
773         grep -q "nginx_passenger" ${P_DIR}/top.sls          || echo "    - nginx_passenger" >> ${P_DIR}/top.sls
774         grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo "    - nginx_${R}_configuration" >> ${P_DIR}/top.sls
775         # Special case for keepweb
776         if [ ${R} = "keepweb" ]; then
777           grep -q "nginx_download_configuration" ${P_DIR}/top.sls || echo "    - nginx_download_configuration" >> ${P_DIR}/top.sls
778           grep -q "nginx_collections_configuration" ${P_DIR}/top.sls || echo "    - nginx_collections_configuration" >> ${P_DIR}/top.sls
779         fi
780
781         if [ "${SSL_MODE}" = "lets-encrypt" ]; then
782           if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
783             grep -q "aws_credentials" ${P_DIR}/top.sls || echo "    - aws_credentials" >> ${P_DIR}/top.sls
784           fi
785           grep -q "letsencrypt"     ${P_DIR}/top.sls || echo "    - letsencrypt" >> ${P_DIR}/top.sls
786           grep -q "letsencrypt_${R}_configuration" ${P_DIR}/top.sls || echo "    - letsencrypt_${R}_configuration" >> ${P_DIR}/top.sls
787
788           # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
789           # Special case for keepweb
790           if [ ${R} = "keepweb" ]; then
791             for kwsub in download collections; do
792               sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${kwsub}.${CLUSTER}.${DOMAIN}*/g;
793                       s#__CERT_PEM__#/etc/letsencrypt/live/${kwsub}.${CLUSTER}.${DOMAIN}/fullchain.pem#g;
794                       s#__CERT_KEY__#/etc/letsencrypt/live/${kwsub}.${CLUSTER}.${DOMAIN}/privkey.pem#g" \
795               ${P_DIR}/nginx_${kwsub}_configuration.sls
796             done
797           else
798             sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${R}.${CLUSTER}.${DOMAIN}*/g;
799                     s#__CERT_PEM__#/etc/letsencrypt/live/${R}.${CLUSTER}.${DOMAIN}/fullchain.pem#g;
800                     s#__CERT_KEY__#/etc/letsencrypt/live/${R}.${CLUSTER}.${DOMAIN}/privkey.pem#g" \
801             ${P_DIR}/nginx_${R}_configuration.sls
802           fi
803         else
804           grep -q "ssl_key_encrypted" ${P_DIR}/top.sls || echo "    - ssl_key_encrypted" >> ${P_DIR}/top.sls
805           # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
806           # Special case for keepweb
807           if [ ${R} = "keepweb" ]; then
808             for kwsub in download collections; do
809               sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${kwsub}.pem/g;
810                       s#__CERT_PEM__#/etc/nginx/ssl/arvados-${kwsub}.pem#g;
811                       s#__CERT_KEY__#/etc/nginx/ssl/arvados-${kwsub}.key#g" \
812               ${P_DIR}/nginx_${kwsub}_configuration.sls
813               grep -q ${kwsub} ${P_DIR}/extra_custom_certs.sls || echo "  - ${kwsub}" >> ${P_DIR}/extra_custom_certs.sls
814             done
815           else
816             sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${R}.pem/g;
817                     s#__CERT_PEM__#/etc/nginx/ssl/arvados-${R}.pem#g;
818                     s#__CERT_KEY__#/etc/nginx/ssl/arvados-${R}.key#g" \
819             ${P_DIR}/nginx_${R}_configuration.sls
820             grep -q ${R} ${P_DIR}/extra_custom_certs.sls || echo "  - ${R}" >> ${P_DIR}/extra_custom_certs.sls
821           fi
822         fi
823         # We need to tweak the Nginx's pillar depending whether we want plain nginx or nginx+passenger
824         sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
825       ;;
826       "shell")
827         # States
828         echo "    - extra.shell_sudo_passwordless" >> ${S_DIR}/top.sls
829         echo "    - extra.shell_cron_add_login_sync" >> ${S_DIR}/top.sls
830         grep -q "docker" ${S_DIR}/top.sls       || echo "    - docker.software" >> ${S_DIR}/top.sls
831         grep -q "arvados.${R}" ${S_DIR}/top.sls || echo "    - arvados.${R}" >> ${S_DIR}/top.sls
832         # Pillars
833         grep -q "docker" ${P_DIR}/top.sls       || echo "    - docker" >> ${P_DIR}/top.sls
834       ;;
835       "dispatcher" | "keepbalance" | "keepstore")
836         # States
837         grep -q "arvados.${R}" ${S_DIR}/top.sls || echo "    - arvados.${R}" >> ${S_DIR}/top.sls
838         # Pillars
839         # ATM, no specific pillar needed
840       ;;
841       *)
842         echo "Unknown role ${R}"
843         exit 1
844       ;;
845     esac
846   done
847 fi
848
849 if [ "${DUMP_CONFIG}" = "yes" ]; then
850   # We won't run the rest of the script because we're just dumping the config
851   exit 0
852 fi
853
854 # Now run the install
855 salt-call --state-output=mixed --local state.apply -l ${LOG_LEVEL}
856
857 # Finally, make sure that /etc/hosts is not overwritten on reboot
858 if [ -d /etc/cloud/cloud.cfg.d ]; then
859   # TODO: will this work on CentOS?
860   sed -i 's/^manage_etc_hosts: true/#manage_etc_hosts: true/g' /etc/cloud/cloud.cfg.d/*
861 fi
862
863 # Leave a copy of the Arvados CA so the user can copy it where it's required
864 if [ "${SSL_MODE}" = "self-signed" ]; then
865   echo "Copying the Arvados CA certificate '${CLUSTER}.${DOMAIN}-arvados-snakeoil-ca.crt' to the installer dir, so you can import it"
866   if [ "x${VAGRANT}" = "xyes" ]; then
867     cp /etc/ssl/certs/arvados-snakeoil-ca.pem /vagrant/${CLUSTER}.${DOMAIN}-arvados-snakeoil-ca.pem
868   else
869     cp /etc/ssl/certs/arvados-snakeoil-ca.pem ${SCRIPT_DIR}/${CLUSTER}.${DOMAIN}-arvados-snakeoil-ca.crt
870   fi
871 fi
872
873 if [ "x${VAGRANT}" = "xyes" ]; then
874     # If running in a vagrant VM, also add default user to docker group
875     echo "Adding the vagrant user to the docker group"
876     usermod -a -G docker vagrant
877 fi
878
879 # Test that the installation finished correctly
880 if [ "x${TEST}" = "xyes" ]; then
881   cd ${T_DIR}
882   # If we use RVM, we need to run this with it, or most ruby commands will fail
883   RVM_EXEC=""
884   if [ -x /usr/local/rvm/bin/rvm-exec ]; then
885     RVM_EXEC="/usr/local/rvm/bin/rvm-exec"
886   fi
887   ${RVM_EXEC} ./run-test.sh
888 fi