<commit_before>#!/bin/bash

# Enable for logging
# set -x

master_dns_name=
s3_bucket_name=
amazon_machine_image=
ami_vm_os="ubuntu"
run_cluster_func=false
run_ssh_func=false
openebs_pod_status=
public_ip_addr=

function show_help() {
    cat << EOF
Usage : $(basename "$0") --setup-local-env
        $(basename "$0") --create-cluster-config [--ami-vm-os=[ubuntu|coreos]]
        $(basename "$0") --list-aws-instances
        $(basename "$0") --ssh-aws-ec2[ ipaddress|=ipaddress]
        $(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
--ami-vm-os                     The OS to be used for the Amazon Machine Image.
                                Defaults to Ubuntu.
--list-aws-instances            Outputs the list of AWS instances in the cluster.
--ssh-aws-ec2                   SSH to Amazon EC2 instance with Public IP Address.
EOF
}

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

function add_network_rules() {

    cat <<'EOF' >>kubernetes.tf
resource "aws_security_group_rule" "allow_all_node_inbound" {
  type            = "ingress"
  from_port       = 0
  to_port         = 65535
  protocol        = "tcp"
  cidr_blocks     = ["0.0.0.0/0"]

  security_group_id = "${aws_security_group.nodes-openebs-k8s-local.id}"
}

resource "aws_security_group_rule" "allow_all_node_outbound" {
  type            = "egress"
  from_port       = 0
  to_port         = 65535
  protocol        = "tcp"
  cidr_blocks     = ["0.0.0.0/0"]

  security_group_id = "${aws_security_group.nodes-openebs-k8s-local.id}"
}
EOF
}

function start_iscsi_services() {

    cat <<'EOF' >>data/aws_launch_configuration_nodes.openebs.k8s.local_user_data
sudo modprobe iscsi_tcp
sudo systemctl start iscsid-initiatorname
sudo systemctl start iscsid
EOF
}

function setup_local_env() {

    echo "Installing Prerequisites..."

    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() {

    get_current_user=$(aws iam get-user | grep UserName | awk '{print $2}' | tr -d '", ')
    
    echo -ne "Creating Group on AWS for OpenEBS Admins..."
    
    aws iam create-group --group-name openebsadmins &<commit_msg>Fix for Issue #877 - Update code to download the latest version of terraform<commit_after>#!/bin/bash

# Enable for logging
# set -x

master_dns_name=
s3_bucket_name=
amazon_machine_image=
ami_vm_os="ubuntu"
run_cluster_func=false
run_ssh_func=false
openebs_pod_status=
public_ip_addr=
terraform_url=

function show_help() {
    cat << EOF
Usage : $(basename "$0") --setup-local-env
        $(basename "$0") --create-cluster-config [--ami-vm-os=[ubuntu|coreos]]
        $(basename "$0") --list-aws-instances
        $(basename "$0") --ssh-aws-ec2[ ipaddress|=ipaddress]
        $(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
--ami-vm-os                     The OS to be used for the Amazon Machine Image.
                                Defaults to Ubuntu.
--list-aws-instances            Outputs the list of AWS instances in the cluster.
--ssh-aws-ec2                   SSH to Amazon EC2 instance with Public IP Address.
EOF
}

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

function add_network_rules() {

    cat <<'EOF' >>kubernetes.tf
resource "aws_security_group_rule" "allow_all_node_inbound" {
  type            = "ingress"
  from_port       = 0
  to_port         = 65535
  protocol        = "tcp"
  cidr_blocks     = ["0.0.0.0/0"]

  security_group_id = "${aws_security_group.nodes-openebs-k8s-local.id}"
}

resource "aws_security_group_rule" "allow_all_node_outbound" {
  type            = "egress"
  from_port       = 0
  to_port         = 65535
  protocol        = "tcp"
  cidr_blocks     = ["0.0.0.0/0"]

  security_group_id = "${aws_security_group.nodes-openebs-k8s-local.id}"
}
EOF
}

function start_iscsi_services() {

    cat <<'EOF' >>data/aws_launch_configuration_nodes.openebs.k8s.local_user_data
sudo modprobe iscsi_tcp
sudo systemctl start iscsid-initiatorname
sudo systemctl start iscsid
EOF
}

function setup_local_env() {

    echo "Installing Prerequisites..."

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

    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..."
        terraform_url=$(curl https://releases.hashicorp.com/index.json | jq '{terraform}' | egrep "linux.*amd64" | sort --version-sort -r | egrep -v 'beta|rc' | head -1 | awk -F[\"] '{print $4}')
        curl -o terraform.zip $terraform_url
        unzip terraform.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() {

    get_current_user=$(aws iam get-user | grep UserName | awk '{print $2}' | tr -d '", ')
    
    echo -ne "Creating Group on AWS for OpenEBS Admins..."
    
    aws iam create-group --group-name openebsadmins &
{'fraction_non_alphanumeric': 0.11041421664706651, 'fraction_numerical': 0.01764014112112897, 'mean_word_length': 2.469628286491387, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7431499', 'n_tokens_mistral': 2713, 'n_tokens_neox': 2557, 'n_words': 666}