<commit_before>#!/bin/bash

set -e

master_dns_name=
s3_bucket_name=

function show_help() {
    cat << EOF
    Usage : $(basename "$0") --setup-local-env
            $(basename "$0") --create-cluster-config
            $(basename "$0") --ssh-aws-ec2
            $(basename "$0") --help                    

    Sets Up OpenEBS On AWS 
    
    -h|--help                       Display this help and exit.
    --setup-local-env               Sets up, AWSCLI, Terraform and KOPS.
    --create-cluster-config         Generates a terraform file(.tf) and Passwordless SSH
    --ssh-aws-ec2                   SSH to Kubernetes Master on EC2 instance.                             
EOF
}

function show_terraform_commands() {
    cat << EOF
    Run the terraform commands in the following order:
    $ terraform init
    $ terraform plan
    $ terraform apply
EOF
}

function setup_local_env() {

    echo "Installing Pre-requisites..."

    sudo apt-get update
    sudo apt-get install -y unzip curl wget

    IS_AWS_CLI_INSTALLED=$(which aws >> /dev/null 2>&1; echo $?)
    if [ $IS_AWS_CLI_INSTALLED -eq 0 ]; then
        echo "aws is installed; Skipping"
        sleep 2
    else
        echo "Missing aws; Installing..."
        sudo apt-get update
        sudo apt-get install -y python-pip
        sudo -H pip install awscli
    fi

    IS_TERRAFORM_INSTALLED=$(which terraform >> /dev/null 2>&1; echo $?)
    if [ $IS_TERRAFORM_INSTALLED -eq 0 ]; then
        echo "terraform is installed; Skipping"
        sleep 2
    else 
        echo "Missing terraform; Downloading and installing..."
        wget "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_linux_amd64.zip"
        unzip terraform_0.10.0_linux_amd64.zip
        chmod +x terraform
        sudo mv terraform /usr/local/bin/terraform
    fi

    IS_KOPS_INSTALLED=$(which kops >> /dev/null 2>&1; echo $?)
    if [ $IS_KOPS_INSTALLED -eq 0 ]; then
        echo "kops is installed; Skipping"
        sleep 2
    else
        echo "Missing kops; Downloading and installing..."
        wget "https://github.com/kubernetes/kops/releases/download/1.7.0/kops-linux-amd64"
        chmod +x kops-linux-amd64
        sudo mv kops-linux-amd64 /usr/local/bin/kops
    fi
}

function create_cluster_config() {

    echo "Creating Group on AWS for OpenEBS Users..."
    aws iam create-group --group-name openebsusers

    aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonEC2FullAccess --group-name openebsusers

    aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonRoute53FullAccess --group-name openebsusers

    aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess --group-name openebsusers

    aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/IAMFullAccess --group-name openebsusers

    aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonVPCFullAccess --group-name openebsusers

    aws iam add-user-to-group --user-name openebsuser01 --group-name openebsusers
    
    create_terraform_file
    
}

function create_terraform_file() {

    echo "Creating S3 bucket to store cluster state..."
    
    # Wait for AWS to refresh
    sleep 60

    # Create unique S3 bucket name for each user
    # Amazon S3 bucket names are universal
    s3_bucket_name=`echo $(mktemp)| tr '[:upper:]' '[:lower:]' | cut -d '.' -f 2`
    
    aws s3api create-bucket --bucket openebs-k8s-`echo $s3_bucket_name`-local-state-store

    if [ -e ~/.ssh/id_rsa.pub ];then
        echo "Using Public Key for Passwordless SSH."
    else
        echo "Generating Public Key for Passwordless SSH"
        ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
    fi

    echo "Generating terraform file(.tf)"

    kops create cluster --cloud=aws \
    --master-size=t2.micro \
    --master-zones=us-east-1a \
    --node-count=2 \
    --node-size=t2.micro \
    --zones=us-east-1a \
    --image=ami-2757f631 \
    --state=s3://openebs-k8s-local-state-store \
    --target=terraform \
    --out=. \
    --name=openebs.k8s.local

    show_terraform_commands
}

function ssh_aws_ec2() {

    master_dns_name=`aws ec2 describe-instances --region us-east-1 --query 'Reservations[].Instances[].[SecurityGroups[].GroupName,PublicDnsName]' | grep -A 2 masters | grep ec2 | tr -d '"'`
    if [ -z "$master_dns_name" ]; then
        echo " The EC2 instance is not available yet."
        exit 1
    fi    
    ssh -i ~/.ssh/id_rsa ubuntu@`echo $master_dns_name`
}

if (($# == 0)); then
    show_help
    exit 2<commit_msg>Add the S3 bucket name to kops create cluster command.<commit_after>#!/bin/bash

set -e

master_dns_name=
s3_bucket_name=

function show_help() {
    cat << EOF
    Usage : $(basename "$0") --setup-local-env
            $(basename "$0") --create-cluster-config
            $(basename "$0") --ssh-aws-ec2
            $(basename "$0") --help                    

    Sets Up OpenEBS On AWS 
    
    -h|--help                       Display this help and exit.
    --setup-local-env               Sets up, AWSCLI, Terraform and KOPS.
    --create-cluster-config         Generates a terraform file(.tf) and Passwordless SSH
    --ssh-aws-ec2                   SSH to Kubernetes Master on EC2 instance.                             
EOF
}

function show_terraform_commands() {
    cat << EOF
    Run the terraform commands in the following order:
    $ terraform init
    $ terraform plan
    $ terraform apply
EOF
}

function setup_local_env() {

    echo "Installing Pre-requisites..."

    sudo apt-get update
    sudo apt-get install -y unzip curl wget

    IS_AWS_CLI_INSTALLED=$(which aws >> /dev/null 2>&1; echo $?)
    if [ $IS_AWS_CLI_INSTALLED -eq 0 ]; then
        echo "aws is installed; Skipping"
        sleep 2
    else
        echo "Missing aws; Installing..."
        sudo apt-get update
        sudo apt-get install -y python-pip
        sudo -H pip install awscli
    fi

    IS_TERRAFORM_INSTALLED=$(which terraform >> /dev/null 2>&1; echo $?)
    if [ $IS_TERRAFORM_INSTALLED -eq 0 ]; then
        echo "terraform is installed; Skipping"
        sleep 2
    else 
        echo "Missing terraform; Downloading and installing..."
        wget "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_linux_amd64.zip"
        unzip terraform_0.10.0_linux_amd64.zip
        chmod +x terraform
        sudo mv terraform /usr/local/bin/terraform
    fi

    IS_KOPS_INSTALLED=$(which kops >> /dev/null 2>&1; echo $?)
    if [ $IS_KOPS_INSTALLED -eq 0 ]; then
        echo "kops is installed; Skipping"
        sleep 2
    else
        echo "Missing kops; Downloading and installing..."
        wget "https://github.com/kubernetes/kops/releases/download/1.7.0/kops-linux-amd64"
        chmod +x kops-linux-amd64
        sudo mv kops-linux-amd64 /usr/local/bin/kops
    fi
}

function create_cluster_config() {

    echo "Creating Group on AWS for OpenEBS Users..."
    aws iam create-group --group-name openebsusers

    aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonEC2FullAccess --group-name openebsusers

    aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonRoute53FullAccess --group-name openebsusers

    aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess --group-name openebsusers

    aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/IAMFullAccess --group-name openebsusers

    aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonVPCFullAccess --group-name openebsusers

    aws iam add-user-to-group --user-name openebsuser01 --group-name openebsusers
    
    create_terraform_file
    
}

function create_terraform_file() {

    echo "Creating S3 bucket to store cluster state..."
    
    # Wait for AWS to refresh
    sleep 60

    # Create unique S3 bucket name for each user
    # Amazon S3 bucket names are universal
    s3_bucket_name=`echo $(mktemp)| tr '[:upper:]' '[:lower:]' | cut -d '.' -f 2`
    
    aws s3api create-bucket --bucket openebs-k8s-`echo $s3_bucket_name`-local-state-store

    if [ -e ~/.ssh/id_rsa.pub ];then
        echo "Using Public Key for Passwordless SSH."
    else
        echo "Generating Public Key for Passwordless SSH"
        ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
    fi

    echo "Generating terraform file(.tf)"

    kops create cluster --cloud=aws \
    --master-size=t2.micro \
    --master-zones=us-east-1a \
    --node-count=2 \
    --node-size=t2.micro \
    --zones=us-east-1a \
    --image=ami-2757f631 \
    --state=s3://openebs-k8s-`echo $s3_bucket_name`-local-state-store \
    --target=terraform \
    --out=. \
    --name=openebs.k8s.local

    show_terraform_commands
}

function ssh_aws_ec2() {

    master_dns_name=`aws ec2 describe-instances --region us-east-1 --query 'Reservations[].Instances[].[SecurityGroups[].GroupName,PublicDnsName]' | grep -A 2 masters | grep ec2 | tr -d '"'`
    if [ -z "$master_dns_name" ]; then
        echo " The EC2 instance is not available yet."
        exit 1
    fi    
    ssh -i ~/.ssh/id_rsa ubuntu@`echo $master_dns_name`
}

if (($# == 0)); then
    show_help
    exit 2
{'fraction_non_alphanumeric': 0.1168958742632613, 'fraction_numerical': 0.018773193625845886, 'mean_word_length': 2.333212077118952, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7120445', 'n_tokens_mistral': 3263, 'n_tokens_neox': 3064, 'n_words': 787}