a943fff6a7bcc60b2bb114c4ebac304d23688a0c
[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         set -x
68
69         git add -A
70         if ! git diff --exit-code ; then
71             git commit -m"prepare for deploy"
72         fi
73         for NODE in "${!NODES[@]}"
74         do
75             if test $NODE = localhost ; then
76                 sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}
77             else
78                 if ! ssh $NODE test -d arvados-setup.git ; then
79                     ssh $NODE git init --bare arvados-setup.git
80                     git remote add $NODE $DEPLOY_USER@$NODE:arvados-setup.git
81                     git push $NODE
82                     ssh $NODE git clone arvados-setup.git arvados-setup
83                 fi
84
85                 git push $NODE master
86                 ssh $NODE git -C arvados-setup pull
87
88                 ssh $DEPLOY_USER@$NODE "cd arvados-setup && sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}"
89             fi
90         done
91         ;;
92     *)
93         echo "Arvados installer"
94         echo ""
95         echo "initialize   initialize the setup directory for configuration"
96         echo "deploy       deploy the configuration from the setup directory"
97         ;;
98 esac