blob: eb39b41ab8e2b69fbd9dc14ce54b6488acda44a1 [file] [log] [blame]
#!/bin/bash
# @@@ START COPYRIGHT @@@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# @@@ END COPYRIGHT @@@
# This script sets up the Command Line Interface(CLI) for various cloud environments
#
TRAF_CONFIG=/etc/trafodion/trafodion_config
source $TRAF_CONFIG
###### Setting up CLI for AWS as sudo id
if [[ ! -z $AWS_CLOUD ]]; then
###### Check for existence of aws
if [[ ! -d /usr/local/aws ]]; then
cd $HOME
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip $HOME/awscli-bundle.zip
if [[ $node_count -gt "1" ]]; then
$TRAF_PDCP $HOME/awscli-bundle $HOME
$TRAF_PDSH "sudo $HOME/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws" | tee -a $INSTALL_LOG
else
sudo $HOME/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws | tee -a $INSTALL_LOG
fi
$TRAF_PDSH "sudo rm -rf $HOME/awscli-bundle"
rm -f $HOME/awscli-bundle.zip
fi
###### Check for existence of .aws for trafodion id
###### Check if aws configuration file exist for Trafodion Id
AWSCONFIG_DIR=`sudo su $TRAF_USER --login --command "ls -altr | grep -w ".aws" | wc -l" `
if [[ $AWSCONFIG_DIR == 0 ]]; then
###### Execute 'aws configure' command as a Trafodion Id
echo
echo "***INFO: Configuring AWS keys for executing CLI commands"
echo
sudo su $TRAF_USER --login --command "/usr/local/bin/aws configure"
###### Copy the .aws folder to all nodes in the cluster for Trafodion Id
sudo su $TRAF_USER --login --command "$TRAF_PDCP $HOME_DIR/$TRAF_USER/.aws $HOME_DIR/$TRAF_USER"
echo
echo "***INFO: AWS configuration for trafodion id located in $HOME_DIR/$TRAF_USER/.aws"
echo
else
echo
echo "AWS Configuration already exist for Trafodion Id"
echo -n "Do you want to overwrite the configuration (Y/N), default is N: "
read answer
if [ ! -z $answer ]; then
if [[ "${answer}" =~ ^[Yy]$ ]]; then
###### Execute 'aws configure' command as a Trafodion id
echo
echo "***INFO: Configuring AWS keys for executing CLI commands"
echo
sudo su $TRAF_USER --login --command "/usr/local/bin/aws configure"
###### Copy the .aws folder to all nodes in the cluster for Trafodion Id
sudo su $TRAF_USER --login --command "$TRAF_PDCP $HOME_DIR/$TRAF_USER/.aws $HOME_DIR/$TRAF_USER"
echo
echo "***INFO: AWS configuration for trafodion id located in $HOME_DIR/$TRAF_USER/.aws"
echo
else
echo
echo "***INFO: Skipping AWS configuration setup"
echo
fi
fi
fi
fi