#!/usr/bin/env bash # Copyright © 2020 Interplanetary Database Association e.V., # Planetmint and IPDB software contributors. # SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) # Code is Apache-2.0 and docs are CC-BY-4.0 set -o nounset # Make sure umask is sane umask 022 # defaults stack_branch=${STACK_BRANCH:="master"} stack_repo=${STACK_REPO:="planetmint/planetmint"} stack_size=${STACK_SIZE:=4} stack_type=${STACK_TYPE:="docker"} stack_type_provider=${STACK_TYPE_PROVIDER:=""} tm_version=${TM_VERSION:="0.31.5"} mongo_version=${MONGO_VERSION:="3.6"} stack_vm_memory=${STACK_VM_MEMORY:=2048} stack_vm_cpus=${STACK_VM_CPUS:=2} stack_box_name=${STACK_BOX_NAME:="ubuntu/xenial64"} azure_subscription_id=${AZURE_SUBSCRIPTION_ID:=""} azure_tenant_id=${AZURE_TENANT_ID:=""} azure_client_secret=${AZURE_CLIENT_SECRET:=""} azure_client_id=${AZURE_CLIENT_ID:=""} azure_region=${AZURE_REGION:="westeurope"} azure_image_urn=${AZURE_IMAGE_URN:="Canonical:UbuntuServer:16.04-LTS:latest"} azure_resource_group=${AZURE_RESOURCE_GROUP:="bdb-vagrant-rg-$(date '+%Y-%m-%d')"} azure_dns_prefix=${AZURE_DNS_PREFIX:="bdb-instance-$(date '+%Y-%m-%d')"} azure_admin_username=${AZURE_ADMIN_USERNAME:="vagrant"} azure_vm_size=${AZURE_VM_SIZE:="Standard_D2_v2"} ssh_private_key_path=${SSH_PRIVATE_KEY_PATH:=""} unstack_type=${UNSTACK_TYPE:="hard"} # Check for uninitialized variables NOUNSET=${NOUNSET:-} if [[ -n "$NOUNSET" ]]; then set -o nounset fi TOP_DIR=$(cd $(dirname "$0") && pwd) SCRIPTS_DIR=$TOP_DIR/planetmint/pkg/scripts CONF_DIR=$TOP_DIR/planetmint/pkg/configuration function usage() { cat < >(tee $log_file) 2>&1 echo "Capturing output to $log_file" echo "Installation started at $(date '+%Y-%m-%d %H:%M:%S')" function finish() { echo "Installation finished at $(date '+%Y-%m-%d %H:%M:%S')" } trap finish EXIT export STACK_REPO=$stack_repo export STACK_BRANCH=$stack_branch echo "Using planetmint repo: '$STACK_REPO'" echo "Using planetmint branch '$STACK_BRANCH'" git clone https://github.com/${stack_repo}.git -b ${stack_branch} || true # Source utility functions source ${SCRIPTS_DIR}/functions-common if [[ $stack_type == "local" ]]; then mongo_version=$(echo "$mongo_version" | cut -d. -f-2) fi # configure stack-config.yml cat >$TOP_DIR/planetmint/pkg/configuration/vars/stack-config.yml < $CONF_DIR/hosts/all << EOF $(hostname) ansible_connection=local EOF ansible-playbook $CONF_DIR/planetmint-stop.yml -i $CONF_DIR/hosts/all \ --extra-vars "operation=stop home_path=${TOP_DIR}" else echo "Invalid Stack Type OR Provider" exit 1 fi # Kill background processes on exit trap exit_trap EXIT function exit_trap { exit $? } # Exit on any errors so that errors don't compound and kill if any services already started trap err_trap ERR function err_trap { local r=$? tmux kill-session bdb-dev set +o xtrace exit $? } echo -e "Finished unstacking!!" set -o errexit