18870: New script to help manage install
authorPeter Amstutz <peter.amstutz@curii.com>
Sun, 26 Jun 2022 22:42:03 +0000 (18:42 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Tue, 28 Jun 2022 18:20:35 +0000 (14:20 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

tools/salt-install/installer.sh [new file with mode: 0755]

diff --git a/tools/salt-install/installer.sh b/tools/salt-install/installer.sh
new file mode 100755 (executable)
index 0000000..7bd789f
--- /dev/null
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: CC-BY-SA-3.0
+
+set -e
+
+subcmd="$1"
+if test -n "$subcmd" ; then
+    shift
+fi
+case "$subcmd" in
+    initialize)
+       if ! test -f provision.sh ; then
+           echo "Must be run from arvados/tools/salt-install"
+           exit
+       fi
+
+       SETUPDIR=$1
+       PARAMS=$2
+       SLS=$3
+
+       err=
+       if test -z "$PARAMS" -o ! -f local.params.example.$PARAMS ; then
+           echo "Not found: local.params.example.$PARAMS"
+           echo "Expected one of multiple_hosts, single_host_multiple_hostnames, single_host_single_hostname"
+           err=1
+       fi
+
+       if test -z "$SLS" -o ! -d config_examples/$SLS ; then
+           echo "Not found: config_examples/$SLS"
+           echo "Expected one of multi_host/aws, single_host/multiple_hostnames, single_host/single_hostname"
+           err=1
+       fi
+
+       if test -z "$SETUPDIR" -o -z "$PARAMS" -o -z "$SLS" ; then
+           echo "installer.sh <setup dir to initialize> <params template> <config template>"
+           err=1
+       fi
+
+       if test -n "$err" ; then
+           exit 1
+       fi
+
+       echo "Initializing $SETUPDIR"
+       git init $SETUPDIR
+       cp -r *.sh tests $SETUPDIR
+
+       cp local.params.example.$PARAMS $SETUPDIR/local.params
+       cp -r config_examples/$SLS $SETUPDIR/local_config_dir
+
+       cd $SETUPDIR
+       git add *.sh local.params local_config_dir tests
+       git commit -m"initial commit"
+
+       echo "setup directory initialized, now go to $SETUPDIR, edit 'local.params' and 'local_config_dir' as needed, then run 'installer.sh deploy'"
+    ;;
+    deploy)
+       CONFIG_FILE=local.params
+       if ! test -s $CONFIG_FILE ; then
+           echo "Must be run from arvados-setup, maybe you need to 'initialize' first?"
+       fi
+
+       source ${CONFIG_FILE}
+
+       git commit -m"prepare for deploy"
+       for NODE in "${!NODES[@]}"
+       do
+           if ! ssh $NODE test -d arvados-setup.git ; then
+               ssh $NODE git init --bare arvados-setup.git
+               git add remote $NODE $DEPLOY_USER@$NODE:arvados-setup.git
+               git push $NODE
+               ssh $NODE git clone arvados-setup.git arvados-setup
+           fi
+
+           git push $NODE master
+           ssh $NODE git -C arvados-setup pull
+
+           ssh $DEPLOY_USER@$NODE "cd arvados-setup && sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}"
+       done
+       ;;
+    *)
+       echo "Arvados installer"
+       echo ""
+       echo "initialize   initialize the setup directory for configuration"
+       echo "deploy       deploy the configuration from the setup directory"
+       ;;
+esac