18870: Updating params.local
[arvados.git] / tools / salt-install / installer.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 set -e
8
9 subcmd="$1"
10 if test -n "$subcmd" ; then
11     shift
12 fi
13 case "$subcmd" in
14     initialize)
15         if ! test -f provision.sh ; then
16             echo "Must be run from arvados/tools/salt-install"
17             exit
18         fi
19
20         SETUPDIR=$1
21         PARAMS=$2
22         SLS=$3
23
24         err=
25         if test -z "$PARAMS" -o ! -f local.params.example.$PARAMS ; then
26             echo "Not found: local.params.example.$PARAMS"
27             echo "Expected one of multiple_hosts, single_host_multiple_hostnames, single_host_single_hostname"
28             err=1
29         fi
30
31         if test -z "$SLS" -o ! -d config_examples/$SLS ; then
32             echo "Not found: config_examples/$SLS"
33             echo "Expected one of multi_host/aws, single_host/multiple_hostnames, single_host/single_hostname"
34             err=1
35         fi
36
37         if test -z "$SETUPDIR" -o -z "$PARAMS" -o -z "$SLS" ; then
38             echo "installer.sh <setup dir to initialize> <params template> <config template>"
39             err=1
40         fi
41
42         if test -n "$err" ; then
43             exit 1
44         fi
45
46         echo "Initializing $SETUPDIR"
47         git init $SETUPDIR
48         cp -r *.sh tests $SETUPDIR
49
50         cp local.params.example.$PARAMS $SETUPDIR/local.params
51         cp -r config_examples/$SLS $SETUPDIR/local_config_dir
52
53         cd $SETUPDIR
54         git add *.sh local.params local_config_dir tests
55         git commit -m"initial commit"
56
57         echo "setup directory initialized, now go to $SETUPDIR, edit 'local.params' and 'local_config_dir' as needed, then run 'installer.sh deploy'"
58     ;;
59     deploy)
60         CONFIG_FILE=local.params
61         if ! test -s $CONFIG_FILE ; then
62             echo "Must be run from arvados-setup, maybe you need to 'initialize' first?"
63         fi
64
65         source ${CONFIG_FILE}
66
67         git commit -m"prepare for deploy"
68         for NODE in "${!NODES[@]}"
69         do
70             if test $NODE = localhost ; then
71                 sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}
72             else
73                 if ! ssh $NODE test -d arvados-setup.git ; then
74                     ssh $NODE git init --bare arvados-setup.git
75                     git add remote $NODE $DEPLOY_USER@$NODE:arvados-setup.git
76                     git push $NODE
77                     ssh $NODE git clone arvados-setup.git arvados-setup
78                 fi
79
80                 git push $NODE master
81                 ssh $NODE git -C arvados-setup pull
82
83                 ssh $DEPLOY_USER@$NODE "cd arvados-setup && sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}"
84             fi
85         done
86         ;;
87     *)
88         echo "Arvados installer"
89         echo ""
90         echo "initialize   initialize the setup directory for configuration"
91         echo "deploy       deploy the configuration from the setup directory"
92         ;;
93 esac