#!/bin/bash set -o errexit set -o nounset set +x usage() { cat </dev/null \ | sudo xargs -I % ln -fs % "$3" } install_config_profile() { if [ -d /tmp/custom ]; then rm -rf /opt/config/custom sudo mv /tmp/custom /opt/config/ fi # we're removing the whole directory and recreating to avoid # any quirks around dotfiles that might show up here. sudo rm -rf /etc/nomad.d sudo rm -rf /etc/consul.d sudo rm -rf /etc/vault.d sudo mkdir -p /etc/nomad.d sudo mkdir -p /etc/consul.d sudo mkdir -p /etc/vault.d sym "${NOMAD_PROFILE}/nomad/" '*' /etc/nomad.d sym "${NOMAD_PROFILE}/consul/" '*' /etc/consul.d sym "${NOMAD_PROFILE}/vault/" '*' /etc/vault.d if [ -n "$NOMAD_ROLE" ]; then sym "${NOMAD_PROFILE}/nomad/${NOMAD_ROLE}/" '*' /etc/nomad.d sym "${NOMAD_PROFILE}/consul/${NOMAD_ROLE}/" '*' /etc/consul.d sym "${NOMAD_PROFILE}/vault/${NOMAD_ROLE}/" '*' /etc/vault.d fi if [ -n "$NOMAD_INDEX" ]; then sym "${NOMAD_PROFILE}/nomad/${NOMAD_ROLE}/indexed/" "*${NOMAD_INDEX}*" /etc/nomad.d sym "${NOMAD_PROFILE}/consul/${NOMAD_ROLE}/indexed/" "*${NOMAD_INDEX}*" /etc/consul.d sym "${NOMAD_PROFILE}/vault/${NOMAD_ROLE}/indexed/" "*${NOMAD_INDEX}*" /etc/vault.d fi if [ $ACLS == "1" ]; then sudo ln -fs /opt/config/shared/nomad-acl.hcl /etc/nomad.d/acl.hcl fi } while [[ $# -gt 0 ]] do opt="$1" case $opt in --nomad_sha) if [ -z "$2" ]; then echo "Missing sha parameter"; usage; fi NOMAD_SHA="$2" install_fn=install_from_s3 shift 2 ;; --nomad_release | --nomad_version) if [ -z "$2" ]; then echo "Missing version parameter"; usage; fi NOMAD_VERSION="$2" install_fn=install_from_release shift 2 ;; --nomad_binary) if [ -z "$2" ]; then echo "Missing file parameter"; usage; fi NOMAD_UPLOADED_BINARY="$2" install_fn=install_from_uploaded_binary shift 2 ;; --config_profile) if [ -z "$2" ]; then echo "Missing profile parameter"; usage; fi NOMAD_PROFILE="/opt/config/${2}" shift 2 ;; --role) if [ -z "$2" ]; then echo "Missing role parameter"; usage; fi NOMAD_ROLE="$2" shift 2 ;; --index) if [ -z "$2" ]; then echo "Missing index parameter"; usage; fi NOMAD_INDEX="$2" shift 2 ;; --nostart) # for initial packer builds, we don't want to start Nomad START=0 shift ;; --enterprise) BUILD_FOLDER="builds-ent" shift ;; --nomad_acls) ACLS=1 shift ;; *) usage ;; esac done # call the appropriate installation function if [ -n "$install_fn" ]; then $install_fn fi if [ -n "$NOMAD_PROFILE" ]; then install_config_profile fi if [ $START == "1" ]; then if [ "$NOMAD_ROLE" == "server" ]; then sudo systemctl restart vault fi sudo systemctl restart consul sudo systemctl restart nomad fi