#!/bin/bash echo "Install OS tools" sudo yum -y -q -e 0 install jq > /dev/null echo "Update OS tools - this may take a few minutes ....." sudo yum update -y > /dev/null echo "Update pip" sudo pip install --upgrade pip 2&> /dev/null # echo "Uninstall AWS CLI v1" sudo /usr/local/bin/pip uninstall awscli -y 2&> /dev/null sudo pip uninstall awscli -y 2&> /dev/null echo "Install AWS CLI v2" curl --silent "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" > /dev/null unzip -qq awscliv2.zip sudo ./aws/install > /dev/null echo "alias aws='/usr/local/bin/aws'" >> ~/.bash_profile source ~/.bash_profile rm -f awscliv2.zip rm -rf aws # setup for AWS cli export ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account) export AWS_REGION=$(curl -s 169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.region') export AZS=($(aws ec2 describe-availability-zones --query 'AvailabilityZones[].ZoneName' --output text --region $AWS_REGION)) export TF_VAR_region=${AWS_REGION} test -n "$AWS_REGION" && echo AWS_REGION is "$AWS_REGION" || echo "AWS_REGION is not set !!" echo "export ACCOUNT_ID=${ACCOUNT_ID}" | tee -a ~/.bash_profile echo "export AWS_REGION=${AWS_REGION}" | tee -a ~/.bash_profile echo "export AZS=(${AZS[@]})" | tee -a ~/.bash_profile echo "export TF_VAR_region=${AWS_REGION}" | tee -a ~/.bash_profile aws configure set default.region ${AWS_REGION} echo "pip3" curl --silent "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" python3 get-pip.py 2&> /dev/null # ------ resize OS disk ----------- # Specify the desired volume size in GiB as a command-line argument. If not specified, default to 32 GiB. VOLUME_SIZE=${1:-32} # Get the ID of the environment host Amazon EC2 instance. INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data//instance-id) # Get the ID of the Amazon EBS volume associated with the instance. VOLUME_ID=$(aws ec2 describe-instances \ --instance-id $INSTANCE_ID \ --query "Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId" \ --output text) # Resize the EBS volume. aws ec2 modify-volume --volume-id $VOLUME_ID --size $VOLUME_SIZE > /dev/null # Wait for the resize to finish. while [ \ "$(aws ec2 describe-volumes-modifications \ --volume-id $VOLUME_ID \ --filters Name=modification-state,Values="optimizing","completed" \ --query "length(VolumesModifications)"\ --output text)" != "1" ]; do sleep 1 done if [ $(readlink -f /dev/xvda) = "/dev/xvda" ] then # Rewrite the partition table so that the partition takes up all the space that it can. sudo growpart /dev/xvda 1 # Expand the size of the file system. sudo resize2fs /dev/xvda1 > /dev/null else # Rewrite the partition table so that the partition takes up all the space that it can. sudo growpart /dev/nvme0n1 1 # Expand the size of the file system. sudo resize2fs /dev/nvme0n1p1 &> /dev/null #(Amazon Linux 1) sudo xfs_growfs /dev/nvme0n1p1 &> /dev/null #(Amazon Linux 2) fi df -m / # # echo "Setup kubectl" if [ ! `which kubectl 2> /dev/null` ]; then echo "Install kubectl v1.24.10" curl --silent -LO https://storage.googleapis.com/kubernetes-release/release/v1.24.10/bin/linux/amd64/kubectl > /dev/null chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl > /dev/null kubectl completion bash >> ~/.bash_completion fi if [ ! `which eksctl 2> /dev/null` ]; then echo "install eksctl" curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp > /dev/null sudo mv -v /tmp/eksctl /usr/local/bin > /dev/null echo "eksctl completion" eksctl completion bash >> ~/.bash_completion fi this=`pwd` #echo "sample apps" cd ~/environment echo "alias aws='/usr/local/bin/aws'" >> ~/.bash_profile source ~/.bash_profile # test -n "$AWS_REGION" && echo "PASSED: AWS_REGION is $AWS_REGION" || echo AWS_REGION is not set !! test -n "$TF_VAR_region" && echo "PASSED: TF_VAR_region is $TF_VAR_region" || echo TF_VAR_region is not set !! test -n "$ACCOUNT_ID" && echo "PASSED: ACCOUNT_ID is $ACCOUNT_ID" || echo ACCOUNT_ID is not set !! echo "setup tools run" >> ~/setup-tools.log cd $this profile_name="lf-admin" instance_id=$(curl -sS http://169.254.169.254/latest/meta-data/instance-id) ipa=$(aws ec2 describe-instances --instance-ids $instance_id --query Reservations[].Instances[].IamInstanceProfile | jq -r .[].Arn) iip=$(aws ec2 describe-iam-instance-profile-associations --filters "Name=instance-id,Values=$instance_id" --query IamInstanceProfileAssociations[].AssociationId | jq -r .[]) if aws ec2 replace-iam-instance-profile-association --iam-instance-profile "Name=$profile_name" --association-id $iip; then aws cloud9 update-environment --environment-id $C9_PID --managed-credentials-action DISABLE rm -vf ${HOME}/.aws/credentials echo "Profile $profile_name associated successfully." else echo "ERROR: Encountered error associating instance profile lf-admin with Cloud9 environment" fi # #echo "For final checks - run ./check.sh" #