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