From 8f146812136131e98ad405e04d622ccb09848c24 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 24 Jul 2024 22:45:35 -0500 Subject: [PATCH 01/11] feat: Add checkKeyName function to prevent the script from asking to duplicate key pairs to the AWS --- src/aws/up.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/aws/up.sh b/src/aws/up.sh index 10f46b42..ad165874 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -10,7 +10,17 @@ groupName=luftballons-sg instanceName=luftballon checkSSH=~/.ssh/$publickey - +checkKeyName() { + key_pairs=($(aws ec2 describe-key-pairs --query "KeyPairs[*].KeyName" --output text)) + + for key in "${key_pairs[@]}" + do + if [ "$key" == "$keyName" ]; then + echo "Error: Key Pair '$key' matches the specified keyName '$keyName'. Exiting..." + exit 1 + fi + done +} function importSshKey() { @@ -149,6 +159,7 @@ function up { keyname=luftballon fi + checkKeyName keyName=$(importSshKey | getValueByKeyword KeyName ) From a9d16372ce22d5ebfe9390a202a01a6a60ba45ee Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Thu, 25 Jul 2024 04:59:33 +0100 Subject: [PATCH 02/11] fix variable name --- src/aws/up.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/up.sh b/src/aws/up.sh index ad165874..12f80cad 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -15,7 +15,7 @@ checkKeyName() { for key in "${key_pairs[@]}" do - if [ "$key" == "$keyName" ]; then + if [ "$key" == "$keyname" ]; then echo "Error: Key Pair '$key' matches the specified keyName '$keyName'. Exiting..." exit 1 fi From 83b4730d8db84b73213bd740ef0344c0b46858a7 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 24 Jul 2024 23:01:52 -0500 Subject: [PATCH 03/11] camel case --- src/aws/up.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aws/up.sh b/src/aws/up.sh index 12f80cad..49c4790d 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -11,9 +11,9 @@ instanceName=luftballon checkSSH=~/.ssh/$publickey checkKeyName() { - key_pairs=($(aws ec2 describe-key-pairs --query "KeyPairs[*].KeyName" --output text)) + keyPairs=($(aws ec2 describe-key-pairs --query "KeyPairs[*].KeyName" --output text)) - for key in "${key_pairs[@]}" + for key in "${keyPairs[@]}" do if [ "$key" == "$keyname" ]; then echo "Error: Key Pair '$key' matches the specified keyName '$keyName'. Exiting..." From fdf58db0dd3a5fbb2b7c6c4441012dc8bb7ddbed Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 24 Jul 2024 23:05:22 -0500 Subject: [PATCH 04/11] variable name --- src/aws/up.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/aws/up.sh b/src/aws/up.sh index 49c4790d..244126a9 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -16,7 +16,7 @@ checkKeyName() { for key in "${keyPairs[@]}" do if [ "$key" == "$keyname" ]; then - echo "Error: Key Pair '$key' matches the specified keyName '$keyName'. Exiting..." + echo "Error: Key Pair '$key' matches the specified key name '$keyname'. Exiting..." exit 1 fi done @@ -161,14 +161,14 @@ function up { checkKeyName - keyName=$(importSshKey | getValueByKeyword KeyName ) + importedKeyName=$(importSshKey | getValueByKeyword KeyName ) - if [ -z $keyName ] + if [ -z $importedKeyName ] then exit 1 fi - echo "Success to add ssh key: $keyName" + echo "Success to add ssh key: $importedKeyName" createSecurityGroups echo "Add security group" @@ -191,5 +191,5 @@ function up { openSSHTunnel $instanceName $publicIp $portConfigArray - storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName + storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $importedKeyName $instanceId $publicIp $groupName } From 7b31854776bf2596464dda5f88f9d539262c60e6 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 31 Jul 2024 22:18:25 -0500 Subject: [PATCH 05/11] Enhance main.sh to check existing AWS resources before creation - Added checks for existing SSH key on AWS and create if not present - Implemented verification for Security Group existence and creation if missing - Included logic to verify EC2 instance existence and state - Create and run instance if it does not exist - Log state if the instance is running - Start the instance if it is stopped --- src/aws/up.sh | 107 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 42 deletions(-) diff --git a/src/aws/up.sh b/src/aws/up.sh index 244126a9..8cd3ebd5 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -10,16 +10,23 @@ groupName=luftballons-sg instanceName=luftballon checkSSH=~/.ssh/$publickey -checkKeyName() { - keyPairs=($(aws ec2 describe-key-pairs --query "KeyPairs[*].KeyName" --output text)) - - for key in "${keyPairs[@]}" - do - if [ "$key" == "$keyname" ]; then - echo "Error: Key Pair '$key' matches the specified key name '$keyname'. Exiting..." - exit 1 - fi - done +checkSshKey() { + aws ec2 describe-key-pairs --key-names $keyname &> /dev/null + return $? +} + +checkSecurityGroup() { + aws ec2 describe-security-groups --group-names $groupName &> /dev/null + return $? +} + +checkInstance() { + aws ec2 describe-instances --filters "Name=tag:Name,Values=$instanceName" --query "Reservations[*].Instances[*].InstanceId" --output text +} + +checkInstanceState() { + ID=$1 + aws ec2 describe-instances --instance-ids $ID --query "Reservations[*].Instances[*].State.Name" --output text } function importSshKey() @@ -158,38 +165,54 @@ function up { then keyname=luftballon fi + - checkKeyName - - importedKeyName=$(importSshKey | getValueByKeyword KeyName ) - - if [ -z $importedKeyName ] - then - exit 1 + if ! checkSshKey ; then + importedKeyName=$(importSshKey | getValueByKeyword KeyName ) + if [ -z $importedKeyName ] + then + exit 1 + fi + echo "Success to add ssh key: $importedKeyName" + else + echo "The key pair $keyname already exists. Please use another key name." + + if ! checkSecurityGroup; then + createSecurityGroups + echo "Add security group" + # Add rules to Security Group as needed + else + echo "Security Group already exists." fi - echo "Success to add ssh key: $importedKeyName" - - createSecurityGroups - echo "Add security group" - - instanceId=$(createEc2 | getValueByKeyword InstanceId ) - echo "Create EC2 Instance" - echo "Instance id is $instanceId" - - - aws ec2 create-tags --resources $instanceId --tags Key=Name,Value=$instanceName - aws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses - - - publicIp=$(waitForOutput "getLatestIpAddress $instanceId") - echo "Public IP Address is $publicIp" - - echo "Will open ssh tunnel soon" - isOpen=$(waitForOutput "ssh-keyscan -H $publicIp | grep ecdsa-sha2-nistp256") - echo "Opened ssh tunnel" - - openSSHTunnel $instanceName $publicIp $portConfigArray - - storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $importedKeyName $instanceId $publicIp $groupName -} + instanceId=$(checkInstance) + if [ -z "$instanceId" ]; then + instanceId=$(createEc2 | getValueByKeyword InstanceId ) + echo "Creating and running EC2 instance..." + + echo "Instance id is $instanceId" + aws ec2 create-tags --resources $instanceId --tags Key=Name,Value=$instanceName + aws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses + + publicIp=$(waitForOutput "getLatestIpAddress $instanceId") + echo "Public IP Address is $publicIp" + + echo "Will open ssh tunnel soon" + isOpen=$(waitForOutput "ssh-keyscan -H $publicIp | grep ecdsa-sha2-nistp256") + echo "Opened ssh tunnel" + + openSSHTunnel $instanceName $publicIp $portConfigArray + + storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $importedKeyName $instanceId $publicIp $groupNameaws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses + else + instanceState=$(check_instance_state $instanceId) + if [ "$instanceState" = "running" ]; then + echo "EC2 instance is already running." + elif [ "$instanceState" = "stopped" ]; then + echo "Starting stopped EC2 instance..." + start $instanceName + else + echo "EC2 instance is in state: $instanceState." + fi + fi +} \ No newline at end of file From 18bcd11879eb77ebf64c0cb456848b6a6fd39b89 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 31 Jul 2024 22:23:24 -0500 Subject: [PATCH 06/11] fix syntax error in up function by adding missing closing fi --- src/aws/up.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aws/up.sh b/src/aws/up.sh index 8cd3ebd5..001fa511 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -176,6 +176,7 @@ function up { echo "Success to add ssh key: $importedKeyName" else echo "The key pair $keyname already exists. Please use another key name." + fi if ! checkSecurityGroup; then createSecurityGroups From 4fc81d6af0db7aa404a4951bd51926711c35f14a Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 31 Jul 2024 22:27:13 -0500 Subject: [PATCH 07/11] fix the function name --- src/aws/up.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/up.sh b/src/aws/up.sh index 001fa511..21994cc1 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -206,7 +206,7 @@ function up { storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $importedKeyName $instanceId $publicIp $groupNameaws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses else - instanceState=$(check_instance_state $instanceId) + instanceState=$(checkInstanceState $instanceId) if [ "$instanceState" = "running" ]; then echo "EC2 instance is already running." elif [ "$instanceState" = "stopped" ]; then From 8ca0b8a54278503d5502bfc5dc1ffcf783646b48 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 31 Jul 2024 22:41:48 -0500 Subject: [PATCH 08/11] Enhance up function to handle terminated EC2 instances - Added check for terminated EC2 instance state - Execute instance creation steps when instance state is terminated - Ensure consistent behavior for creating and running EC2 instances when necessary --- src/aws/up.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/aws/up.sh b/src/aws/up.sh index 21994cc1..c22bfb39 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -188,7 +188,13 @@ function up { instanceId=$(checkInstance) if [ -z "$instanceId" ]; then - instanceId=$(createEc2 | getValueByKeyword InstanceId ) + instanceState="" + else + instanceState=$(checkInstanceState $instanceId) + fi + + if [ -z "$instanceId" ] || [ "$instanceState" = "terminated" ]; then + instanceId=$(createEc2 | getValueByKeyword InstanceId) echo "Creating and running EC2 instance..." echo "Instance id is $instanceId" @@ -206,7 +212,6 @@ function up { storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $importedKeyName $instanceId $publicIp $groupNameaws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses else - instanceState=$(checkInstanceState $instanceId) if [ "$instanceState" = "running" ]; then echo "EC2 instance is already running." elif [ "$instanceState" = "stopped" ]; then From c48491df2d3076a1ebb7736a0e20de44a1fb16f1 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 31 Jul 2024 23:01:37 -0500 Subject: [PATCH 09/11] feat: ignore the terminated states currently --- src/aws/up.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/up.sh b/src/aws/up.sh index c22bfb39..7aaafe5e 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -193,7 +193,7 @@ function up { instanceState=$(checkInstanceState $instanceId) fi - if [ -z "$instanceId" ] || [ "$instanceState" = "terminated" ]; then + if [ -z "$instanceId" ]; then instanceId=$(createEc2 | getValueByKeyword InstanceId) echo "Creating and running EC2 instance..." From 306d7f0a15780aad107f7180ac8de03e49691f4c Mon Sep 17 00:00:00 2001 From: dogi Date: Thu, 1 Aug 2024 00:38:36 -0400 Subject: [PATCH 10/11] Update up.sh --- src/aws/up.sh | 290 +++++++++++++++++++++++--------------------------- 1 file changed, 132 insertions(+), 158 deletions(-) diff --git a/src/aws/up.sh b/src/aws/up.sh index 7aaafe5e..9449b2c3 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -31,89 +31,77 @@ checkInstanceState() { function importSshKey() { - if [[ -f ~/.ssh/$publickey ]] - then - aws ec2 import-key-pair --key-name "$keyname" --public-key-material fileb://~/.ssh/$publickey - else - echo 'ssh key pair (~/.ssh/$publickey) do not exist ~/.ssh/$publickey' - echo 'Please generate the ssh key by the commad "ssh-keygen -t rsa"' - exit 1 - fi + if [[ -f ~/.ssh/$publickey ]]; then + aws ec2 import-key-pair --key-name "$keyname" --public-key-material fileb://~/.ssh/$publickey + else + echo 'ssh key pair (~/.ssh/$publickey) do not exist ~/.ssh/$publickey' + echo 'Please generate the ssh key by the commad "ssh-keygen -t rsa"' + exit 1 + fi } function addPort(){ - aws ec2 authorize-security-group-ingress \ - --group-name $groupName \ - --protocol tcp \ - --port $1 \ - --cidr 0.0.0.0/0 + aws ec2 authorize-security-group-ingress \ + --group-name $groupName \ + --protocol tcp \ + --port $1 \ + --cidr 0.0.0.0/0 } function addUDPPort() { - aws ec2 authorize-security-group-ingress \ - --group-name $groupName \ - --protocol udp \ - --port $1 \ - --cidr 0.0.0.0/0 + aws ec2 authorize-security-group-ingress \ + --group-name $groupName \ + --protocol udp \ + --port $1 \ + --cidr 0.0.0.0/0 } - function createSecurityGroups(){ - aws ec2 create-security-group \ - --group-name $groupName \ - --description "luftballons security group" - - if [ -z "$portConfigArray" ] - then - portConfigArray="8080:80,8443:443,2022:22" - fi - - portArray=($(makePortArray "$portConfigArray")) - - for i in "${portArray[@]}" - do - addPort $i - echo $i - done - - if [ -z "$udpPortConfigArray" ] - then - udpPortConfigArray="1194" - fi - - portArray=($udpPortConfigArray) - - for i in "${portArray[@]}" - do - addUDPPort $i - echo $i - done + aws ec2 create-security-group \ + --group-name $groupName \ + --description "luftballons security group" + if [ -z "$portConfigArray" ]; then + portConfigArray="8080:80,8443:443,2022:22" + fi + portArray=($(makePortArray "$portConfigArray")) + for i in "${portArray[@]}"; do + addPort $i + echo $i + done + if [ -z "$udpPortConfigArray" ]; then + udpPortConfigArray="1194" + fi + portArray=($udpPortConfigArray) + for i in "${portArray[@]}"; do + addUDPPort $i + echo $i + done } function createEc2(){ - image="ami-0750fb43a63427eff" - #image="ami-01e5ff16fd6e8c542" - aws ec2 run-instances \ - --count 1 \ - --image-id $image \ - --instance-type t2.micro \ - --key-name $keyname \ - --security-groups $groupName + image="ami-0750fb43a63427eff" + #image="ami-01e5ff16fd6e8c542" + aws ec2 run-instances \ + --count 1 \ + --image-id $image \ + --instance-type t2.micro \ + --key-name $keyname \ + --security-groups $groupName } function findData(){ - keyWord=$1 - grep $keyWord | awk -F':' '{ print $2 }' | sed 's/ //g; s/"//g; s/,//g' + keyWord=$1 + grep $keyWord | awk -F':' '{ print $2 }' | sed 's/ //g; s/"//g; s/,//g' } function deleteKeyword(){ - keyWord=$1 - sed "s/$keyWord//g; s/ //g" + keyWord=$1 + sed "s/$keyWord//g; s/ //g" } function getValueByKeyword(){ - keyWord=$1 - findData $keyWord | deleteKeyword $keyWord + keyWord=$1 + findData $keyWord | deleteKeyword $keyWord } function usage { @@ -126,99 +114,85 @@ function usage { } function up { - while getopts 'n:pN:a:' OPTION; do - case "$OPTION" in - n) - keyname=$OPTARG - ;; - p) - portConfigArray=$(getArrayValueAsStringByKey $instanceName tcpPortArray) - udpPortConfigArray=$(getArrayValueAsStringByKey $instanceName udpPortArray) - if [ -z "$portConfigArray" ] - then - echo "There is no stored port numbers. The default port numbers are used" - fi - if [ -z "$udpPortConfigArray" ] - then - echo "There is no stored udp port numbers. The default port numbers are used" - fi - ;; - a) - groupName=$OPTARG-sg - instanceName=$OPTARG - keyname=$OPTARG - ;; - ?) - usage - ;; - esac - done - shift "$(($OPTIND -1))" - - aws --version || ( echo "Run './installAwsCli.sh' first. AWS CLI is not installed." && exit 1 ) - - if test ! -f "$checkSSH"; then - echo "Run 'ssh-keygen' first, with an empty passphrase for no passphrase. Missing ssh key." && exit 1 - fi - - if [ -z $keyname ] - then - keyname=luftballon - fi - - - if ! checkSshKey ; then - importedKeyName=$(importSshKey | getValueByKeyword KeyName ) - if [ -z $importedKeyName ] - then - exit 1 - fi - echo "Success to add ssh key: $importedKeyName" - else - echo "The key pair $keyname already exists. Please use another key name." - fi - - if ! checkSecurityGroup; then - createSecurityGroups - echo "Add security group" - # Add rules to Security Group as needed - else - echo "Security Group already exists." - fi - - instanceId=$(checkInstance) - if [ -z "$instanceId" ]; then - instanceState="" - else - instanceState=$(checkInstanceState $instanceId) - fi - - if [ -z "$instanceId" ]; then - instanceId=$(createEc2 | getValueByKeyword InstanceId) - echo "Creating and running EC2 instance..." - - echo "Instance id is $instanceId" - aws ec2 create-tags --resources $instanceId --tags Key=Name,Value=$instanceName - aws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses - - publicIp=$(waitForOutput "getLatestIpAddress $instanceId") - echo "Public IP Address is $publicIp" - - echo "Will open ssh tunnel soon" - isOpen=$(waitForOutput "ssh-keyscan -H $publicIp | grep ecdsa-sha2-nistp256") - echo "Opened ssh tunnel" - - openSSHTunnel $instanceName $publicIp $portConfigArray - - storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $importedKeyName $instanceId $publicIp $groupNameaws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses - else - if [ "$instanceState" = "running" ]; then - echo "EC2 instance is already running." - elif [ "$instanceState" = "stopped" ]; then - echo "Starting stopped EC2 instance..." - start $instanceName - else - echo "EC2 instance is in state: $instanceState." - fi - fi -} \ No newline at end of file + while getopts 'n:pN:a:' OPTION; do + case "$OPTION" in + n) + keyname=$OPTARG + ;; + p) + portConfigArray=$(getArrayValueAsStringByKey $instanceName tcpPortArray) + udpPortConfigArray=$(getArrayValueAsStringByKey $instanceName udpPortArray) + if [ -z "$portConfigArray" ]; then + echo "There is no stored port numbers. The default port numbers are used" + fi + if [ -z "$udpPortConfigArray" ]; then + echo "There is no stored udp port numbers. The default port numbers are used" + fi + ;; + a) + groupName=$OPTARG-sg + instanceName=$OPTARG + keyname=$OPTARG + ;; + ?) + usage + ;; + esac + done + shift "$(($OPTIND -1))" + + aws --version || ( echo "Run './installAwsCli.sh' first. AWS CLI is not installed." && exit 1 ) + + if test ! -f "$checkSSH"; then + echo "Run 'ssh-keygen' first, with an empty passphrase for no passphrase. Missing ssh key." && exit 1 + fi + + if [ -z $keyname ]; then + keyname=luftballon + fi + + if ! checkSshKey ; then + importedKeyName=$(importSshKey | getValueByKeyword KeyName ) + if [ -z $importedKeyName ]; then + exit 1 + fi + echo "Success to add ssh key: $importedKeyName" + else + echo "The key pair $keyname already exists. Please use another key name." + fi + + if ! checkSecurityGroup; then + createSecurityGroups + echo "Add security group" + # Add rules to Security Group as needed + else + echo "Security Group already exists." + fi + + instanceId=$(checkInstance) + if [ -z "$instanceId" ]; then + instanceState="" + instanceId=$(createEc2 | getValueByKeyword InstanceId) + echo "Creating and running EC2 instance..." + echo "Instance id is $instanceId" + aws ec2 create-tags --resources $instanceId --tags Key=Name,Value=$instanceName + aws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses + publicIp=$(waitForOutput "getLatestIpAddress $instanceId") + echo "Public IP Address is $publicIp" + echo "Will open ssh tunnel soon" + isOpen=$(waitForOutput "ssh-keyscan -H $publicIp | grep ecdsa-sha2-nistp256") + echo "Opened ssh tunnel" + openSSHTunnel $instanceName $publicIp $portConfigArray + storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $importedKeyName $instanceId $publicIp $groupNameaws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses + else + instanceState=$(checkInstanceState $instanceId) + if [ "$instanceState" = "running" ]; then + echo "EC2 instance is already running." + elif [ "$instanceState" = "stopped" ]; then + echo "Starting stopped EC2 instance..." + start $instanceName + else + echo "EC2 instance is in state: $instanceState." + fi + fi +} From 9f5adff365784ff25dd4b960521df72ca4209ef0 Mon Sep 17 00:00:00 2001 From: dogi Date: Fri, 2 Aug 2024 22:28:04 -0400 Subject: [PATCH 11/11] Update up.sh --- src/aws/up.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/aws/up.sh b/src/aws/up.sh index 9449b2c3..f50a2681 100644 --- a/src/aws/up.sh +++ b/src/aws/up.sh @@ -42,24 +42,24 @@ function importSshKey() function addPort(){ aws ec2 authorize-security-group-ingress \ - --group-name $groupName \ - --protocol tcp \ - --port $1 \ - --cidr 0.0.0.0/0 + --group-name $groupName \ + --protocol tcp \ + --port $1 \ + --cidr 0.0.0.0/0 } function addUDPPort() { aws ec2 authorize-security-group-ingress \ - --group-name $groupName \ - --protocol udp \ - --port $1 \ - --cidr 0.0.0.0/0 + --group-name $groupName \ + --protocol udp \ + --port $1 \ + --cidr 0.0.0.0/0 } function createSecurityGroups(){ aws ec2 create-security-group \ - --group-name $groupName \ - --description "luftballons security group" + --group-name $groupName \ + --description "luftballons security group" if [ -z "$portConfigArray" ]; then portConfigArray="8080:80,8443:443,2022:22" fi @@ -82,11 +82,11 @@ function createEc2(){ image="ami-0750fb43a63427eff" #image="ami-01e5ff16fd6e8c542" aws ec2 run-instances \ - --count 1 \ - --image-id $image \ - --instance-type t2.micro \ - --key-name $keyname \ - --security-groups $groupName + --count 1 \ + --image-id $image \ + --instance-type t2.micro \ + --key-name $keyname \ + --security-groups $groupName } function findData(){ @@ -105,12 +105,12 @@ function getValueByKeyword(){ } function usage { - echo "script usage: $(basename \$0 aws up) [-n ssh key name] [-p] [-a change key name, instance name, and group name]" >&2 - echo 'Start Luftballon.' - echo ' -n Change SSH key name on AWS' - echo ' -a Change SSH key name, instance name, and group name' - echo ' -p Use stored port Numbers instead of the default port number.' - exit 1 + echo "script usage: $(basename \$0 aws up) [-n ssh key name] [-p] [-a change key name, instance name, and group name]" >&2 + echo 'Start Luftballon.' + echo ' -n Change SSH key name on AWS' + echo ' -a Change SSH key name, instance name, and group name' + echo ' -p Use stored port Numbers instead of the default port number.' + exit 1 } function up {