Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add driver aws #44

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
77eabb8
store all scripts related to AWS in the AWS directory
hiroTochigi Jan 13, 2024
070b215
send argument
hiroTochigi Jan 18, 2024
2368ff9
execute command
hiroTochigi Jan 18, 2024
087eb3b
Refactor delete.sh into a function and integrate into driver.sh
hiroTochigi Jan 18, 2024
cbefbfb
add source declaration for delete.sh in driver.sh
hiroTochigi Jan 18, 2024
49ce51e
add test command to driver.sh for storeConfigIntoTreehousesConfigAsSt…
hiroTochigi Jan 18, 2024
7825fb0
add call to test function callStoreConfigIntoTreehousesConfigAsString…
hiroTochigi Jan 18, 2024
5bf9396
debug
hiroTochigi Jan 18, 2024
218e649
Merge branch 'add-driver-aws' of github.com:treehouses/luftballon int…
hiroTochigi Jan 18, 2024
95c785a
debug delete.sh
hiroTochigi Jan 20, 2024
2c76cdb
Merge branch 'add-driver-aws' of github.com:treehouses/luftballon int…
hiroTochigi Jan 20, 2024
066d4b6
debug getValueByAttribute
hiroTochigi Jan 20, 2024
a300594
Merge branch 'add-driver-aws' of github.com:treehouses/luftballon int…
hiroTochigi Jan 20, 2024
79f0053
debug getValueByAttribute
hiroTochigi Jan 20, 2024
e65da93
Merge branch 'add-driver-aws' of github.com:treehouses/luftballon int…
hiroTochigi Jan 20, 2024
b0621da
debug getValueByAttribute
hiroTochigi Jan 20, 2024
b0c2503
debug getValueByAttribute
hiroTochigi Jan 20, 2024
22e1c1e
debuf
hiroTochigi Jan 20, 2024
0d02df8
debug
hiroTochigi Jan 20, 2024
92611b4
debug
hiroTochigi Jan 20, 2024
00e68ab
debug
hiroTochigi Jan 20, 2024
694f9e4
debug
hiroTochigi Jan 20, 2024
1a437f0
debug
hiroTochigi Jan 20, 2024
5ace3a7
debug
hiroTochigi Jan 20, 2024
f8d0da8
debug
hiroTochigi Jan 20, 2024
fa61305
debug
hiroTochigi Jan 20, 2024
6bbd2db
debug
hiroTochigi Jan 20, 2024
5791757
remove getTreehousesConfigValue
hiroTochigi Jan 25, 2024
e2a0e27
replace init with initJqObject
hiroTochigi Jan 25, 2024
f7d6c26
use getTreehousesConfigValue
hiroTochigi Jan 25, 2024
c554e3d
try to use delete.sh
hiroTochigi Jan 25, 2024
72427b0
remove test script and set executable permission for driver.sh
hiroTochigi Jan 27, 2024
afcf859
Add README.md with detailed usage instructions for driver.sh
hiroTochigi Jan 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
310 changes: 155 additions & 155 deletions LICENSE

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions archive/jsonController.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function deleteKeyValue(){
echo "$output"
}

function init(){
function initJqObject(){
local name="$1"
local output=$( echo null \
| jq --arg name $name \
Expand Down Expand Up @@ -131,7 +131,7 @@ function getBucketByBucketKey(){
local buckets="$1"
local key="$2"
local theBucket=$(echo "$buckets" | jq --arg key $key 'getpath([$key])')
local emptyBucket=$(init "$key")
local emptyBucket=$(initJqObject "$key")
local theBucketWithKey=$(makeBucket "$emptyBucket" "$key" "$theBucket" )
echo "$theBucketWithKey"
}
Expand Down Expand Up @@ -163,7 +163,10 @@ function printAllConfig(){
function getValueByAttribute(){
local instanceName=$1
local attribute=$2
echo "instanceName: $instanceName"
echo "attribute: $attribute"
local backet=$(getBucketByBucketKey "$(getConfigAsJson)" $instanceName)
echo "backet: $backet"
local keyName=$(echo "$backet" | \
jq -r --arg instanceName "$instanceName" \
--arg attribute "$attribute" \
Expand Down
69 changes: 0 additions & 69 deletions delete.sh

This file was deleted.

45 changes: 0 additions & 45 deletions restart.sh

This file was deleted.

37 changes: 37 additions & 0 deletions src/aws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# AWS EC2 Management Script

This script is designed to simplify the management of AWS EC2 instances. It provides easy-to-use commands for initializing and deleting EC2 instances.

## Usage

This script supports two main commands: init and delete.

### Command: init

The init command verifies the AWS CLI installation, checks for the existence of an SSH key, and defines functions for importing an SSH key and adding ports in AWS EC2.

```bash
./driver.sh init [additional options]
```

Options for init:

- -n [ssh key name]: Specify a name for the SSH key on AWS.
- -a [balloon name]: Change the SSH key name, instance name, and group name, based on the provided balloon name.
- -p: Use stored port numbers instead of the default port number.

### Command: delete

The delete command deletes an AWS EC2 instance and its related resources, identified by a given "balloon name". It also handles cleanup tasks such as removing SSH tunnels and deleting security keys.

```bash
./driver.sh delete [balloon name]
```

### Help

To view the usage instructions, use the following command:

```bash
./driver.sh
```
4 changes: 0 additions & 4 deletions addPort.sh → src/aws/addPort.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@


manageConfigPath=$(pwd)
source $manageConfigPath/dependencies/manageConfig.sh
source $manageConfigPath/dependencies/config.sh

BASE=/home/pi
groupName=luftballons-sg

Expand Down
59 changes: 59 additions & 0 deletions src/aws/delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

#BASE=$HOME
BASE=/home/pi

function delete(){

balloonName=$1

if ! isBalloonNameValid "$balloonName"; then
echo "Please provide a valid balloon name"
exit 1
fi

instanceId=$(getValueByAttribute $balloonName instanceId)

if [ "$instanceId" = "null" ]; then
echo "$balloonName is already deleted"
exit 1
fi

keyName=$(getValueByAttribute $balloonName key)
groupName=$(getValueByAttribute $balloonName groupName)


storePortArrayString $groupName tcp $balloonName
storePortArrayString $groupName udp $balloonName
updateSshtunnelConfig $balloonName

echo $instanceId
aws ec2 terminate-instances --instance-ids $instanceId
echo "ec2 instance delete"

echo $keyName
aws ec2 delete-key-pair --key-name $keyName
echo "security key delete"

treehouses sshtunnel remove all
echo "remove all sshtunnel"

sleep 30
echo $groupName
while true; do
output=$(aws ec2 delete-security-group --group-name "$groupName" 2>&1)
if [[ $? -eq 0 ]]; then
echo "Security group '$groupName' successfully deleted."
break
elif [[ $output == *"DependencyViolation"* ]]; then
echo "Dependency violation. Retrying in 5 seconds..."
sleep 10
else
echo "An error occurred: $output"
break
fi
done

deleteObsoleteKeyValue $balloonName

}
4 changes: 0 additions & 4 deletions deletePort.sh → src/aws/deletePort.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@

manageConfigPath=$(pwd)
source $manageConfigPath/dependencies/manageConfig.sh
source $manageConfigPath/dependencies/config.sh

luftballonHostPort=$1
localHostPort=$2

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function storeConfig(){
local publicIp=$4
local groupName=$5

local value=$(init $instanceName)
local value=$(initJqObject $instanceName)
value=$(addKeyValue "$value" $instanceName instanceName $instanceName )
value=$(addKeyValue "$value" $instanceName key $keyName )
value=$(addKeyValue "$value" $instanceName instanceId $instanceId )
Expand All @@ -22,7 +22,7 @@ function makeConfig(){
local publicIp=$4
local groupName=$5

local value=$(init $instanceName)
local value=$(initJqObject $instanceName)
value=$(addKeyValue "$value" $instanceName instanceName $instanceName )
value=$(addKeyValue "$value" $instanceName key $keyName )
value=$(addKeyValue "$value" $instanceName instanceId $instanceId )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
function getConfigAsJson(){
local allConfig=$(getTreehousesConfigValue $configName | jq .)
if [ -z "$configName" ]; then
echo "configName is not set"
return 1
fi
local allConfig=$(getTreehousesConfigValue $configName)
if ! echo "$allConfig" | jq . > /dev/null 2>&1; then
echo "getTreehousesConfigValue did not return valid JSON"
return 1
fi
echo "$allConfig"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function deleteKeyValue(){
echo "$output"
}

function init(){
function initJqObject(){
local name="$1"
local output=$( echo null \
| jq --arg name $name \
Expand Down Expand Up @@ -141,7 +141,7 @@ function getBucketByBucketKey(){
local buckets="$1"
local key="$2"
local theBucket=$(echo "$buckets" | jq --arg key $key 'getpath([$key])')
local emptyBucket=$(init "$key")
local emptyBucket=$(initJqObject "$key")
local theBucketWithKey=$(makeBucket "$emptyBucket" "$key" "$theBucket" )
echo "$theBucketWithKey"
}
Expand Down
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions src/aws/driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
source load.sh

awsUsage() {
echo "Usage: $0 credential [command]"
echo "Commands:"
echo " init - Verify AWS CLI installation, SSH key existence, and defines functions for SSH key import and port addition in AWS EC2"
echo " delete - deletes an AWS EC2 instance and its related resources, identified by a given "balloon name", and handles associated cleanup tasks such as removing SSH tunnels and deleting security keys"
exit 1
}

# Check if at least one argument is provided
if [ $# -eq 0 ]; then
awsUsage
fi

# Execute the appropriate command
case "$1" in
init)
init "${@:2}"
;;
delete)
delete "${@:2}"
;;
*)
echo "Error: Invalid command."
authUsage
;;
esac
13 changes: 1 addition & 12 deletions src/aws/init.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
#!/bin/bash
manageConfigPath=$(pwd)
source $manageConfigPath/dependencies/config.sh
source $manageConfigPath/dependencies/utilitiyFunction.sh
source $manageConfigPath/dependencies/isBalloonNameValid.sh
source $manageConfigPath/dependencies/jsonOperations.sh
source $manageConfigPath/dependencies/configOperations.sh
source $manageConfigPath/dependencies/configFunctions.sh
source $manageConfigPath/dependencies/getLatestIpAddress.sh
source $manageConfigPath/dependencies/securitygroupFunction.sh
source $manageConfigPath/dependencies/manageConfig.sh
source $manageConfigPath/dependencies/sshtunnelFunction.sh
source $manageConfigPath/dependencies/reverseShell.sh

portConfigArray=
udpPortConfigArray=
Expand Down Expand Up @@ -201,6 +189,7 @@ function init {

openSSHTunnel $publicIp $portConfigArray
storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName
callStoreConfigIntoTreehousesConfigAsStringfiedJson
}


File renamed without changes.
Loading
Loading