Skip to content

Commit

Permalink
new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sagespidy committed May 30, 2017
1 parent 97b4261 commit 61d0995
Showing 1 changed file with 47 additions and 13 deletions.
60 changes: 47 additions & 13 deletions ec2instance.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -xe
clear
aws configure
echo
Expand All @@ -16,45 +17,78 @@ echo "The security group has been created. "
echo
echo

echo "group id is $g_id"

echo "security group id is $g_id"

# Command to add open ports in Above created security group

#enable ssh
aws ec2 authorize-security-group-ingress --group-name $g_name --protocol tcp --port 22 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-name $g_name --protocol tcp --port 22 --cidr 111.93.125.26/32
aws ec2 authorize-security-group-ingress --group-name $g_name --protocol tcp --port 22 --cidr 182.74.105.34/32
#enable HTTP

aws ec2 authorize-security-group-ingress --group-name $g_name --protocol tcp --port 80 --cidr 0.0.0.0/0
#enable HTTPS
aws ec2 authorize-security-group-ingress --group-name $g_name --protocol tcp --port 443 --cidr 0.0.0.0/0
echo -e "By Default, the following ports are enabled: \n 22 SSH\n 80 HTTP\n 443 HTTPS"


clear

###
### Create pem file
####
clear
###

echo " The key pair "
echo -e "\n\n\n"
echo "Do You want create new pem file Yes/no ?"
read x
function f1()
{
read y
if [[ $y =~ ^[Yy][eE][sS]$ ]]
then
echo "Please enter the name of pem file to be created:"
read kp
aws ec2 create-key-pair --key-name $kp --query 'KeyMaterial' --output text > $kp.pem
echo -e "\n\n\n"
echo "pem file Created SuccessFully.\n "
chmod 400 $kp.pem
mv $kp.pem ~/
elif [[ $y =~ ^[nN][oO] ]]
then
echo "enter name of pem file | Just name - don't include .pem extension"
read kp
echo $kp.pem

else
echo 'Please type either "yes" or "no"'
f1
fi
}

# shit goes here
read -p "Do you want to create a new pem file " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
if [[ $x =~ ^[Yy][eE][sS]$ ]]
then
echo "Please enter the name of key-pair to be created:"
read kp
aws ec2 create-key-pair --key-name $kp --query 'KeyMaterial' --output text > $kp.pem
echo -e "\n\n\n"
echo "\n\n\n"
echo "Key-pair Created SuccessFully.\n "
chmod 400 $kp.pem
mv $kp.pem ~/
elif [[ $x =~ ^[nN][oO] ]]
then
echo "enter name of pem file | Just name - don't include .pem extension"
read kp
echo $kp.pem

else
echo "enter name of pem file | Just name - don't include .pem extension"
read kp
echo $kp.pem
echo 'Please type either "yes" or "no"'
f1
fi




# finally Launch instance with ubuntu

echo -e " \n\n\n\ "
Expand Down

0 comments on commit 61d0995

Please sign in to comment.