grenade/setup-grenade
Adalberto Medeiros e64184bc16 Fix setup-grenade to pass user and host as parameter
setup-grenade was not working when defining a different username/host
when running ./setup-grenade <host> [<user>].

Change-Id: Ie9590878dafbdd2e3ff8b2d9779be6cdefe671b6
2013-05-03 15:32:19 -03:00

50 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# setup-grenade [hostname [username]]
#
# Assumes ssh keys set up to an account with root privs
# Configuration:
# * Reads ``grenaderc`` (and ``localrc``) if present;
# * Reads ``localrc`` if present and ``grenaderc`` is not present
# * Runs with sane defaults if no ``*rc`` file is present
# Keep track of the source directory
SRC_DIR=$(cd $(dirname "$0") && pwd)
# Set up some defaults if grenaderc is not present
GRENADE_REPO=https://github.com/openstack-dev/grenade.git
GRENADE_DIR=${STACK_ROOT}/grenade
GRENADE_BRANCH=master
STACK_ROOT=/opt/stack
GRENADE_DIR=${STACK_ROOT}/grenade
# Source params
if [[ -r $SRC_DIR/grenaderc ]]; then
source $SRC_DIR/grenaderc
elif [[ -r $SRCDIR/localrc ]]; then
source $SRC_DIR/localrc
fi
HOST=${1:-localhost}
DEST_USER=${2:-${USER:-stack}}
set -o xtrace
ssh -t $DEST_USER@$HOST " \
sudo mkdir -p ${STACK_ROOT}; \
[[ -w ${STACK_ROOT} ]] || sudo chown $DEST_USER ${STACK_ROOT}; \
[[ -d $GRENADE_DIR ]] || (cd ${STACK_ROOT}; git clone $GRENADE_REPO $GRENADE_DIR); \
[[ -d $GRENADE_DIR ]] && (cd $GRENADE_DIR; git checkout $GRENADE_BRANCH); \
"
# Copy devstack.localrc if it exists
if [[ -r $SRC_DIR/devstack.localrc ]]; then
scp -p $SRC_DIR/devstack.localrc $DEST_USER@$HOST:$GRENADE_DIR
fi
# Copy localrc if it exists
if [[ -r $SRC_DIR/localrc ]]; then
scp -p $SRC_DIR/localrc $DEST_USER@$HOST:$GRENADE_DIR
fi