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