From 77eabb8c71ec052694f8fbe3753ecbd8a23ccc89 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 12 Jan 2024 22:05:31 -0600 Subject: [PATCH 01/99] store all scripts related to AWS in the AWS directory --- restart.sh | 45 ------------------- addPort.sh => src/aws/addPort.sh | 4 -- delete.sh => src/aws/delete.sh | 15 ------- deletePort.sh => src/aws/deletePort.sh | 4 -- .../aws/dependencies}/config.sh | 0 .../aws/dependencies}/configFunctions.sh | 0 .../aws/dependencies}/configOperations.sh | 0 .../aws/dependencies}/getLatestIpAddress.sh | 0 .../aws/dependencies}/isBalloonNameValid.sh | 0 .../aws/dependencies}/jsonOperations.sh | 0 .../aws/dependencies}/manageConfig.sh | 0 .../aws/dependencies}/reverseShell.sh | 0 .../dependencies}/securitygroupFunction.sh | 0 .../aws/dependencies}/sshtunnelFunction.sh | 0 .../aws/dependencies}/utilitiyFunction.sh | 0 src/aws/driver.sh | 28 ++++++++++++ src/aws/init.sh | 12 ----- installAwsCli.sh => src/aws/installAwsCli.sh | 0 stop.sh => src/aws/load.sh | 26 +---------- src/aws/restart.sh | 29 ++++++++++++ src/aws/stop.sh | 24 ++++++++++ src/azure/create/init.sh | 7 +++ 22 files changed, 89 insertions(+), 105 deletions(-) delete mode 100644 restart.sh rename addPort.sh => src/aws/addPort.sh (90%) rename delete.sh => src/aws/delete.sh (65%) rename deletePort.sh => src/aws/deletePort.sh (93%) rename {dependencies => src/aws/dependencies}/config.sh (100%) rename {dependencies => src/aws/dependencies}/configFunctions.sh (100%) rename {dependencies => src/aws/dependencies}/configOperations.sh (100%) rename {dependencies => src/aws/dependencies}/getLatestIpAddress.sh (100%) rename {dependencies => src/aws/dependencies}/isBalloonNameValid.sh (100%) rename {dependencies => src/aws/dependencies}/jsonOperations.sh (100%) rename {dependencies => src/aws/dependencies}/manageConfig.sh (100%) rename {dependencies => src/aws/dependencies}/reverseShell.sh (100%) rename {dependencies => src/aws/dependencies}/securitygroupFunction.sh (100%) rename {dependencies => src/aws/dependencies}/sshtunnelFunction.sh (100%) rename {dependencies => src/aws/dependencies}/utilitiyFunction.sh (100%) create mode 100644 src/aws/driver.sh rename installAwsCli.sh => src/aws/installAwsCli.sh (100%) rename stop.sh => src/aws/load.sh (56%) create mode 100644 src/aws/restart.sh create mode 100644 src/aws/stop.sh create mode 100644 src/azure/create/init.sh diff --git a/restart.sh b/restart.sh deleted file mode 100644 index 40230a6b..00000000 --- a/restart.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/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 - - - -#BASE=$HOME -BASE=/home/pi - -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 - -aws ec2 start-instances --instance-ids $instanceId - -echo "get the new ip address. The procedure might take time for a while" -publicIp=$(waitForOutput "getLatestIpAddress $instanceId") - -echo "the new ip address is $publicIp" -updateIPAddress $balloonName $publicIp - -echo "open the new sshtunnel" -openSSHTunnel $publicIp \ No newline at end of file diff --git a/addPort.sh b/src/aws/addPort.sh similarity index 90% rename from addPort.sh rename to src/aws/addPort.sh index 16995f84..78af7697 100644 --- a/addPort.sh +++ b/src/aws/addPort.sh @@ -1,9 +1,5 @@ -manageConfigPath=$(pwd) -source $manageConfigPath/dependencies/manageConfig.sh -source $manageConfigPath/dependencies/config.sh - BASE=/home/pi groupName=luftballons-sg diff --git a/delete.sh b/src/aws/delete.sh similarity index 65% rename from delete.sh rename to src/aws/delete.sh index 9b6a935c..81732794 100755 --- a/delete.sh +++ b/src/aws/delete.sh @@ -1,20 +1,5 @@ #!/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 - - - #BASE=$HOME BASE=/home/pi diff --git a/deletePort.sh b/src/aws/deletePort.sh similarity index 93% rename from deletePort.sh rename to src/aws/deletePort.sh index 985051d2..a90c346c 100644 --- a/deletePort.sh +++ b/src/aws/deletePort.sh @@ -1,8 +1,4 @@ -manageConfigPath=$(pwd) -source $manageConfigPath/dependencies/manageConfig.sh -source $manageConfigPath/dependencies/config.sh - luftballonHostPort=$1 localHostPort=$2 diff --git a/dependencies/config.sh b/src/aws/dependencies/config.sh similarity index 100% rename from dependencies/config.sh rename to src/aws/dependencies/config.sh diff --git a/dependencies/configFunctions.sh b/src/aws/dependencies/configFunctions.sh similarity index 100% rename from dependencies/configFunctions.sh rename to src/aws/dependencies/configFunctions.sh diff --git a/dependencies/configOperations.sh b/src/aws/dependencies/configOperations.sh similarity index 100% rename from dependencies/configOperations.sh rename to src/aws/dependencies/configOperations.sh diff --git a/dependencies/getLatestIpAddress.sh b/src/aws/dependencies/getLatestIpAddress.sh similarity index 100% rename from dependencies/getLatestIpAddress.sh rename to src/aws/dependencies/getLatestIpAddress.sh diff --git a/dependencies/isBalloonNameValid.sh b/src/aws/dependencies/isBalloonNameValid.sh similarity index 100% rename from dependencies/isBalloonNameValid.sh rename to src/aws/dependencies/isBalloonNameValid.sh diff --git a/dependencies/jsonOperations.sh b/src/aws/dependencies/jsonOperations.sh similarity index 100% rename from dependencies/jsonOperations.sh rename to src/aws/dependencies/jsonOperations.sh diff --git a/dependencies/manageConfig.sh b/src/aws/dependencies/manageConfig.sh similarity index 100% rename from dependencies/manageConfig.sh rename to src/aws/dependencies/manageConfig.sh diff --git a/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh similarity index 100% rename from dependencies/reverseShell.sh rename to src/aws/dependencies/reverseShell.sh diff --git a/dependencies/securitygroupFunction.sh b/src/aws/dependencies/securitygroupFunction.sh similarity index 100% rename from dependencies/securitygroupFunction.sh rename to src/aws/dependencies/securitygroupFunction.sh diff --git a/dependencies/sshtunnelFunction.sh b/src/aws/dependencies/sshtunnelFunction.sh similarity index 100% rename from dependencies/sshtunnelFunction.sh rename to src/aws/dependencies/sshtunnelFunction.sh diff --git a/dependencies/utilitiyFunction.sh b/src/aws/dependencies/utilitiyFunction.sh similarity index 100% rename from dependencies/utilitiyFunction.sh rename to src/aws/dependencies/utilitiyFunction.sh diff --git a/src/aws/driver.sh b/src/aws/driver.sh new file mode 100644 index 00000000..3ab62fdf --- /dev/null +++ b/src/aws/driver.sh @@ -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" + exit 1 +} + +function auth(){ + + # Check if at least one argument is provided + if [ $# -eq 0 ]; then + awsUsage + fi + + # Execute the appropriate command + case "$1" in + init) + init + ;; + *) + echo "Error: Invalid command." + authUsage + ;; + esac + +} \ No newline at end of file diff --git a/src/aws/init.sh b/src/aws/init.sh index 9747b9fc..3a7050d5 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -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= diff --git a/installAwsCli.sh b/src/aws/installAwsCli.sh similarity index 100% rename from installAwsCli.sh rename to src/aws/installAwsCli.sh diff --git a/stop.sh b/src/aws/load.sh similarity index 56% rename from stop.sh rename to src/aws/load.sh index 0539140d..5ee7c1ff 100644 --- a/stop.sh +++ b/src/aws/load.sh @@ -1,7 +1,5 @@ #!/bin/bash - manageConfigPath=$(pwd) - source $manageConfigPath/dependencies/config.sh source $manageConfigPath/dependencies/utilitiyFunction.sh source $manageConfigPath/dependencies/isBalloonNameValid.sh @@ -14,27 +12,5 @@ source $manageConfigPath/dependencies/manageConfig.sh source $manageConfigPath/dependencies/sshtunnelFunction.sh source $manageConfigPath/dependencies/reverseShell.sh +source $manageConfigPath/init.sh - -#BASE=$HOME -BASE=/home/pi - -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 - -publicIp=$(waitForOutput "getLatestIpAddress $instanceId") -treehouses sshtunnel remove host root@$publicIp -echo "Delete sshtunnel of root@$publicIp" - -aws ec2 stop-instances --instance-ids $instanceId \ No newline at end of file diff --git a/src/aws/restart.sh b/src/aws/restart.sh new file mode 100644 index 00000000..e7f86f3e --- /dev/null +++ b/src/aws/restart.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +#BASE=$HOME +BASE=/home/pi + +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 + +aws ec2 start-instances --instance-ids $instanceId + +echo "get the new ip address. The procedure might take time for a while" +publicIp=$(waitForOutput "getLatestIpAddress $instanceId") + +echo "the new ip address is $publicIp" +updateIPAddress $balloonName $publicIp + +echo "open the new sshtunnel" +openSSHTunnel $publicIp \ No newline at end of file diff --git a/src/aws/stop.sh b/src/aws/stop.sh new file mode 100644 index 00000000..8a2fdd20 --- /dev/null +++ b/src/aws/stop.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +#BASE=$HOME +BASE=/home/pi + +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 + +publicIp=$(waitForOutput "getLatestIpAddress $instanceId") +treehouses sshtunnel remove host root@$publicIp +echo "Delete sshtunnel of root@$publicIp" + +aws ec2 stop-instances --instance-ids $instanceId \ No newline at end of file diff --git a/src/azure/create/init.sh b/src/azure/create/init.sh new file mode 100644 index 00000000..35d4a909 --- /dev/null +++ b/src/azure/create/init.sh @@ -0,0 +1,7 @@ +function initAzure(){ + az group create --name luftballon --location eastus + az vm create --resource-group luftballon --name luftballon --image Ubuntu2204 --admin-username hiroyuki --generate-ssh-keys --public-ip-sku Standard + echo $(az vm show --show-details --resource-group luftballon --name luftballon --query publicIps --output tsv) + az vm run-command invoke --resource-group luftballon --name luftballon --command-id RunShellScript --scripts "sudo apt-get update && sudo apt-get install -y nginx" + az vm open-port --port 80 --resource-group luftballon --name luftballon +} From 070b2151eed6fce0c4856a154b863e92d65e2693 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 17 Jan 2024 20:48:28 -0600 Subject: [PATCH 02/99] send argument --- src/aws/driver.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index 3ab62fdf..b374e5e5 100644 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -17,7 +17,7 @@ function auth(){ # Execute the appropriate command case "$1" in init) - init + init "${@:2}" ;; *) echo "Error: Invalid command." From 2368ff90c17222b27552edb2ac951167d2f6822b Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 17 Jan 2024 20:52:08 -0600 Subject: [PATCH 03/99] execute command --- src/aws/driver.sh | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index b374e5e5..2b5c632d 100644 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -7,22 +7,18 @@ awsUsage() { exit 1 } -function auth(){ +# Check if at least one argument is provided +if [ $# -eq 0 ]; then + awsUsage +fi - # Check if at least one argument is provided - if [ $# -eq 0 ]; then - awsUsage - fi - - # Execute the appropriate command - case "$1" in - init) - init "${@:2}" - ;; - *) - echo "Error: Invalid command." - authUsage - ;; - esac - -} \ No newline at end of file +# Execute the appropriate command +case "$1" in + init) + init "${@:2}" + ;; + *) + echo "Error: Invalid command." + authUsage + ;; +esac From 087eb3b686f29644f4348220a405ac44086f6e76 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 17 Jan 2024 21:17:04 -0600 Subject: [PATCH 04/99] Refactor delete.sh into a function and integrate into driver.sh Converted the standalone delete.sh script into a reusable function. This function is now imported into driver.sh for better modularity and code organization. The delete function handles the deletion of an AWS EC2 instance and its related resources, including SSH tunnels and security keys. --- src/aws/delete.sh | 98 ++++++++++++++++++++++++----------------------- src/aws/driver.sh | 4 ++ 2 files changed, 55 insertions(+), 47 deletions(-) diff --git a/src/aws/delete.sh b/src/aws/delete.sh index 81732794..40ac022e 100755 --- a/src/aws/delete.sh +++ b/src/aws/delete.sh @@ -3,52 +3,56 @@ #BASE=$HOME BASE=/home/pi -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 +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 -done -deleteObsoleteKeyValue $balloonName + 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 + +} \ No newline at end of file diff --git a/src/aws/driver.sh b/src/aws/driver.sh index 2b5c632d..b8b38fec 100644 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -4,6 +4,7 @@ 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 } @@ -17,6 +18,9 @@ case "$1" in init) init "${@:2}" ;; + delete) + delete "${@:2}" + ;; *) echo "Error: Invalid command." authUsage From cbefbfb9aa2da4ae74aa188db2119f2ce557fa73 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 17 Jan 2024 21:19:51 -0600 Subject: [PATCH 05/99] add source declaration for delete.sh in driver.sh Included a source declaration for delete.sh in driver.sh, enabling the use of the delete function within the driver script. --- src/aws/load.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aws/load.sh b/src/aws/load.sh index 5ee7c1ff..ba4e2115 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -13,4 +13,5 @@ source $manageConfigPath/dependencies/sshtunnelFunction.sh source $manageConfigPath/dependencies/reverseShell.sh source $manageConfigPath/init.sh +source $manageConfigPath/delete.sh From 49ce51e987e96d04ed05b2dec2bb731b5e4a108c Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 17 Jan 2024 22:13:33 -0600 Subject: [PATCH 06/99] add test command to driver.sh for storeConfigIntoTreehousesConfigAsStringfiedJson function --- ...toreConfigIntoTreehousesConfigAsStringfiedJson.sh | 12 ++++++++++++ src/aws/driver.sh | 3 +++ src/aws/load.sh | 1 + 3 files changed, 16 insertions(+) create mode 100644 src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh diff --git a/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh b/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh new file mode 100644 index 00000000..7968335f --- /dev/null +++ b/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh @@ -0,0 +1,12 @@ + +source configFunctions.sh + +function callStoreConfigIntoTreehousesConfigAsStringfiedJson() { + local instanceName="testBallon" + local keyName="key-testBallon" + local instanceId="i-0abcd1234efgh5678" # replace with your actual AWS instance ID + local publicIp="192.0.2.0" # replace with your actual public IPv4 address + local groupName="testBallon" + + storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName +} \ No newline at end of file diff --git a/src/aws/driver.sh b/src/aws/driver.sh index b8b38fec..8ef81419 100644 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -21,6 +21,9 @@ case "$1" in delete) delete "${@:2}" ;; + test) + callStoreConfigIntoTreehousesConfigAsStringfiedJson "${@:2}" + ;; *) echo "Error: Invalid command." authUsage diff --git a/src/aws/load.sh b/src/aws/load.sh index ba4e2115..cd798fa9 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -14,4 +14,5 @@ source $manageConfigPath/dependencies/reverseShell.sh source $manageConfigPath/init.sh source $manageConfigPath/delete.sh +source $manageConfigPath/callStoreConfigIntoTreehousesConfigAsStringfiedJson From 7825fb0370077c7db6fd31291f9b8f2002a282d0 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 17 Jan 2024 22:22:09 -0600 Subject: [PATCH 07/99] add call to test function callStoreConfigIntoTreehousesConfigAsStringfiedJson in init.sh --- src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh | 2 +- src/aws/init.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh b/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh index 7968335f..309ac756 100644 --- a/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh +++ b/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh @@ -5,7 +5,7 @@ function callStoreConfigIntoTreehousesConfigAsStringfiedJson() { local instanceName="testBallon" local keyName="key-testBallon" local instanceId="i-0abcd1234efgh5678" # replace with your actual AWS instance ID - local publicIp="192.0.2.0" # replace with your actual public IPv4 address + local publicIp="192.1.2.1" # replace with your actual public IPv4 address local groupName="testBallon" storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName diff --git a/src/aws/init.sh b/src/aws/init.sh index 3a7050d5..d0e2f8b0 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -189,6 +189,7 @@ function init { openSSHTunnel $publicIp $portConfigArray storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName + callStoreConfigIntoTreehousesConfigAsStringfiedJson } From 5bf93963e4ec6a96e2b06dd33ee323c9df85914e Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Thu, 18 Jan 2024 04:22:52 +0000 Subject: [PATCH 08/99] debug --- .../callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh | 5 +---- src/aws/delete.sh | 2 +- src/aws/load.sh | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh b/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh index 7968335f..e4e07458 100644 --- a/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh +++ b/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh @@ -1,6 +1,3 @@ - -source configFunctions.sh - function callStoreConfigIntoTreehousesConfigAsStringfiedJson() { local instanceName="testBallon" local keyName="key-testBallon" @@ -9,4 +6,4 @@ function callStoreConfigIntoTreehousesConfigAsStringfiedJson() { local groupName="testBallon" storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName -} \ No newline at end of file +} diff --git a/src/aws/delete.sh b/src/aws/delete.sh index 40ac022e..3700e009 100755 --- a/src/aws/delete.sh +++ b/src/aws/delete.sh @@ -55,4 +55,4 @@ function delete(){ deleteObsoleteKeyValue $balloonName -} \ No newline at end of file +} diff --git a/src/aws/load.sh b/src/aws/load.sh index cd798fa9..e7a825b5 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -14,5 +14,5 @@ source $manageConfigPath/dependencies/reverseShell.sh source $manageConfigPath/init.sh source $manageConfigPath/delete.sh -source $manageConfigPath/callStoreConfigIntoTreehousesConfigAsStringfiedJson +source $manageConfigPath/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh From 95c785aadf6fc192d5f404fe1ca5ffc7a0714faf Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:13:11 -0600 Subject: [PATCH 09/99] debug delete.sh --- src/aws/delete.sh | 69 +++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/src/aws/delete.sh b/src/aws/delete.sh index 40ac022e..39a51e57 100755 --- a/src/aws/delete.sh +++ b/src/aws/delete.sh @@ -22,37 +22,42 @@ function delete(){ 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 + echo "ballonName: $balloonName" + echo "instanceId: $instanceId" + echo "keyName: $keyName" + echo "groupName: $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 } \ No newline at end of file From 066d4b6091d75fed38b2c81712eb1371be67b829 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:24:41 -0600 Subject: [PATCH 10/99] debug getValueByAttribute --- archive/jsonController.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/archive/jsonController.sh b/archive/jsonController.sh index b051303a..2dda0155 100644 --- a/archive/jsonController.sh +++ b/archive/jsonController.sh @@ -164,6 +164,7 @@ function getValueByAttribute(){ local instanceName=$1 local attribute=$2 local backet=$(getBucketByBucketKey "$(getConfigAsJson)" $instanceName) + echo "backet: $backet" local keyName=$(echo "$backet" | \ jq -r --arg instanceName "$instanceName" \ --arg attribute "$attribute" \ From 79f00539986ae3e10d69f22226a26af1c015e148 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:26:45 -0600 Subject: [PATCH 11/99] debug getValueByAttribute --- archive/jsonController.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archive/jsonController.sh b/archive/jsonController.sh index 2dda0155..9c9ce423 100644 --- a/archive/jsonController.sh +++ b/archive/jsonController.sh @@ -163,6 +163,8 @@ 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" | \ From b0621daff1cd10d9a416623217de18515ad5b14e Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:30:07 -0600 Subject: [PATCH 12/99] debug getValueByAttribute --- src/aws/dependencies/configOperations.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/aws/dependencies/configOperations.sh b/src/aws/dependencies/configOperations.sh index c7ea3bc8..b7080a1b 100644 --- a/src/aws/dependencies/configOperations.sh +++ b/src/aws/dependencies/configOperations.sh @@ -11,7 +11,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" \ From b0c2503bd638b60c6b8e7ce86346030ec1378a22 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:38:49 -0600 Subject: [PATCH 13/99] debug getValueByAttribute --- src/aws/delete.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/aws/delete.sh b/src/aws/delete.sh index 1e37ca66..a4fdb6ba 100755 --- a/src/aws/delete.sh +++ b/src/aws/delete.sh @@ -22,10 +22,10 @@ function delete(){ keyName=$(getValueByAttribute $balloonName key) groupName=$(getValueByAttribute $balloonName groupName) - echo "ballonName: $balloonName" - echo "instanceId: $instanceId" - echo "keyName: $keyName" - echo "groupName: $groupName" + #echo "ballonName: $balloonName" + #echo "instanceId: $instanceId" + #echo "keyName: $keyName" + #echo "groupName: $groupName" #storePortArrayString $groupName tcp $balloonName #storePortArrayString $groupName udp $balloonName From 22e1c1e4dcc2b228e137c44949d0fe849599cf76 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:41:16 -0600 Subject: [PATCH 14/99] debuf --- src/aws/delete.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/aws/delete.sh b/src/aws/delete.sh index a4fdb6ba..bd6b9d5c 100755 --- a/src/aws/delete.sh +++ b/src/aws/delete.sh @@ -19,11 +19,11 @@ function delete(){ exit 1 fi - keyName=$(getValueByAttribute $balloonName key) - groupName=$(getValueByAttribute $balloonName groupName) + #keyName=$(getValueByAttribute $balloonName key) + #groupName=$(getValueByAttribute $balloonName groupName) - #echo "ballonName: $balloonName" - #echo "instanceId: $instanceId" + echo "ballonName: $balloonName" + echo "instanceId: $instanceId" #echo "keyName: $keyName" #echo "groupName: $groupName" From 0d02df8e069ea03722bf827b3b2259aab2e16f17 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:43:21 -0600 Subject: [PATCH 15/99] debug --- src/aws/dependencies/configOperations.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aws/dependencies/configOperations.sh b/src/aws/dependencies/configOperations.sh index b7080a1b..5d7e055a 100644 --- a/src/aws/dependencies/configOperations.sh +++ b/src/aws/dependencies/configOperations.sh @@ -12,6 +12,7 @@ function getValueByAttribute(){ local instanceName=$1 local attribute=$2 echo "instanceName: $instanceName" + echo "instanceName: $instanceName" echo "attribute: $attribute" local backet=$(getBucketByBucketKey "$(getConfigAsJson)" $instanceName) echo "backet: $backet" From 92611b47520f7d25101dc137c87f743bf7d32758 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:45:12 -0600 Subject: [PATCH 16/99] debug --- src/aws/dependencies/configOperations.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aws/dependencies/configOperations.sh b/src/aws/dependencies/configOperations.sh index 5d7e055a..c160ceac 100644 --- a/src/aws/dependencies/configOperations.sh +++ b/src/aws/dependencies/configOperations.sh @@ -1,6 +1,7 @@ function getConfigAsJson(){ local allConfig=$(getTreehousesConfigValue $configName | jq .) echo "$allConfig" + echo "$allConfig" } function printAllConfig(){ From 00e68ab6fb5a029230d35e46258e1dbb55277202 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:46:58 -0600 Subject: [PATCH 17/99] debug --- src/aws/dependencies/configOperations.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aws/dependencies/configOperations.sh b/src/aws/dependencies/configOperations.sh index c160ceac..8b6a03e7 100644 --- a/src/aws/dependencies/configOperations.sh +++ b/src/aws/dependencies/configOperations.sh @@ -1,4 +1,5 @@ function getConfigAsJson(){ + echo "configName: $configName" local allConfig=$(getTreehousesConfigValue $configName | jq .) echo "$allConfig" echo "$allConfig" From 694f9e48dbd5043a37eef6b8d443d75771e0a89e Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:48:39 -0600 Subject: [PATCH 18/99] debug --- src/aws/dependencies/manageConfig.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aws/dependencies/manageConfig.sh b/src/aws/dependencies/manageConfig.sh index 8493dd85..1a41ad74 100644 --- a/src/aws/dependencies/manageConfig.sh +++ b/src/aws/dependencies/manageConfig.sh @@ -1,6 +1,7 @@ function getTreehousesConfigValue(){ keyWord=$1 + echo "keyord: $keyWord" treehouses config | grep $keyWord= | sed "s/${keyWord}=//" } From 1a437f0eefa1651341105015a2a4fdc454cca1d5 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:49:36 -0600 Subject: [PATCH 19/99] debug --- src/aws/dependencies/manageConfig.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/aws/dependencies/manageConfig.sh b/src/aws/dependencies/manageConfig.sh index 1a41ad74..7e5e4214 100644 --- a/src/aws/dependencies/manageConfig.sh +++ b/src/aws/dependencies/manageConfig.sh @@ -2,6 +2,9 @@ function getTreehousesConfigValue(){ keyWord=$1 echo "keyord: $keyWord" + echo "keyord: $keyWord" + echo "keyord: $keyWord" + echo "keyord: $keyWord" treehouses config | grep $keyWord= | sed "s/${keyWord}=//" } From 5ace3a7819edf098bad10bcfb6f7bad08154895f Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:51:12 -0600 Subject: [PATCH 20/99] debug --- src/aws/dependencies/manageConfig.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/aws/dependencies/manageConfig.sh b/src/aws/dependencies/manageConfig.sh index 7e5e4214..8493dd85 100644 --- a/src/aws/dependencies/manageConfig.sh +++ b/src/aws/dependencies/manageConfig.sh @@ -1,10 +1,6 @@ function getTreehousesConfigValue(){ keyWord=$1 - echo "keyord: $keyWord" - echo "keyord: $keyWord" - echo "keyord: $keyWord" - echo "keyord: $keyWord" treehouses config | grep $keyWord= | sed "s/${keyWord}=//" } From f8d0da86ba08008651a78fabc90a1a2cf12955e1 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 21:54:14 -0600 Subject: [PATCH 21/99] debug --- src/aws/delete.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aws/delete.sh b/src/aws/delete.sh index bd6b9d5c..646ebcda 100755 --- a/src/aws/delete.sh +++ b/src/aws/delete.sh @@ -24,6 +24,7 @@ function delete(){ echo "ballonName: $balloonName" echo "instanceId: $instanceId" + echo "configName: $configName" #echo "keyName: $keyName" #echo "groupName: $groupName" From fa613059fb610ad6e10d3f5a0a53700137b818bf Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 22:01:21 -0600 Subject: [PATCH 22/99] debug --- src/aws/dependencies/configOperations.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/aws/dependencies/configOperations.sh b/src/aws/dependencies/configOperations.sh index 8b6a03e7..c160ceac 100644 --- a/src/aws/dependencies/configOperations.sh +++ b/src/aws/dependencies/configOperations.sh @@ -1,5 +1,4 @@ function getConfigAsJson(){ - echo "configName: $configName" local allConfig=$(getTreehousesConfigValue $configName | jq .) echo "$allConfig" echo "$allConfig" From 6bbd2db5cba9885b9dda9f164bcf350a520dd50a Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 19 Jan 2024 22:06:30 -0600 Subject: [PATCH 23/99] debug --- src/aws/dependencies/configOperations.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/aws/dependencies/configOperations.sh b/src/aws/dependencies/configOperations.sh index c160ceac..ed49113e 100644 --- a/src/aws/dependencies/configOperations.sh +++ b/src/aws/dependencies/configOperations.sh @@ -1,6 +1,14 @@ function getConfigAsJson(){ - local allConfig=$(getTreehousesConfigValue $configName | jq .) - echo "$allConfig" + if [ -z "$configName" ]; then + echo "configName is not set" + return 1 + fi + echo "configName: $configName" + 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" } From 5791757b23f868777db62ba3b9eb333eb3f977d7 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 24 Jan 2024 21:15:43 -0600 Subject: [PATCH 24/99] remove getTreehousesConfigValue --- src/aws/dependencies/configOperations.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/aws/dependencies/configOperations.sh b/src/aws/dependencies/configOperations.sh index ed49113e..ed90be67 100644 --- a/src/aws/dependencies/configOperations.sh +++ b/src/aws/dependencies/configOperations.sh @@ -3,8 +3,8 @@ function getConfigAsJson(){ echo "configName is not set" return 1 fi - echo "configName: $configName" - local allConfig=$(getTreehousesConfigValue $configName) + local allConfig=$(treehouses config | grep $configName= | sed "s/${configName}=//") + #local allConfig=$(getTreehousesConfigValue $configName) if ! echo "$allConfig" | jq . > /dev/null 2>&1; then echo "getTreehousesConfigValue did not return valid JSON" return 1 @@ -20,11 +20,7 @@ function printAllConfig(){ function getValueByAttribute(){ local instanceName=$1 local attribute=$2 - echo "instanceName: $instanceName" - 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" \ From e2a0e2701d1af99f0efbf66660e4f040ff56464b Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 24 Jan 2024 21:34:02 -0600 Subject: [PATCH 25/99] replace init with initJqObject --- LICENSE | 310 ++++++++++++------------ archive/jsonController.sh | 4 +- src/aws/dependencies/configFunctions.sh | 4 +- src/aws/dependencies/jsonOperations.sh | 4 +- 4 files changed, 161 insertions(+), 161 deletions(-) diff --git a/LICENSE b/LICENSE index 0ad25db4..162676cb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,178 +1,178 @@ GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. +Copyright (C) 2007 Free Software Foundation, Inc. +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. Preamble - The GNU Affero General Public License is a free, copyleft license for +The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, +The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. - Developers that use our General Public Licenses protect your rights +Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. - A secondary benefit of defending all users' freedom is that +A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. - The GNU Affero General Public License is designed specifically to +The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to +to the community. It requires the operator of a network server to provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on +users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is +An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. - The precise terms and conditions for copying, distribution and +The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS - 0. Definitions. +0. Definitions. - "This License" refers to version 3 of the GNU Affero General Public License. +"This License" refers to version 3 of the GNU Affero General Public License. - "Copyright" also means copyright-like laws that apply to other kinds of +"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and +"The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. - To "modify" a work means to copy from or adapt all or part of the work +To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the +exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. - A "covered work" means either the unmodified Program or a work based +A "covered work" means either the unmodified Program or a work based on the Program. - To "propagate" a work means to do anything with it that, without +To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, +computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through +To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. - An interactive user interface displays "Appropriate Legal Notices" +An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If +work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. - 1. Source Code. +1. Source Code. - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source +The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source form of a work. - A "Standard Interface" means an interface that either is an official +A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. - The "System Libraries" of an executable work include anything, other +The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A +implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. - The "Corresponding Source" for a work in object code form means all +The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's +control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source +which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. - The Corresponding Source need not include anything that users +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. - The Corresponding Source for a work in source code form is that +The Corresponding Source for a work in source code form is that same work. - 2. Basic Permissions. +2. Basic Permissions. - All rights granted under this License are granted for the term of +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your +content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. - You may make, run and propagate covered works that you do not +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose +in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works +not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 +Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. +3. Protecting Users' Legal Rights From Anti-Circumvention Law. - No covered work shall be deemed part of an effective technological +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. - When you convey a covered work, you waive any legal power to forbid +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or @@ -180,9 +180,9 @@ modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. - 4. Conveying Verbatim Copies. +4. Conveying Verbatim Copies. - You may convey verbatim copies of the Program's source code as you +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any @@ -190,12 +190,12 @@ non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. - You may charge any price or no price for each copy that you convey, +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. - 5. Conveying Modified Source Versions. +5. Conveying Modified Source Versions. - You may convey a work based on the Program, or the modifications to +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: @@ -220,19 +220,19 @@ terms of section 4, provided that you also meet all of these conditions: interfaces that do not display Appropriate Legal Notices, your work need not make them do so. - A compilation of a covered work with other separate and independent +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work +beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. - 6. Conveying Non-Source Forms. +6. Conveying Non-Source Forms. - You may convey a covered work in object code form under the terms +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: @@ -278,75 +278,75 @@ in one of these ways: Source of the work are being offered to the general public at no charge under subsection 6d. - A separable portion of the object code, whose source code is excluded +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. - A "User Product" is either (1) a "consumer product", which means any +A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product +actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. - "Installation Information" for a User Product means any methods, +"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must +a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. - If you convey an object code work under this section in, or with, or +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply +by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). - The requirement to provide Installation Information does not include a +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a +the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. - Corresponding Source conveyed, and Installation Information provided, +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. - 7. Additional Terms. +7. Additional Terms. - "Additional permissions" are terms that supplement the terms of this +"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions +that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. - When you convey a copy of a covered work, you may at your option +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. - Notwithstanding any other provision of this License, for material you +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: @@ -373,74 +373,74 @@ that material) supplement the terms of this License with terms: any liability that these contractual assumptions directly impose on those licensors and authors. - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you +All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains +restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. - If you add terms to a covered work in accord with this section, you +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. - Additional terms, permissive or non-permissive, may be stated in the +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. - 8. Termination. +8. Termination. - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or +You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). - However, if you cease all violation of this License, then your +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. - Moreover, your license from a particular copyright holder is +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. - Termination of your rights under this section does not terminate the +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently +this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. - 9. Acceptance Not Required for Having Copies. +9. Acceptance Not Required for Having Copies. - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work +You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, +to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. - 10. Automatic Licensing of Downstream Recipients. +10. Automatic Licensing of Downstream Recipients. - Each time you convey a covered work, the recipient automatically +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible +propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. - An "entity transaction" is a transaction transferring control of an +An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered +organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could @@ -448,43 +448,43 @@ give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may +You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. - 11. Patents. +11. Patents. - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The +A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". - A contributor's "essential patent claims" are all patent claims +A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For +consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. - Each contributor grants you a non-exclusive, worldwide, royalty-free +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. - In the following three paragraphs, a "patent license" is any express +In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a +sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. - If you convey a covered work, knowingly relying on a patent license, +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, @@ -492,13 +492,13 @@ then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have +license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. - If, pursuant to or in connection with a single transaction or +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify @@ -506,10 +506,10 @@ or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. - A patent license is "discriminatory" if it does not include within +A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered +specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying @@ -521,83 +521,83 @@ for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. - Nothing in this License shall be construed as excluding or limiting +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. - 12. No Surrender of Others' Freedom. +12. No Surrender of Others' Freedom. - If conditions are imposed on you (whether by court order, agreement or +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a +excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you +not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. - 13. Remote Network Interaction; Use with the GNU General Public License. +13. Remote Network Interaction; Use with the GNU General Public License. - Notwithstanding any other provision of this License, if you modify the +Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source +means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. - Notwithstanding any other provision of this License, you have +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this +combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. - 14. Revised Versions of this License. +14. Revised Versions of this License. - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions +The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - Each version is given a distinguishing version number. If the +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the +Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. - If the Program specifies that a proxy can decide which future +If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any +Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. - 15. Disclaimer of Warranty. +15. Disclaimer of Warranty. - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - 16. Limitation of Liability. +16. Limitation of Liability. - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE @@ -607,9 +607,9 @@ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - 17. Interpretation of Sections 15 and 16. +17. Interpretation of Sections 15 and 16. - If the disclaimer of warranty and limitation of liability provided +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the @@ -620,11 +620,11 @@ copy of the Program in return for a fee. How to Apply These Terms to Your New Programs - If you develop a new program, and you want it to be of the greatest +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. - To do so, attach the following notices to the program. It is safest +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. @@ -647,15 +647,15 @@ the "copyright" line and a pointer to where the full notice is found. Also add information on how to contact you by electronic and paper mail. - If your software can interact with users remotely through a computer +If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its +get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different +of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. - You should also get your employer (if you work as a programmer) or school, +You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see . diff --git a/archive/jsonController.sh b/archive/jsonController.sh index 9c9ce423..2e5660da 100644 --- a/archive/jsonController.sh +++ b/archive/jsonController.sh @@ -96,7 +96,7 @@ function deleteKeyValue(){ echo "$output" } -function init(){ +function initJqObject(){ local name="$1" local output=$( echo null \ | jq --arg name $name \ @@ -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" } diff --git a/src/aws/dependencies/configFunctions.sh b/src/aws/dependencies/configFunctions.sh index 2fb31408..974630a7 100644 --- a/src/aws/dependencies/configFunctions.sh +++ b/src/aws/dependencies/configFunctions.sh @@ -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 ) @@ -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 ) diff --git a/src/aws/dependencies/jsonOperations.sh b/src/aws/dependencies/jsonOperations.sh index 5beaeb72..b9d658fd 100644 --- a/src/aws/dependencies/jsonOperations.sh +++ b/src/aws/dependencies/jsonOperations.sh @@ -92,7 +92,7 @@ function deleteKeyValue(){ echo "$output" } -function init(){ +function initJqObject(){ local name="$1" local output=$( echo null \ | jq --arg name $name \ @@ -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" } From f7d6c26a7eb845541c1e699a66c9403f40074910 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 24 Jan 2024 21:37:24 -0600 Subject: [PATCH 26/99] use getTreehousesConfigValue --- src/aws/dependencies/configOperations.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/aws/dependencies/configOperations.sh b/src/aws/dependencies/configOperations.sh index ed90be67..ea1ce0aa 100644 --- a/src/aws/dependencies/configOperations.sh +++ b/src/aws/dependencies/configOperations.sh @@ -3,8 +3,7 @@ function getConfigAsJson(){ echo "configName is not set" return 1 fi - local allConfig=$(treehouses config | grep $configName= | sed "s/${configName}=//") - #local allConfig=$(getTreehousesConfigValue $configName) + local allConfig=$(getTreehousesConfigValue $configName) if ! echo "$allConfig" | jq . > /dev/null 2>&1; then echo "getTreehousesConfigValue did not return valid JSON" return 1 From c554e3dace60923f867000e7cde9163992efa104 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 24 Jan 2024 22:29:14 -0600 Subject: [PATCH 27/99] try to use delete.sh --- src/aws/delete.sh | 77 ++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/src/aws/delete.sh b/src/aws/delete.sh index 646ebcda..1395b8ec 100755 --- a/src/aws/delete.sh +++ b/src/aws/delete.sh @@ -19,46 +19,41 @@ function delete(){ exit 1 fi - #keyName=$(getValueByAttribute $balloonName key) - #groupName=$(getValueByAttribute $balloonName groupName) - - echo "ballonName: $balloonName" - echo "instanceId: $instanceId" - echo "configName: $configName" - #echo "keyName: $keyName" - #echo "groupName: $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 + 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 } From 72427b049a5f303f709201b6d723dffaae1923cb Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 26 Jan 2024 21:32:24 -0600 Subject: [PATCH 28/99] remove test script and set executable permission for driver.sh - Deleted the test script section from driver.sh for cleaner. - Updated driver.sh to be executable, enhancing usability and ease of execution. --- ...allStoreConfigIntoTreehousesConfigAsStringfiedJson.sh | 9 --------- src/aws/driver.sh | 3 --- src/aws/load.sh | 1 - 3 files changed, 13 deletions(-) delete mode 100644 src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh mode change 100644 => 100755 src/aws/driver.sh diff --git a/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh b/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh deleted file mode 100644 index f222679b..00000000 --- a/src/aws/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh +++ /dev/null @@ -1,9 +0,0 @@ -function callStoreConfigIntoTreehousesConfigAsStringfiedJson() { - local instanceName="testBallon" - local keyName="key-testBallon" - local instanceId="i-0abcd1234efgh5678" # replace with your actual AWS instance ID - local publicIp="192.1.2.1" # replace with your actual public IPv4 address - local groupName="testBallon" - - storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName -} diff --git a/src/aws/driver.sh b/src/aws/driver.sh old mode 100644 new mode 100755 index 8ef81419..b8b38fec --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -21,9 +21,6 @@ case "$1" in delete) delete "${@:2}" ;; - test) - callStoreConfigIntoTreehousesConfigAsStringfiedJson "${@:2}" - ;; *) echo "Error: Invalid command." authUsage diff --git a/src/aws/load.sh b/src/aws/load.sh index e7a825b5..ba4e2115 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -14,5 +14,4 @@ source $manageConfigPath/dependencies/reverseShell.sh source $manageConfigPath/init.sh source $manageConfigPath/delete.sh -source $manageConfigPath/callStoreConfigIntoTreehousesConfigAsStringfiedJson.sh From afcf859cf70f884d2d29ba8fbbe6d52f8a251f9c Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 26 Jan 2024 21:33:53 -0600 Subject: [PATCH 29/99] Add README.md with detailed usage instructions for driver.sh - Created README.md to offer comprehensive guidance on using driver.sh. - Includes instructions for the 'init' and 'delete' commands, script setup, and options for the 'init' command. - Enhances user understanding and ease of use for the script. --- src/aws/README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/aws/README.md diff --git a/src/aws/README.md b/src/aws/README.md new file mode 100644 index 00000000..95e819ff --- /dev/null +++ b/src/aws/README.md @@ -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 +``` From 1c00fe2c1fcfeb9720ce26c674eb6b278f86102a Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 31 Jan 2024 21:40:06 -0600 Subject: [PATCH 30/99] add restart and stop command in the driver --- src/aws/README.md | 16 ++++++++++++++++ src/aws/driver.sh | 8 ++++++++ src/aws/load.sh | 2 ++ src/aws/restart.sh | 36 +++++++++++++++++++----------------- src/aws/stop.sh | 31 ++++++++++++++++--------------- 5 files changed, 61 insertions(+), 32 deletions(-) diff --git a/src/aws/README.md b/src/aws/README.md index 95e819ff..5719bfaa 100644 --- a/src/aws/README.md +++ b/src/aws/README.md @@ -28,6 +28,22 @@ The delete command deletes an AWS EC2 instance and its related resources, identi ./driver.sh delete [balloon name] ``` +### Command: stop + +The stop command stops a specified AWS EC2 instance and removes its associated SSH tunnel. + +```bash +./driver.sh stop [balloon name] +``` + +### Command: restart + +The restart command restarts a specified Amazon EC2 instance, updates its IP address, and opens a new SSH tunnel to it. + +```bash +./driver.sh restart [balloon name] +``` + ### Help To view the usage instructions, use the following command: diff --git a/src/aws/driver.sh b/src/aws/driver.sh index b8b38fec..b48745e4 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -5,6 +5,8 @@ awsUsage() { 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" + echo " stop - stops a specified AWS EC2 instance and removes its associated SSH tunnel" + echo " restart- restarts a specified Amazon EC2 instance, updates its IP address, and opens a new SSH tunnel to it" exit 1 } @@ -21,6 +23,12 @@ case "$1" in delete) delete "${@:2}" ;; + stop) + stop "${@:2}" + ;; + stop) + restart "${@:2}" + ;; *) echo "Error: Invalid command." authUsage diff --git a/src/aws/load.sh b/src/aws/load.sh index ba4e2115..9a2507bf 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -14,4 +14,6 @@ source $manageConfigPath/dependencies/reverseShell.sh source $manageConfigPath/init.sh source $manageConfigPath/delete.sh +source $manageConfigPath/stop.sh +source $manageConfigPath/restart.sh diff --git a/src/aws/restart.sh b/src/aws/restart.sh index e7f86f3e..af3bf7f4 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -3,27 +3,29 @@ #BASE=$HOME BASE=/home/pi -balloonName=$1 +function restart(){ + balloonName=$1 -if ! isBalloonNameValid "$balloonName"; then - echo "Please provide a valid balloon name" - exit 1 -fi + if ! isBalloonNameValid "$balloonName"; then + echo "Please provide a valid balloon name" + exit 1 + fi -instanceId=$(getValueByAttribute $balloonName instanceId) + instanceId=$(getValueByAttribute $balloonName instanceId) -if [ "$instanceId" = "null" ]; then - echo "$balloonName is already deleted" - exit 1 -fi + if [ "$instanceId" = "null" ]; then + echo "$balloonName is already deleted" + exit 1 + fi -aws ec2 start-instances --instance-ids $instanceId + aws ec2 start-instances --instance-ids $instanceId -echo "get the new ip address. The procedure might take time for a while" -publicIp=$(waitForOutput "getLatestIpAddress $instanceId") + echo "get the new ip address. The procedure might take time for a while" + publicIp=$(waitForOutput "getLatestIpAddress $instanceId") -echo "the new ip address is $publicIp" -updateIPAddress $balloonName $publicIp + echo "the new ip address is $publicIp" + updateIPAddress $balloonName $publicIp -echo "open the new sshtunnel" -openSSHTunnel $publicIp \ No newline at end of file + echo "open the new sshtunnel" + openSSHTunnel $publicIp +} \ No newline at end of file diff --git a/src/aws/stop.sh b/src/aws/stop.sh index 8a2fdd20..fe8b7aea 100644 --- a/src/aws/stop.sh +++ b/src/aws/stop.sh @@ -3,22 +3,23 @@ #BASE=$HOME BASE=/home/pi -balloonName=$1 +function stop(){ + balloonName=$1 + if ! isBalloonNameValid "$balloonName"; then + echo "Please provide a valid balloon name" + exit 1 + fi -if ! isBalloonNameValid "$balloonName"; then - echo "Please provide a valid balloon name" - exit 1 -fi + instanceId=$(getValueByAttribute $balloonName instanceId) -instanceId=$(getValueByAttribute $balloonName instanceId) + if [ "$instanceId" = "null" ]; then + echo "$balloonName is already deleted" + exit 1 + fi -if [ "$instanceId" = "null" ]; then - echo "$balloonName is already deleted" - exit 1 -fi + publicIp=$(waitForOutput "getLatestIpAddress $instanceId") + treehouses sshtunnel remove host root@$publicIp + echo "Delete sshtunnel of root@$publicIp" -publicIp=$(waitForOutput "getLatestIpAddress $instanceId") -treehouses sshtunnel remove host root@$publicIp -echo "Delete sshtunnel of root@$publicIp" - -aws ec2 stop-instances --instance-ids $instanceId \ No newline at end of file + aws ec2 stop-instances --instance-ids $instanceId +} \ No newline at end of file From c7bbb565af7464cad9c9556e6132c261b2572d33 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 31 Jan 2024 21:47:08 -0600 Subject: [PATCH 31/99] fix case command --- src/aws/driver.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index b48745e4..c222d279 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -26,7 +26,7 @@ case "$1" in stop) stop "${@:2}" ;; - stop) + restart) restart "${@:2}" ;; *) From 2ee421aedb1ff0583556fe03c2379b5a76423a69 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 2 Feb 2024 21:51:57 -0600 Subject: [PATCH 32/99] add SSH tunnel configuration to the config file when the VM is stopped --- src/aws/init.sh | 1 - src/aws/stop.sh | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/aws/init.sh b/src/aws/init.sh index d0e2f8b0..3a7050d5 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -189,7 +189,6 @@ function init { openSSHTunnel $publicIp $portConfigArray storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName - callStoreConfigIntoTreehousesConfigAsStringfiedJson } diff --git a/src/aws/stop.sh b/src/aws/stop.sh index fe8b7aea..8ca506c5 100644 --- a/src/aws/stop.sh +++ b/src/aws/stop.sh @@ -22,4 +22,6 @@ function stop(){ echo "Delete sshtunnel of root@$publicIp" aws ec2 stop-instances --instance-ids $instanceId + + updateSshtunnelConfig } \ No newline at end of file From 2fba03892914c2286097640335f297c1f553ade8 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 2 Feb 2024 21:54:02 -0600 Subject: [PATCH 33/99] fix bag --- src/aws/stop.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/stop.sh b/src/aws/stop.sh index 8ca506c5..a754ee70 100644 --- a/src/aws/stop.sh +++ b/src/aws/stop.sh @@ -23,5 +23,5 @@ function stop(){ aws ec2 stop-instances --instance-ids $instanceId - updateSshtunnelConfig + updateSshtunnelConfig $balloonName } \ No newline at end of file From b3fac6c1b07f5103880a5c88fa4ae59075998096 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 2 Feb 2024 22:09:02 -0600 Subject: [PATCH 34/99] move function before removing SSH tunnel --- src/aws/stop.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/stop.sh b/src/aws/stop.sh index a754ee70..2cac8868 100644 --- a/src/aws/stop.sh +++ b/src/aws/stop.sh @@ -17,11 +17,11 @@ function stop(){ exit 1 fi + updateSshtunnelConfig $balloonName publicIp=$(waitForOutput "getLatestIpAddress $instanceId") treehouses sshtunnel remove host root@$publicIp echo "Delete sshtunnel of root@$publicIp" aws ec2 stop-instances --instance-ids $instanceId - updateSshtunnelConfig $balloonName } \ No newline at end of file From 25dbd8dbe47bdac9bd666dcd4b9b13fedc543b6e Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 2 Feb 2024 23:33:32 -0600 Subject: [PATCH 35/99] Add port array into config file --- src/aws/stop.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/aws/stop.sh b/src/aws/stop.sh index 2cac8868..bf815133 100644 --- a/src/aws/stop.sh +++ b/src/aws/stop.sh @@ -17,7 +17,10 @@ function stop(){ exit 1 fi - updateSshtunnelConfig $balloonName + groupName=$(getValueByAttribute $balloonName groupName) + storePortArrayString $groupName tcp $balloonName + storePortArrayString $groupName udp $balloonName + publicIp=$(waitForOutput "getLatestIpAddress $instanceId") treehouses sshtunnel remove host root@$publicIp echo "Delete sshtunnel of root@$publicIp" From 852f911f3adffb8b7785601e4e22f7cb99a71eb3 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 2 Feb 2024 23:34:13 -0600 Subject: [PATCH 36/99] generate ssh tunnel config --- src/aws/restart.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/aws/restart.sh b/src/aws/restart.sh index af3bf7f4..7203b086 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -23,9 +23,11 @@ function restart(){ echo "get the new ip address. The procedure might take time for a while" publicIp=$(waitForOutput "getLatestIpAddress $instanceId") + portConfigArray=$(getArrayValueAsStringByKey $instanceName tcpPortArray) + echo "the new ip address is $publicIp" updateIPAddress $balloonName $publicIp echo "open the new sshtunnel" - openSSHTunnel $publicIp + openSSHTunnel $publicIp $portConfigArray } \ No newline at end of file From f2d7fdb55738105c9356e906299af838abe1cc01 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 7 Feb 2024 21:17:26 -0600 Subject: [PATCH 37/99] execute aws command from the root level --- main.sh | 27 +++++++++++++++++++++++++ src/aws/driver.sh | 51 +++++++++++++++++++++++++---------------------- src/aws/load.sh | 32 ++++++++++++++--------------- 3 files changed, 70 insertions(+), 40 deletions(-) create mode 100644 main.sh diff --git a/main.sh b/main.sh new file mode 100644 index 00000000..03ebb2d3 --- /dev/null +++ b/main.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +manageConfigPath=$(pwd) + +usage() { + echo "Usage: $0 credential [command]" + echo "Commands:" + echo " aws - Execute an AWS command" + exit 1 +} + +# Check if at least one argument is provided +if [ $# -eq 0 ]; then + usage +fi + +# Execute the appropriate command +case "$1" in + aws) + source $manageConfigPath/src/aws/load.sh + driver "${@:2}" + ;; + *) + echo "Error: Invalid command." + usage + ;; +esac diff --git a/src/aws/driver.sh b/src/aws/driver.sh index c222d279..00c95f7f 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -1,4 +1,3 @@ -source load.sh awsUsage() { echo "Usage: $0 credential [command]" @@ -10,27 +9,31 @@ awsUsage() { exit 1 } -# Check if at least one argument is provided -if [ $# -eq 0 ]; then - awsUsage -fi +function driver() { -# Execute the appropriate command -case "$1" in - init) - init "${@:2}" - ;; - delete) - delete "${@:2}" - ;; - stop) - stop "${@:2}" - ;; - restart) - restart "${@:2}" - ;; - *) - echo "Error: Invalid command." - authUsage - ;; -esac + # 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}" + ;; + stop) + stop "${@:2}" + ;; + restart) + restart "${@:2}" + ;; + *) + echo "Error: Invalid command." + authUsage + ;; + esac + +} \ No newline at end of file diff --git a/src/aws/load.sh b/src/aws/load.sh index 9a2507bf..5bf776fc 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -1,19 +1,19 @@ #!/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 +source $manageConfigPath/src/aws/dependencies/config.sh +source $manageConfigPath/src/aws/dependencies/utilitiyFunction.sh +source $manageConfigPath/src/aws/dependencies/isBalloonNameValid.sh +source $manageConfigPath/src/aws/dependencies/jsonOperations.sh +source $manageConfigPath/src/aws/dependencies/configOperations.sh +source $manageConfigPath/src/aws/dependencies/configFunctions.sh +source $manageConfigPath/src/aws/dependencies/getLatestIpAddress.sh +source $manageConfigPath/src/aws/dependencies/securitygroupFunction.sh +source $manageConfigPath/src/aws/dependencies/manageConfig.sh +source $manageConfigPath/src/aws/dependencies/sshtunnelFunction.sh +source $manageConfigPath/src/aws/dependencies/reverseShell.sh -source $manageConfigPath/init.sh -source $manageConfigPath/delete.sh -source $manageConfigPath/stop.sh -source $manageConfigPath/restart.sh +source $manageConfigPath/src/aws/init.sh +source $manageConfigPath/src/aws/delete.sh +source $manageConfigPath/src/aws/stop.sh +source $manageConfigPath/src/aws/restart.sh +source $manageConfigPath/src/aws/driver.sh From 8917ece9159666fec3545262dc0a7bc1c05e38d2 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 7 Feb 2024 21:44:17 -0600 Subject: [PATCH 38/99] Update usage messages in driver.sh and init.sh scripts --- src/aws/driver.sh | 4 ++-- src/aws/init.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index 00c95f7f..2e26074d 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -1,6 +1,6 @@ awsUsage() { - echo "Usage: $0 credential [command]" + echo "Usage: $0 $1 [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" @@ -32,7 +32,7 @@ function driver() { ;; *) echo "Error: Invalid command." - authUsage + awsUsage ;; esac diff --git a/src/aws/init.sh b/src/aws/init.sh index 3a7050d5..5f7d8b9e 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -114,7 +114,7 @@ function getValueByKeyword(){ } function usage { - echo "script usage: $(basename \$0) [-n ssh key name] [-p] [-a change key name, instance name, and group name]" >&2 + echo "script usage: $(basename \$0 $1 $2) [-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' From 929c593e671a9040e05a0975819cdfabb43a1ebc Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 7 Feb 2024 21:47:26 -0600 Subject: [PATCH 39/99] Fix variable interpolation in usage messages --- src/aws/driver.sh | 2 +- src/aws/init.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index 2e26074d..f7ff67c9 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -1,6 +1,6 @@ awsUsage() { - echo "Usage: $0 $1 [command]" + echo "Usage: $0 "$1" [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" diff --git a/src/aws/init.sh b/src/aws/init.sh index 5f7d8b9e..19527154 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -114,7 +114,7 @@ function getValueByKeyword(){ } function usage { - echo "script usage: $(basename \$0 $1 $2) [-n ssh key name] [-p] [-a change key name, instance name, and group name]" >&2 + echo "script usage: $(basename \$0 "$1 $2") [-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' From 2fee056d56cf3b20498b2fdcf457ea858b9f2d8d Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 7 Feb 2024 21:49:33 -0600 Subject: [PATCH 40/99] Fix usage message in AWS driver script --- src/aws/driver.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index f7ff67c9..439d521a 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -1,6 +1,6 @@ awsUsage() { - echo "Usage: $0 "$1" [command]" + echo "Usage: $0 $1 [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" @@ -32,7 +32,7 @@ function driver() { ;; *) echo "Error: Invalid command." - awsUsage + awsUsage "${@:2}" ;; esac From dbdd27a805c2215f018039bf4f42f46d1bf0cd00 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 7 Feb 2024 21:51:03 -0600 Subject: [PATCH 41/99] Fix invalid command error message in awsUsage function --- src/aws/driver.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index 439d521a..f7ff67c9 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -1,6 +1,6 @@ awsUsage() { - echo "Usage: $0 $1 [command]" + echo "Usage: $0 "$1" [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" @@ -32,7 +32,7 @@ function driver() { ;; *) echo "Error: Invalid command." - awsUsage "${@:2}" + awsUsage ;; esac From b8ee4d5d1b65c5b58caaaa86482b070ef50bd183 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Thu, 8 Feb 2024 04:21:49 +0000 Subject: [PATCH 42/99] tribial --- src/aws/driver.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index f7ff67c9..899ea0af 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -36,4 +36,4 @@ function driver() { ;; esac -} \ No newline at end of file +} From 8cecc01acce1994c40755e597457ba95f1266fab Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 7 Feb 2024 22:22:58 -0600 Subject: [PATCH 43/99] Update usage messages in driver.sh and init.sh scripts --- src/aws/driver.sh | 2 +- src/aws/init.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index f7ff67c9..e3b14139 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -1,6 +1,6 @@ awsUsage() { - echo "Usage: $0 "$1" [command]" + echo "Usage: aws [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" diff --git a/src/aws/init.sh b/src/aws/init.sh index 19527154..20ab90e4 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -114,7 +114,7 @@ function getValueByKeyword(){ } function usage { - echo "script usage: $(basename \$0 "$1 $2") [-n ssh key name] [-p] [-a change key name, instance name, and group name]" >&2 + echo "script usage: $(basename \$0 aws init) [-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' From c504d0fc568898ca1bb2b6e2248b69879cbb315d Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 7 Feb 2024 22:31:51 -0600 Subject: [PATCH 44/99] set 'balloonName' to a default value in the delete, restart, and stop scripts if the argument is empty. --- src/aws/delete.sh | 2 +- src/aws/dependencies/utilitiyFunction.sh | 7 +++++++ src/aws/restart.sh | 2 +- src/aws/stop.sh | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/aws/delete.sh b/src/aws/delete.sh index 1395b8ec..84aee785 100755 --- a/src/aws/delete.sh +++ b/src/aws/delete.sh @@ -5,7 +5,7 @@ BASE=/home/pi function delete(){ - balloonName=$1 + balloonName=$(setBalloonName "$1") if ! isBalloonNameValid "$balloonName"; then echo "Please provide a valid balloon name" diff --git a/src/aws/dependencies/utilitiyFunction.sh b/src/aws/dependencies/utilitiyFunction.sh index 2d780ab9..518751f2 100644 --- a/src/aws/dependencies/utilitiyFunction.sh +++ b/src/aws/dependencies/utilitiyFunction.sh @@ -20,3 +20,10 @@ function waitForOutput(){ echo $result } +setBalloonName() { + if [ -z "$1" ]; then + echo "luftballon" + else + echo "$1" + fi +} \ No newline at end of file diff --git a/src/aws/restart.sh b/src/aws/restart.sh index 7203b086..33a300ba 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -4,7 +4,7 @@ BASE=/home/pi function restart(){ - balloonName=$1 + balloonName=$(setBalloonName "$1") if ! isBalloonNameValid "$balloonName"; then echo "Please provide a valid balloon name" diff --git a/src/aws/stop.sh b/src/aws/stop.sh index bf815133..7fbf5b25 100644 --- a/src/aws/stop.sh +++ b/src/aws/stop.sh @@ -4,7 +4,7 @@ BASE=/home/pi function stop(){ - balloonName=$1 + balloonName=$(setBalloonName "$1") if ! isBalloonNameValid "$balloonName"; then echo "Please provide a valid balloon name" exit 1 From 2efebb64e61b54334a8feff29f9a85e91493fc2d Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 9 Feb 2024 20:36:21 -0600 Subject: [PATCH 45/99] not delete sshtunnel --- src/aws/stop.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/stop.sh b/src/aws/stop.sh index 7fbf5b25..22af232c 100644 --- a/src/aws/stop.sh +++ b/src/aws/stop.sh @@ -22,7 +22,7 @@ function stop(){ storePortArrayString $groupName udp $balloonName publicIp=$(waitForOutput "getLatestIpAddress $instanceId") - treehouses sshtunnel remove host root@$publicIp + #treehouses sshtunnel remove host root@$publicIp echo "Delete sshtunnel of root@$publicIp" aws ec2 stop-instances --instance-ids $instanceId From 944a7c7df96e99e0b853dabad74a272b91f51570 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 9 Feb 2024 20:52:57 -0600 Subject: [PATCH 46/99] check out ip address --- src/aws/driver.sh | 3 +++ src/aws/load.sh | 1 + src/aws/stop.sh | 1 - src/aws/test.sh | 25 +++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/aws/test.sh diff --git a/src/aws/driver.sh b/src/aws/driver.sh index 3cb67d12..9202b302 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -30,6 +30,9 @@ function driver() { restart) restart "${@:2}" ;; + test) + test "${@:2}" + ;; *) echo "Error: Invalid command." awsUsage diff --git a/src/aws/load.sh b/src/aws/load.sh index 5bf776fc..c657f4c0 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -16,4 +16,5 @@ source $manageConfigPath/src/aws/delete.sh source $manageConfigPath/src/aws/stop.sh source $manageConfigPath/src/aws/restart.sh source $manageConfigPath/src/aws/driver.sh +source $manageConfigPath/src/aws/test.sh diff --git a/src/aws/stop.sh b/src/aws/stop.sh index 22af232c..2d92a24b 100644 --- a/src/aws/stop.sh +++ b/src/aws/stop.sh @@ -23,7 +23,6 @@ function stop(){ publicIp=$(waitForOutput "getLatestIpAddress $instanceId") #treehouses sshtunnel remove host root@$publicIp - echo "Delete sshtunnel of root@$publicIp" aws ec2 stop-instances --instance-ids $instanceId diff --git a/src/aws/test.sh b/src/aws/test.sh new file mode 100644 index 00000000..cabf1b34 --- /dev/null +++ b/src/aws/test.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +#BASE=$HOME +BASE=/home/pi + +function test(){ + balloonName=$(setBalloonName "$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 + + publicIp=$(getValueByAttribute $balloonName publicIp) + + echo $publicIp + + +} \ No newline at end of file From 46c266854ece8ee6f6dc3dc35c55c9d1b3e2d205 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 9 Feb 2024 21:07:10 -0600 Subject: [PATCH 47/99] Add replaceIp function and use it to update IP address in restart.sh --- src/aws/dependencies/replaceIp.sh | 19 +++++++++++++++++++ src/aws/restart.sh | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/aws/dependencies/replaceIp.sh diff --git a/src/aws/dependencies/replaceIp.sh b/src/aws/dependencies/replaceIp.sh new file mode 100644 index 00000000..2b195dbf --- /dev/null +++ b/src/aws/dependencies/replaceIp.sh @@ -0,0 +1,19 @@ +replaceIp() { + FILE="/etc/tunnel" + + if [ "$#" -ne 2 ]; then + echo "Usage: replace_ip OLD_IP NEW_IP" + return 1 + fi + + oldIp=$1 + newIp=$2 + + if [ -f "$FILE" ]; then + sudo sed -i "s/$newIp/$oldIp/g" "$FILE" + echo "IP address has been successfully replaced." + else + echo "Error: File $FILE does not exist." + return 1 + fi +} diff --git a/src/aws/restart.sh b/src/aws/restart.sh index 33a300ba..69071992 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -18,6 +18,8 @@ function restart(){ exit 1 fi + oldPublicIp=$(getValueByAttribute $balloonName publicIp) + aws ec2 start-instances --instance-ids $instanceId echo "get the new ip address. The procedure might take time for a while" @@ -28,6 +30,5 @@ function restart(){ echo "the new ip address is $publicIp" updateIPAddress $balloonName $publicIp - echo "open the new sshtunnel" - openSSHTunnel $publicIp $portConfigArray + replaceIp $oldPublicIp $publicIp } \ No newline at end of file From 6b1ca5fae35db9a1c62a527f4c3c777c573b2ffd Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 9 Feb 2024 21:13:42 -0600 Subject: [PATCH 48/99] import replaceIp --- src/aws/load.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aws/load.sh b/src/aws/load.sh index c657f4c0..6453c8de 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -10,6 +10,7 @@ source $manageConfigPath/src/aws/dependencies/securitygroupFunction.sh source $manageConfigPath/src/aws/dependencies/manageConfig.sh source $manageConfigPath/src/aws/dependencies/sshtunnelFunction.sh source $manageConfigPath/src/aws/dependencies/reverseShell.sh +source $manageConfigPath/src/aws/dependencies/replaceIp.sh source $manageConfigPath/src/aws/init.sh source $manageConfigPath/src/aws/delete.sh From f52339efd1d1df4712ca96269c8160fe4648926f Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 9 Feb 2024 21:29:55 -0600 Subject: [PATCH 49/99] debug --- src/aws/dependencies/replaceIp.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/dependencies/replaceIp.sh b/src/aws/dependencies/replaceIp.sh index 2b195dbf..b7f99bb1 100644 --- a/src/aws/dependencies/replaceIp.sh +++ b/src/aws/dependencies/replaceIp.sh @@ -10,7 +10,7 @@ replaceIp() { newIp=$2 if [ -f "$FILE" ]; then - sudo sed -i "s/$newIp/$oldIp/g" "$FILE" + sed -i "s/$oldIp/$newIp/g" "$FILE" echo "IP address has been successfully replaced." else echo "Error: File $FILE does not exist." From f6f8417753f066f093f4d86b63636f3d9a785cdc Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 14 Feb 2024 21:11:11 -0600 Subject: [PATCH 50/99] Remove test.sh and update load.sh --- src/aws/driver.sh | 3 --- src/aws/load.sh | 1 - 2 files changed, 4 deletions(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index 9202b302..3cb67d12 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -30,9 +30,6 @@ function driver() { restart) restart "${@:2}" ;; - test) - test "${@:2}" - ;; *) echo "Error: Invalid command." awsUsage diff --git a/src/aws/load.sh b/src/aws/load.sh index 6453c8de..53796c89 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -17,5 +17,4 @@ source $manageConfigPath/src/aws/delete.sh source $manageConfigPath/src/aws/stop.sh source $manageConfigPath/src/aws/restart.sh source $manageConfigPath/src/aws/driver.sh -source $manageConfigPath/src/aws/test.sh From 573471eb394ec3d1113cea9e6768b52bda087f4f Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 14 Feb 2024 21:20:14 -0600 Subject: [PATCH 51/99] Add test/experiment to .gitignore and remove src/aws/test.sh --- .gitignore | 1 + src/aws/test.sh | 25 ------------------------- 2 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 src/aws/test.sh diff --git a/.gitignore b/.gitignore index 71f9bc7f..64c86501 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /test +/experiment #confs /vpn/conf/* diff --git a/src/aws/test.sh b/src/aws/test.sh deleted file mode 100644 index cabf1b34..00000000 --- a/src/aws/test.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -#BASE=$HOME -BASE=/home/pi - -function test(){ - balloonName=$(setBalloonName "$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 - - publicIp=$(getValueByAttribute $balloonName publicIp) - - echo $publicIp - - -} \ No newline at end of file From e2dbe9b026fbb183f3616e8694a2da726ceacc79 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 21 Feb 2024 21:21:08 -0600 Subject: [PATCH 52/99] Add installAwsCli function to driver.sh --- src/aws/driver.sh | 3 +++ src/aws/installAwsCli.sh | 6 ++++-- src/aws/load.sh | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/aws/driver.sh b/src/aws/driver.sh index 3cb67d12..25d2a134 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -30,6 +30,9 @@ function driver() { restart) restart "${@:2}" ;; + install) + installAwsCli "${@:2}" + ;; *) echo "Error: Invalid command." awsUsage diff --git a/src/aws/installAwsCli.sh b/src/aws/installAwsCli.sh index 67daa971..97fe44a2 100755 --- a/src/aws/installAwsCli.sh +++ b/src/aws/installAwsCli.sh @@ -1,5 +1,7 @@ #!/bin/bash -apt update; -apt install awscli +function installAwsCli(){ + apt update; + apt install awscli +} diff --git a/src/aws/load.sh b/src/aws/load.sh index 53796c89..e95de65f 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -16,5 +16,6 @@ source $manageConfigPath/src/aws/init.sh source $manageConfigPath/src/aws/delete.sh source $manageConfigPath/src/aws/stop.sh source $manageConfigPath/src/aws/restart.sh +source $manageConfigPath/src/aws/installAwsCli.sh source $manageConfigPath/src/aws/driver.sh From 8998336184375df5f7eb1dcfe885add4b8a38322 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 21 Feb 2024 21:24:48 -0600 Subject: [PATCH 53/99] put AWS CLI check and SSH key check in init.sh --- src/aws/init.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/aws/init.sh b/src/aws/init.sh index 20ab90e4..acd52753 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -10,11 +10,7 @@ groupName=luftballons-sg instanceName=luftballon checkSSH=~/.ssh/$publickey -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 function importSshKey() { @@ -152,6 +148,11 @@ function init { 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 From 67b9bf7059211ad934629d8a57fd21083acd5b6a Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 21 Feb 2024 22:55:59 -0600 Subject: [PATCH 54/99] Add updateOrAppend function to update or append IP and name pairs to /etc/hosts file --- src/aws/dependencies/updateOrAppend.sh | 22 ++++++++++++++++++++++ src/aws/load.sh | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/aws/dependencies/updateOrAppend.sh diff --git a/src/aws/dependencies/updateOrAppend.sh b/src/aws/dependencies/updateOrAppend.sh new file mode 100644 index 00000000..acc6bbea --- /dev/null +++ b/src/aws/dependencies/updateOrAppend.sh @@ -0,0 +1,22 @@ +# This function updates or appends an IP and name pair to a file named "/etc/hosts". +# If the name already exists in the file, it updates the corresponding IP. +# If the name does not exist, it appends a new IP and name pair to the end of the file. +# Arguments: +# ip: The IP address to be updated or appended. +# name: The name to be updated or appended. +updateOrAppend() { + local ip="$1" + local name="$2" + local file="/etc/hosts" + + local escaped_name=$(printf '%s\n' "$name" | sed 's:[][\/.^$*]:\\&:g') + + if grep -qP "^\S+\s+$escaped_name$" "$file"; then + sed -i'' -r "/^\S+\s+$escaped_name$/s/.*/$ip\t$name/" "$file" + else + if [ "$(tail -c1 "$file")" != "" ]; then + echo "" >> "$file" + fi + echo "$ip $name" >> "$file" + fi +} diff --git a/src/aws/load.sh b/src/aws/load.sh index e95de65f..9d811bb2 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -10,7 +10,7 @@ source $manageConfigPath/src/aws/dependencies/securitygroupFunction.sh source $manageConfigPath/src/aws/dependencies/manageConfig.sh source $manageConfigPath/src/aws/dependencies/sshtunnelFunction.sh source $manageConfigPath/src/aws/dependencies/reverseShell.sh -source $manageConfigPath/src/aws/dependencies/replaceIp.sh +source $manageConfigPath/src/aws/dependencies/updateOrAppend.sh source $manageConfigPath/src/aws/init.sh source $manageConfigPath/src/aws/delete.sh From 8b6a4678ba29aa758ceed540d235463b60da3928 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 23 Feb 2024 21:17:54 -0600 Subject: [PATCH 55/99] use updateOrAppend function --- src/aws/dependencies/updateOrAppend.sh | 6 +++--- src/aws/init.sh | 4 +++- src/aws/restart.sh | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/aws/dependencies/updateOrAppend.sh b/src/aws/dependencies/updateOrAppend.sh index acc6bbea..8c75fe86 100644 --- a/src/aws/dependencies/updateOrAppend.sh +++ b/src/aws/dependencies/updateOrAppend.sh @@ -2,11 +2,11 @@ # If the name already exists in the file, it updates the corresponding IP. # If the name does not exist, it appends a new IP and name pair to the end of the file. # Arguments: -# ip: The IP address to be updated or appended. # name: The name to be updated or appended. +# ip: The IP address to be updated or appended. updateOrAppend() { - local ip="$1" - local name="$2" + local name="$1" + local ip="$2" local file="/etc/hosts" local escaped_name=$(printf '%s\n' "$name" | sed 's:[][\/.^$*]:\\&:g') diff --git a/src/aws/init.sh b/src/aws/init.sh index acd52753..084bddc6 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -188,7 +188,9 @@ function init { isOpen=$(waitForOutput "ssh-keyscan -H $publicIp | grep ecdsa-sha2-nistp256") echo "Opened ssh tunnel" - openSSHTunnel $publicIp $portConfigArray + updateOrAppend $instanceName $publicIp + openSSHTunnel $instanceName $portConfigArray + storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName } diff --git a/src/aws/restart.sh b/src/aws/restart.sh index 69071992..3ecde38d 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -30,5 +30,5 @@ function restart(){ echo "the new ip address is $publicIp" updateIPAddress $balloonName $publicIp - replaceIp $oldPublicIp $publicIp + updateOrAppend $instanceName $publicIp } \ No newline at end of file From 25aec13c3c047f078c828b1fc993567fcbd2e5e7 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Tue, 26 Mar 2024 20:09:50 -0500 Subject: [PATCH 56/99] make crud functions --- config.txt | 22 ++++++++++++++++++++++ create.sh | 28 ++++++++++++++++++++++++++++ delete.sh | 19 +++++++++++++++++++ read.sh | 22 ++++++++++++++++++++++ retrieve.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ update.sh | 20 ++++++++++++++++++++ 6 files changed, 155 insertions(+) create mode 100644 config.txt create mode 100644 create.sh create mode 100644 delete.sh create mode 100644 read.sh create mode 100644 retrieve.sh create mode 100644 update.sh diff --git a/config.txt b/config.txt new file mode 100644 index 00000000..36918230 --- /dev/null +++ b/config.txt @@ -0,0 +1,22 @@ + +Host remoteserver + HostName newremoteserver.com + User newremoteuser + Port newremoteport + IdentityFile /new/path/to/remote/server/private/key + RemoteForward 2223 localhost:80 + ServerAliveInterval 30 + ServerAliveCountMax 3 + ExitOnForwardFailure yes + TCPKeepAlive yes + +Host remoteserver1 + HostName newremoteserver.com + User newremoteuser + Port newremoteport + IdentityFile /new/path/to/remote/server/private/key + RemoteForward 2223 localhost:80 + ServerAliveInterval 30 + ServerAliveCountMax 3 + ExitOnForwardFailure yes + TCPKeepAlive yes diff --git a/create.sh b/create.sh new file mode 100644 index 00000000..5d21f1e2 --- /dev/null +++ b/create.sh @@ -0,0 +1,28 @@ +dummy=config + +create_ssh_config() { + HOST_NAME="$1" + HOST_ENTRY=$(cat <> $dummy + echo "Configuration for $HOST_NAME created." + fi +} + +#create_ssh_config "remoteserver" "remoteserver.com" "remoteuser" "remoteport" "/path/to/remote/server/private/key" "2222" "22" diff --git a/delete.sh b/delete.sh new file mode 100644 index 00000000..1bc42954 --- /dev/null +++ b/delete.sh @@ -0,0 +1,19 @@ + +dummy=config + +delete_ssh_config() { + HOST_NAME="$1" + TEMP_FILE=$(mktemp) + + # Ensure the temporary file gets deleted + trap "rm -f $TEMP_FILE" EXIT + + awk -v host="$HOST_NAME" ' + $1 == "Host" && $2 == host {skip = 1} + $1 == "Host" && $2 != host && skip {skip = 0; print ""} + !skip {print} + ' $dummy > "$TEMP_FILE" && mv "$TEMP_FILE" $dummy + + echo "Configuration for $HOST_NAME deleted." +} +delete_ssh_config "remoteserver" diff --git a/read.sh b/read.sh new file mode 100644 index 00000000..c7af7125 --- /dev/null +++ b/read.sh @@ -0,0 +1,22 @@ +get_ssh_config_values() { + HOST_NAME=$1 + CONFIG_FILE=config.txt + FOUND_HOST=0 + + while IFS= read -r line; do + if [[ "$line" == Host\ $HOST_NAME ]]; then + FOUND_HOST=1 + echo "$line" + elif [[ "$line" == Host\ * && $FOUND_HOST -eq 1 ]]; then + break + elif [[ $FOUND_HOST -eq 1 ]]; then + echo "$line" + fi + done < "$CONFIG_FILE" + + if [ $FOUND_HOST -eq 0 ]; then + echo "No configuration found for $HOST_NAME." + fi +} + +#get_ssh_config_values remoteserver1 \ No newline at end of file diff --git a/retrieve.sh b/retrieve.sh new file mode 100644 index 00000000..6ec797f6 --- /dev/null +++ b/retrieve.sh @@ -0,0 +1,44 @@ +source read.sh +extract_ssh_config_to_variables() { + # Capture the output of get_ssh_config_values + CONFIG_OUTPUT=$(get_ssh_config_values "$1") + + # Check if the configuration was found + if echo "$CONFIG_OUTPUT" | grep -q "No configuration found"; then + echo "No configuration found for $1." + return 1 + fi + + # Extracting configuration details + HOST_NAME=$(echo "$CONFIG_OUTPUT" | grep "Host " | awk '{print $NF}') + HOSTNAME=$(echo "$CONFIG_OUTPUT" | grep "HostName " | awk '{print $NF}') + USER=$(echo "$CONFIG_OUTPUT" | grep "User " | awk '{print $NF}') + PORT=$(echo "$CONFIG_OUTPUT" | grep "Port " | awk '{print $NF}') + IDENTITYFILE=$(echo "$CONFIG_OUTPUT" | grep "IdentityFile " | awk '{print $NF}') + REMOTEFORWARD=$(echo "$CONFIG_OUTPUT" | grep "RemoteForward " | awk '{$1=""; print $0}' | xargs) + LOCALPORT=$(echo "$REMOTEFORWARD" | cut -d' ' -f1) + REMOTEHOSTANDPORT=$(echo "$REMOTEFORWARD" | cut -d' ' -f2) + REMOTEHOST=$(echo "$REMOTEHOSTANDPORT" | cut -d':' -f1) + REMOTEPORT=$(echo "$REMOTEHOSTANDPORT" | cut -d':' -f2) + SERVERALIVEINTERVAL=$(echo "$CONFIG_OUTPUT" | grep "ServerAliveInterval " | awk '{print $NF}') + SERVERALIVECOUNTMAX=$(echo "$CONFIG_OUTPUT" | grep "ServerAliveCountMax " | awk '{print $NF}') + EXITONFORWARDFAILURE=$(echo "$CONFIG_OUTPUT" | grep "ExitOnForwardFailure " | awk '{print $NF}') + TCPKEEPALIVE=$(echo "$CONFIG_OUTPUT" | grep "TCPKeepAlive " | awk '{print $NF}') + + # Display the variables for demonstration + echo "HOST_NAME: $HOST_NAME" + echo "HOSTNAME: $HOSTNAME" + echo "USER: $USER" + echo "PORT: $PORT" + echo "IDENTITYFILE: $IDENTITYFILE" + echo "REMOTEFORWARD: $REMOTEFORWARD" + echo "LOCALPORT: $LOCALPORT" + echo "REMOTEHOST: $REMOTEHOST" + echo "REMOTEPORT: $REMOTEPORT" + echo "SERVERALIVEINTERVAL: $SERVERALIVEINTERVAL" + echo "SERVERALIVECOUNTMAX: $SERVERALIVECOUNTMAX" + echo "EXITONFORWARDFAILURE: $EXITONFORWARDFAILURE" + echo "TCPKEEPALIVE: $TCPKEEPALIVE" +} + +extract_ssh_config_to_variables remoteserver1 \ No newline at end of file diff --git a/update.sh b/update.sh new file mode 100644 index 00000000..a242541e --- /dev/null +++ b/update.sh @@ -0,0 +1,20 @@ +source create.sh +dummy=config +update_ssh_config() { + HOST_NAME="$1" + TEMP_FILE=$(mktemp) + + # Ensure the temporary file gets deleted + trap "rm -f $TEMP_FILE" EXIT + + awk -v host="$HOST_NAME" ' + $1 == "Host" && $2 == host {skip = 1} + $1 == "Host" && $2 != host && skip {skip = 0; print ""} + !skip {print} + ' $dummy > "$TEMP_FILE" && mv "$TEMP_FILE" $dummy + + create_ssh_config "$@" + echo "Configuration for $HOST_NAME updated." +} + +update_ssh_config "remoteserver" "newremoteserver.com" "newremoteuser" "newremoteport" "/new/path/to/remote/server/private/key" "2223" "80" From 812f0a4aac4a70a122dd6e6b60836c018de60bd3 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 17 Apr 2024 20:55:58 -0500 Subject: [PATCH 57/99] create several forward lines at once --- array.sh | 24 ++++++++++++++++++++ callUpdate.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ create.sh | 21 +++++++++++++++-- read.sh | 4 +--- retrieve.sh | 24 ++++++-------------- update.sh | 2 +- 6 files changed, 114 insertions(+), 23 deletions(-) create mode 100644 array.sh create mode 100644 callUpdate.sh diff --git a/array.sh b/array.sh new file mode 100644 index 00000000..a0ede4bb --- /dev/null +++ b/array.sh @@ -0,0 +1,24 @@ + +extractBlocks() { + local input_string="$1" + local block_pattern='([0-9]+)\ localhost:([0-9]+)' + local -a blocks_array + + while read -r block; do + if [[ $block =~ $block_pattern ]]; then + blocks_array+=("$block") + fi + done <<< "$(echo $input_string | grep -oE '([0-9]+)\ localhost:[0-9]+')" + + for block in "${blocks_array[@]}"; do + echo "$block" + done +} + +input_string="12345 localhost:22 54321 localhost:80 ..." +# Capture the output in an array +readarray -t captured_blocks < <(extractBlocks "$input_string") +# Print each captured block +for block in "${captured_blocks[@]}"; do + echo "$block" +done \ No newline at end of file diff --git a/callUpdate.sh b/callUpdate.sh new file mode 100644 index 00000000..1d061480 --- /dev/null +++ b/callUpdate.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +source update.sh +source retrieve.sh + +host="remoteserver1" + +ssh_config=$(extract_ssh_config_to_variables $host) + +function update(){ + host=$1 + newKey=$2 + newValue=$3 + + if [ $? -ne 0 ]; then + echo "Failed to execute extract_ssh_config_to_variables or the command does not exist." + exit 1 + fi + + while IFS=: read -r key value; do + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + + declare "$key=$value" + done <<< "$ssh_config" + + case "$newKey" in + "HostName") + HostName=$newValue + ;; + "User") + User=$newValue + ;; + "Port") + Port=$newValue + ;; + "IdentityFile") + IdentityFile=$newValue + ;; + "ServerAliveInterval") + ServerAliveInterval=$newValue + ;; + "ServerAliveCountMax") + ServerAliveCountMax=$newValue + ;; + "ExitOnForwardFailure") + ExitOnForwardFailure=$newValue + ;; + "TCPKeepAlive") + TCPKeepAlive=$newValue + ;; + *) + echo "Invalid key." + exit 1 + ;; + esac + + update_ssh_config "$host" "$HostName" "$User" "$Port" "$IdentityFile" "2222:88" + +} + +update $host "HostName" "newremoteserver.com" \ No newline at end of file diff --git a/create.sh b/create.sh index 5d21f1e2..8cb02c13 100644 --- a/create.sh +++ b/create.sh @@ -1,5 +1,22 @@ dummy=config +#create_ssh_config() { +# HOST_NAME="$1" +# HOST_ENTRY=$(cat < Date: Wed, 17 Apr 2024 22:28:48 -0500 Subject: [PATCH 58/99] Refactor extractBlocks to format output and adopt camelCase variables - Initialized allPortsPairs for concatenated output. - Updated loop to format local and remote ports into a single string. - Shifted variable naming to camelCase for consistency. --- array.sh | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/array.sh b/array.sh index a0ede4bb..42fd8fb7 100644 --- a/array.sh +++ b/array.sh @@ -1,24 +1,23 @@ extractBlocks() { - local input_string="$1" - local block_pattern='([0-9]+)\ localhost:([0-9]+)' - local -a blocks_array + local inputString="$1" + local blockPattern='([0-9]+)\ localhost:([0-9]+)' + local -a blocksArray + local allPortsPairs="" while read -r block; do - if [[ $block =~ $block_pattern ]]; then - blocks_array+=("$block") + if [[ $block =~ $blockPattern ]]; then + blocksArray+=("$block") fi - done <<< "$(echo $input_string | grep -oE '([0-9]+)\ localhost:[0-9]+')" + done <<< "$(echo $inputString | grep -oE '([0-9]+)\ localhost:[0-9]+')" - for block in "${blocks_array[@]}"; do - echo "$block" + for block in "${blocksArray[@]}"; do + local localPort=$(echo "$block" | cut -d' ' -f1) + local remoteHostAndPort=$(echo "$block" | cut -d' ' -f2) + local remotePort=$(echo "$remoteHostAndPort" | cut -d':' -f2) + allPortsPairs+="${localPort}:${remotePort}," done + allPortsPairs="${allPortsPairs%,}" + echo "$allPortsPairs" } -input_string="12345 localhost:22 54321 localhost:80 ..." -# Capture the output in an array -readarray -t captured_blocks < <(extractBlocks "$input_string") -# Print each captured block -for block in "${captured_blocks[@]}"; do - echo "$block" -done \ No newline at end of file From 90e95284b6588518e517468f516358cdeeedec56 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 17 Apr 2024 22:30:08 -0500 Subject: [PATCH 59/99] Add test_extractBlocks function to validate extractBlocks output - Source array.sh to access extractBlocks function. - Implement test_extractBlocks function to run automated tests. - Include sample tests for different input scenarios. --- allTest.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 allTest.sh diff --git a/allTest.sh b/allTest.sh new file mode 100644 index 00000000..093ecac5 --- /dev/null +++ b/allTest.sh @@ -0,0 +1,15 @@ +source array.sh + +test_extractBlocks() { + local input_string="$1" + echo "Testing with input: $input_string" + # Capture the output in an array + readarray -t captured_blocks < <(extractBlocks "$input_string") + # Print each captured block + for block in "${captured_blocks[@]}"; do + echo "$block" + done +} + +test_extractBlocks "12345 localhost:22 54321 localhost:80 ..." +test_extractBlocks "67890 localhost:443 another_text 98765 localhost:8080" From 0d637857529bcf74aeb0d12daf798da32ceea619 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 24 Apr 2024 22:10:42 -0500 Subject: [PATCH 60/99] update RemoteForward argument --- allTest.sh | 24 ++++++++++++++++++++++++ callUpdate.sh | 29 +++++++++++++++++++++-------- replace.sh | 11 +++++++++++ retrieve.sh | 6 +----- 4 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 replace.sh diff --git a/allTest.sh b/allTest.sh index 093ecac5..32bf5623 100644 --- a/allTest.sh +++ b/allTest.sh @@ -1,4 +1,5 @@ source array.sh +source replace.sh test_extractBlocks() { local input_string="$1" @@ -13,3 +14,26 @@ test_extractBlocks() { test_extractBlocks "12345 localhost:22 54321 localhost:80 ..." test_extractBlocks "67890 localhost:443 another_text 98765 localhost:8080" + +test_replaceFirstOccurrence() { + local test_all="$1" + local test_first="$2" + local test_second="$3" + local expected_result="$4" + + local result=$(replaceFirstOccurrence "$test_all" "$test_first" "$test_second") + if [[ "$result" == "$expected_result" ]]; then + echo "PASS: Got expected result '$result'" + else + echo "FAIL: Expected '$expected_result', but got '$result'" + fi +} + +# Run test cases +echo "Running test cases..." +test_replaceFirstOccurrence "8888:80,9999:443" "8888:80" "8887:81" "8887:81,9999:443" +test_replaceFirstOccurrence "8888:80,9999:443" "9999:443" "9998:442" "8888:80,9998:442" +test_replaceFirstOccurrence "8888:80,9999:443" "7777:77" "7776:76" "8888:80,9999:443" +test_replaceFirstOccurrence "8888:80,8888:80" "8888:80" "8887:81" "8887:81,8888:80" +test_replaceFirstOccurrence "" "8888:80" "8887:81" "" +echo "Tests completed." \ No newline at end of file diff --git a/callUpdate.sh b/callUpdate.sh index 1d061480..cfdc05f4 100644 --- a/callUpdate.sh +++ b/callUpdate.sh @@ -2,18 +2,21 @@ source update.sh source retrieve.sh +source array.sh +source replace.sh -host="remoteserver1" +host="myserver" -ssh_config=$(extract_ssh_config_to_variables $host) function update(){ - host=$1 - newKey=$2 - newValue=$3 + local host=$1 + local newKey=$2 + local newValue=$3 + local currentValue + local ssh_config=$(extractSshConfigToVariables $host) if [ $? -ne 0 ]; then - echo "Failed to execute extract_ssh_config_to_variables or the command does not exist." + echo "Failed to execute extractSshConfigToVariables or the command does not exist." exit 1 fi @@ -48,6 +51,15 @@ function update(){ ;; "TCPKeepAlive") TCPKeepAlive=$newValue + ;; + "RemoteForward") + currentValue=$newValue # Assign newValue to currentValue + if [[ -n "$4" ]]; then + newValue=$4 # Update newValue if a fourth argument is provided + fi + allArgument=$(extractBlocks "$RemoteForward") + RemoteForward=$(replaceFirstOccurrence "$allArgument" "$currentValue" "$newValue") + ;; *) echo "Invalid key." @@ -55,8 +67,9 @@ function update(){ ;; esac - update_ssh_config "$host" "$HostName" "$User" "$Port" "$IdentityFile" "2222:88" + + update_ssh_config "$host" "$HostName" "$User" "$Port" "$IdentityFile" "$RemoteForward" } -update $host "HostName" "newremoteserver.com" \ No newline at end of file +update $host "RemoteForward" "8888:80" "8887:81" \ No newline at end of file diff --git a/replace.sh b/replace.sh new file mode 100644 index 00000000..8091a974 --- /dev/null +++ b/replace.sh @@ -0,0 +1,11 @@ +replaceFirstOccurrence() { + local all="$1" + local first="$2" + local second="$3" + + if [[ "$all" == *"$first"* ]]; then + all="${all/$first/$second}" + fi + + echo "$all" +} \ No newline at end of file diff --git a/retrieve.sh b/retrieve.sh index 10aa3a9e..c19a7042 100644 --- a/retrieve.sh +++ b/retrieve.sh @@ -1,5 +1,5 @@ source read.sh -extract_ssh_config_to_variables() { +extractSshConfigToVariables() { # Capture the output of get_ssh_config_values CONFIG_OUTPUT=$(get_ssh_config_values "$1") @@ -16,10 +16,6 @@ extract_ssh_config_to_variables() { PORT=$(echo "$CONFIG_OUTPUT" | grep "Port " | awk '{print $NF}') IDENTITYFILE=$(echo "$CONFIG_OUTPUT" | grep "IdentityFile " | awk '{print $NF}') REMOTEFORWARD=$(echo "$CONFIG_OUTPUT" | grep "RemoteForward " | awk '{$1=""; print $0}' | xargs ) - LOCALPORT=$(echo "$REMOTEFORWARD" | cut -d' ' -f1) - REMOTEHOSTANDPORT=$(echo "$REMOTEFORWARD" | cut -d' ' -f2) - REMOTEHOST=$(echo "$REMOTEHOSTANDPORT" | cut -d':' -f1) - REMOTEPORT=$(echo "$REMOTEHOSTANDPORT" | cut -d':' -f2) SERVERALIVEINTERVAL=$(echo "$CONFIG_OUTPUT" | grep "ServerAliveInterval " | awk '{print $NF}') SERVERALIVECOUNTMAX=$(echo "$CONFIG_OUTPUT" | grep "ServerAliveCountMax " | awk '{print $NF}') EXITONFORWARDFAILURE=$(echo "$CONFIG_OUTPUT" | grep "ExitOnForwardFailure " | awk '{print $NF}') From 4b13aafda4dc59c321252c15ee1b0e7a0c1a04f1 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 26 Apr 2024 22:06:45 -0500 Subject: [PATCH 61/99] Refactor: Organize Bash scripts and introduce centralized configuration - Moved existing Bash scripts into designated directories for better organization. - Added config.sh to define file paths centrally. - Created load.sh to source all dependencies and script files from the newly defined paths. - Implemented driver.sh to handle user interactions and function invocations. - Ensured load.sh is executed within driver.sh to initialize all configurations and dependencies. --- callUpdate.sh => src/utils/callUpdate.sh | 9 +---- create.sh => src/utils/create.sh | 22 +---------- delete.sh => src/utils/delete.sh | 3 +- array.sh => src/utils/dependencies/array.sh | 0 src/utils/dependencies/config.sh | 2 + read.sh => src/utils/dependencies/read.sh | 3 +- .../utils/dependencies/replace.sh | 0 .../utils/dependencies/retrieve.sh | 1 - src/utils/driver.sh | 39 +++++++++++++++++++ src/utils/load.sh | 11 ++++++ update.sh => src/utils/update.sh | 6 +-- 11 files changed, 59 insertions(+), 37 deletions(-) rename callUpdate.sh => src/utils/callUpdate.sh (87%) rename create.sh => src/utils/create.sh (60%) rename delete.sh => src/utils/delete.sh (85%) rename array.sh => src/utils/dependencies/array.sh (100%) create mode 100644 src/utils/dependencies/config.sh rename read.sh => src/utils/dependencies/read.sh (90%) rename replace.sh => src/utils/dependencies/replace.sh (100%) rename retrieve.sh => src/utils/dependencies/retrieve.sh (98%) create mode 100644 src/utils/driver.sh create mode 100644 src/utils/load.sh rename update.sh => src/utils/update.sh (62%) diff --git a/callUpdate.sh b/src/utils/callUpdate.sh similarity index 87% rename from callUpdate.sh rename to src/utils/callUpdate.sh index cfdc05f4..1859c5ed 100644 --- a/callUpdate.sh +++ b/src/utils/callUpdate.sh @@ -1,10 +1,5 @@ #!/bin/bash -source update.sh -source retrieve.sh -source array.sh -source replace.sh - host="myserver" @@ -53,9 +48,9 @@ function update(){ TCPKeepAlive=$newValue ;; "RemoteForward") - currentValue=$newValue # Assign newValue to currentValue + currentValue=$newValue if [[ -n "$4" ]]; then - newValue=$4 # Update newValue if a fourth argument is provided + newValue=$4 fi allArgument=$(extractBlocks "$RemoteForward") RemoteForward=$(replaceFirstOccurrence "$allArgument" "$currentValue" "$newValue") diff --git a/create.sh b/src/utils/create.sh similarity index 60% rename from create.sh rename to src/utils/create.sh index 8cb02c13..aaca6010 100644 --- a/create.sh +++ b/src/utils/create.sh @@ -1,21 +1,3 @@ -dummy=config - -#create_ssh_config() { -# HOST_NAME="$1" -# HOST_ENTRY=$(cat <> $dummy + echo "$HOST_ENTRY" >> $CONFIG echo "Configuration for $HOST_NAME created." fi } diff --git a/delete.sh b/src/utils/delete.sh similarity index 85% rename from delete.sh rename to src/utils/delete.sh index 1bc42954..8ef74bc2 100644 --- a/delete.sh +++ b/src/utils/delete.sh @@ -1,5 +1,4 @@ -dummy=config delete_ssh_config() { HOST_NAME="$1" @@ -12,7 +11,7 @@ delete_ssh_config() { $1 == "Host" && $2 == host {skip = 1} $1 == "Host" && $2 != host && skip {skip = 0; print ""} !skip {print} - ' $dummy > "$TEMP_FILE" && mv "$TEMP_FILE" $dummy + ' $CONFIG > "$TEMP_FILE" && mv "$TEMP_FILE" $CONFIG echo "Configuration for $HOST_NAME deleted." } diff --git a/array.sh b/src/utils/dependencies/array.sh similarity index 100% rename from array.sh rename to src/utils/dependencies/array.sh diff --git a/src/utils/dependencies/config.sh b/src/utils/dependencies/config.sh new file mode 100644 index 00000000..937ab62d --- /dev/null +++ b/src/utils/dependencies/config.sh @@ -0,0 +1,2 @@ +#CONFIG=~/.ssh/config +CONFIG=~/Projects/luftballon/config # Test \ No newline at end of file diff --git a/read.sh b/src/utils/dependencies/read.sh similarity index 90% rename from read.sh rename to src/utils/dependencies/read.sh index 137fa7ad..8b0c8200 100644 --- a/read.sh +++ b/src/utils/dependencies/read.sh @@ -1,6 +1,5 @@ get_ssh_config_values() { HOST_NAME=$1 - CONFIG_FILE=config FOUND_HOST=0 while IFS= read -r line; do @@ -12,7 +11,7 @@ get_ssh_config_values() { elif [[ $FOUND_HOST -eq 1 ]]; then echo "$line" fi - done < "$CONFIG_FILE" + done < "$CONFIG" if [ $FOUND_HOST -eq 0 ]; then echo "No configuration found for $HOST_NAME." diff --git a/replace.sh b/src/utils/dependencies/replace.sh similarity index 100% rename from replace.sh rename to src/utils/dependencies/replace.sh diff --git a/retrieve.sh b/src/utils/dependencies/retrieve.sh similarity index 98% rename from retrieve.sh rename to src/utils/dependencies/retrieve.sh index c19a7042..a5f48d86 100644 --- a/retrieve.sh +++ b/src/utils/dependencies/retrieve.sh @@ -1,4 +1,3 @@ -source read.sh extractSshConfigToVariables() { # Capture the output of get_ssh_config_values CONFIG_OUTPUT=$(get_ssh_config_values "$1") diff --git a/src/utils/driver.sh b/src/utils/driver.sh new file mode 100644 index 00000000..3a424282 --- /dev/null +++ b/src/utils/driver.sh @@ -0,0 +1,39 @@ +source load.sh + +function sshConfigManagerUsage() { + echo "Usage: driver [options]" + echo "" + echo "Commands:" + echo " create Create a new SSH configuration" + echo " update Update an existing SSH configuration" + echo " delete Delete an SSH configuration" + echo "" + echo "Options:" + echo " -h, --help Show help information" +} + +function driver() { + + # Check if at least one argument is provided + if [ $# -eq 0 ]; then + sshConfigManagerUsage + fi + + # Execute the appropriate command + case "$1" in + create) + create "${@:2}" + ;; + update) + callUpdate "${@:2}" + ;; + delete) + delete "${@:2}" + ;; + *) + echo "Error: Invalid command." + sshConfigManagerUsage + ;; + esac + +} \ No newline at end of file diff --git a/src/utils/load.sh b/src/utils/load.sh new file mode 100644 index 00000000..5eada01f --- /dev/null +++ b/src/utils/load.sh @@ -0,0 +1,11 @@ +manageConfigPath=$(pwd) +source $manageConfigPath/dependencies/config.sh +source $manageConfigPath/dependencies/array.sh +source $manageConfigPath/dependencies/read.sh +source $manageConfigPath/dependencies/replace.sh +source $manageConfigPath/dependencies/retrieve.sh + +source $manageConfigPath/create.sh +source $manageConfigPath/update.sh +source $manageConfigPath/delete.sh +source $manageConfigPath/callUpdate.sh diff --git a/update.sh b/src/utils/update.sh similarity index 62% rename from update.sh rename to src/utils/update.sh index b37ebd7e..4a36e1f0 100644 --- a/update.sh +++ b/src/utils/update.sh @@ -1,5 +1,3 @@ -source create.sh -dummy=config update_ssh_config() { HOST_NAME="$1" TEMP_FILE=$(mktemp) @@ -11,10 +9,8 @@ update_ssh_config() { $1 == "Host" && $2 == host {skip = 1} $1 == "Host" && $2 != host && skip {skip = 0; print ""} !skip {print} - ' $dummy > "$TEMP_FILE" && mv "$TEMP_FILE" $dummy + ' $CONFIG > "$TEMP_FILE" && mv "$TEMP_FILE" $CONFIG create_ssh_config "$@" echo "Configuration for $HOST_NAME updated." } - -#update_ssh_config "remoteserver" "newremoteserver.com" "newremoteuser" "newremoteport" "/new/path/to/remote/server/private/key" "2222" "88" From 440b6a4f0666c681362d8b2e729cf202a9887883 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 10 May 2024 21:41:45 -0500 Subject: [PATCH 62/99] call functions from the main.sh --- main.sh | 4 ++++ src/utils/callUpdate.sh | 4 ++-- src/utils/create.sh | 4 ++-- src/utils/delete.sh | 5 +++-- src/utils/dependencies/retrieve.sh | 2 +- src/utils/driver.sh | 7 +++---- src/utils/load.sh | 20 ++++++++++---------- src/utils/update.sh | 4 ++-- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/main.sh b/main.sh index 03ebb2d3..8a8f9c9c 100644 --- a/main.sh +++ b/main.sh @@ -20,6 +20,10 @@ case "$1" in source $manageConfigPath/src/aws/load.sh driver "${@:2}" ;; + sshConfigManager) + source $manageConfigPath/src/utils/load.sh + driver "${@:2}" + ;; *) echo "Error: Invalid command." usage diff --git a/src/utils/callUpdate.sh b/src/utils/callUpdate.sh index 1859c5ed..c757000f 100644 --- a/src/utils/callUpdate.sh +++ b/src/utils/callUpdate.sh @@ -63,8 +63,8 @@ function update(){ esac - update_ssh_config "$host" "$HostName" "$User" "$Port" "$IdentityFile" "$RemoteForward" + updateSshConfig "$host" "$HostName" "$User" "$Port" "$IdentityFile" "$RemoteForward" } -update $host "RemoteForward" "8888:80" "8887:81" \ No newline at end of file +#update $host "RemoteForward" "8888:80" "8887:81" \ No newline at end of file diff --git a/src/utils/create.sh b/src/utils/create.sh index aaca6010..48a9c51d 100644 --- a/src/utils/create.sh +++ b/src/utils/create.sh @@ -1,5 +1,5 @@ -create_ssh_config() { +createSshConfig() { HOST_NAME="$1" HOST_ENTRY=$(cat < [options]" @@ -22,13 +21,13 @@ function driver() { # Execute the appropriate command case "$1" in create) - create "${@:2}" + createSshConfig "${@:2}" ;; update) - callUpdate "${@:2}" + update "${@:2}" ;; delete) - delete "${@:2}" + deleteSshConfig "${@:2}" ;; *) echo "Error: Invalid command." diff --git a/src/utils/load.sh b/src/utils/load.sh index 5eada01f..f672337f 100644 --- a/src/utils/load.sh +++ b/src/utils/load.sh @@ -1,11 +1,11 @@ -manageConfigPath=$(pwd) -source $manageConfigPath/dependencies/config.sh -source $manageConfigPath/dependencies/array.sh -source $manageConfigPath/dependencies/read.sh -source $manageConfigPath/dependencies/replace.sh -source $manageConfigPath/dependencies/retrieve.sh +source $manageConfigPath/src/utils/dependencies/config.sh +source $manageConfigPath/src/utils/dependencies/array.sh +source $manageConfigPath/src/utils/dependencies/read.sh +source $manageConfigPath/src/utils/dependencies/replace.sh +source $manageConfigPath/src/utils/dependencies/retrieve.sh -source $manageConfigPath/create.sh -source $manageConfigPath/update.sh -source $manageConfigPath/delete.sh -source $manageConfigPath/callUpdate.sh +source $manageConfigPath/src/utils/create.sh +source $manageConfigPath/src/utils/update.sh +source $manageConfigPath/src/utils/delete.sh +source $manageConfigPath/src/utils/callUpdate.sh +source $manageConfigPath/src/utils/driver.sh diff --git a/src/utils/update.sh b/src/utils/update.sh index 4a36e1f0..c2e868cd 100644 --- a/src/utils/update.sh +++ b/src/utils/update.sh @@ -1,4 +1,4 @@ -update_ssh_config() { +updateSshConfig() { HOST_NAME="$1" TEMP_FILE=$(mktemp) @@ -11,6 +11,6 @@ update_ssh_config() { !skip {print} ' $CONFIG > "$TEMP_FILE" && mv "$TEMP_FILE" $CONFIG - create_ssh_config "$@" + createSshConfig "$@" echo "Configuration for $HOST_NAME updated." } From ba452edcfca0d5a14de5f534d21f76f00f47ba61 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 10 May 2024 22:47:56 -0500 Subject: [PATCH 63/99] make explanation for how to call sshConfigManager --- README.md | 52 +++++++++++++++++++++++++++++++++++++++++ main.sh | 1 + src/utils/callUpdate.sh | 3 --- src/utils/driver.sh | 10 +++++--- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 413199ed..35b5a777 100644 --- a/README.md +++ b/README.md @@ -131,3 +131,55 @@ This command basically does the opposite of the `init.sh` 2. Delete EC2 instance 3. Delete security group on the EC2 portal 4. Delete ssh key on the AWS EC2 portal + +### sshConfigManager Interface + +The `sshConfigManager` interface is designed to facilitate the management of SSH configurations, providing methods to create, update, and delete SSH configuration entries. This interface streamlines the process of maintaining complex SSH config files, making it easier to manage access to multiple remote servers. + +#### Create Command + +**What it does:** +The `create` command generates a new entry in the SSH configuration file with detailed settings for host alias, hostname, user, port, identity file, and port forwarding options. + +**How to execute:** +To add a new SSH configuration entry: + +``` +create "myserver" "example.com" "user" "22" "~/.ssh/id_rsa" "8888:80,9999:443" +``` + +This command sets up a host with alias `myserver`, connecting to `example.com` on port 22 with the specified identity file and port forwarding settings. + +#### Update Command + +**What it does:** +The `update` command modifies an existing SSH configuration entry for a specified host. It can change settings for any key such as `User`, `Port`, or complex keys like `RemoteForward`, where both old and new port forwarding settings need to be specified. + +**How to execute:** +To change the `User` for host `myserver`: + +``` +update myserver User newuser +``` + +To update a `RemoteForward` setting: + +``` +update myserver RemoteForward 8888:80 8899:80 +``` + +These commands adjust the specified configurations, replacing old values with new ones. + +#### Delete Command + +**What it does:** +The `delete` command removes an entire SSH configuration block for a specified host from the SSH config file, effectively discontinuing the SSH management for that host through the configuration file. + +**How to execute:** +To remove the configuration for a host: + +``` +delete myserver +``` + +This command deletes all settings associated with the host `myserver`, cleaning up the SSH config file by removing unused or outdated entries. diff --git a/main.sh b/main.sh index 8a8f9c9c..8f3a88e6 100644 --- a/main.sh +++ b/main.sh @@ -6,6 +6,7 @@ usage() { echo "Usage: $0 credential [command]" echo "Commands:" echo " aws - Execute an AWS command" + echo " sshConfigManager - An interface that manages SSH configurations, allowing creation, updating, and deletion of SSH configuration entries" exit 1 } diff --git a/src/utils/callUpdate.sh b/src/utils/callUpdate.sh index c757000f..df0574bc 100644 --- a/src/utils/callUpdate.sh +++ b/src/utils/callUpdate.sh @@ -1,8 +1,5 @@ #!/bin/bash -host="myserver" - - function update(){ local host=$1 local newKey=$2 diff --git a/src/utils/driver.sh b/src/utils/driver.sh index 14527a57..ea70c59f 100644 --- a/src/utils/driver.sh +++ b/src/utils/driver.sh @@ -3,9 +3,13 @@ function sshConfigManagerUsage() { echo "Usage: driver [options]" echo "" echo "Commands:" - echo " create Create a new SSH configuration" - echo " update Update an existing SSH configuration" - echo " delete Delete an SSH configuration" + echo " create - Generates an SSH configuration block with specified host, user, port, identity key, and port forwarding settings." + echo " should be specified in the format 'local_port:remote_port', and you can include multiple mappings separated by commas to forward several ports." + echo "" + echo " update - Modifies an existing key-value pair in the SSH configuration for the specified host." + echo " update - Updates a specific RemoteForward entry by replacing an old port mapping with a new one." + echo "" + echo " delete - Removes the entire SSH configuration entry associated with the specified host." echo "" echo "Options:" echo " -h, --help Show help information" From 4beb8db3cd618604ebc7b8d8d56244071a810dcf Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 31 May 2024 21:22:16 -0500 Subject: [PATCH 64/99] Added detailed comments and minor improvements to openSSHTunnel function - Added key fingerprint addition for 'luftballon' in openSSHTunnel function for increased security. - Added detailed comments explaining the use of `screen` to restart SSH service. --- src/aws/dependencies/reverseShell.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index 5053d21e..8eaeb408 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -55,6 +55,7 @@ function openSSHTunnel(){ local sshtunnelPortArray=$luftballonHostPort:$serverPort addKeyFingerprintToKnownHost $instanceIp + addKeyFingerprintToKnownHost luftballon treehouses sshtunnel key name $sshkey sleep 2 @@ -64,6 +65,10 @@ function openSSHTunnel(){ ssh -i /root/.ssh/$sshkey root@$instanceIp 'echo "GatewayPorts yes" >> /etc/ssh/sshd_config' sleep 2 + # Restart SSH service on the remote machine in a detached screen session + # Use `screen` to run the command in the background, + # ensuring it completes even if the SSH connection is lost. + # This is necessary to apply the changes made to the SSH configuration. ssh -i /root/.ssh/$sshkey root@$instanceIp 'screen -m -d bash -c "service ssh restart"' sleep 2 From 4d42a202f188f03aa0dc5452a5a57756d82edc89 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 12 Jun 2024 21:26:32 -0500 Subject: [PATCH 65/99] fix: prevent the deletion of the RemoteForward when update other attributes --- src/utils/callUpdate.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/utils/callUpdate.sh b/src/utils/callUpdate.sh index df0574bc..6285a971 100644 --- a/src/utils/callUpdate.sh +++ b/src/utils/callUpdate.sh @@ -19,6 +19,7 @@ function update(){ declare "$key=$value" done <<< "$ssh_config" + RemoteForward=$(extractBlocks "$RemoteForward") case "$newKey" in "HostName") HostName=$newValue @@ -49,9 +50,7 @@ function update(){ if [[ -n "$4" ]]; then newValue=$4 fi - allArgument=$(extractBlocks "$RemoteForward") - RemoteForward=$(replaceFirstOccurrence "$allArgument" "$currentValue" "$newValue") - + RemoteForward=$(replaceFirstOccurrence "$RemoteForward" "$currentValue" "$newValue") ;; *) echo "Invalid key." From d9430c7970616a91aa09cbbf1b03d530c5a684be Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 12 Jun 2024 21:38:32 -0500 Subject: [PATCH 66/99] fix: Rename functions to avoid name collision Changed the names of functions that had identical names in different files to avoid name collisions and ensure unique identifiers across the codebase. This update improves code maintainability and reduces the risk of unintended behavior due to function name conflicts. --- main.sh | 4 ++-- src/aws/driver.sh | 2 +- src/aws/load.sh | 12 ++++++++++++ src/utils/callUpdate.sh | 2 +- src/utils/driver.sh | 4 ++-- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/main.sh b/main.sh index 8f3a88e6..8d6fc313 100644 --- a/main.sh +++ b/main.sh @@ -19,11 +19,11 @@ fi case "$1" in aws) source $manageConfigPath/src/aws/load.sh - driver "${@:2}" + awsDriver "${@:2}" ;; sshConfigManager) source $manageConfigPath/src/utils/load.sh - driver "${@:2}" + configDriver "${@:2}" ;; *) echo "Error: Invalid command." diff --git a/src/aws/driver.sh b/src/aws/driver.sh index 25d2a134..d3ef119a 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -9,7 +9,7 @@ awsUsage() { exit 1 } -function driver() { +function awsDriver() { # Check if at least one argument is provided if [ $# -eq 0 ]; then diff --git a/src/aws/load.sh b/src/aws/load.sh index 9d811bb2..ecea5956 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -12,6 +12,18 @@ source $manageConfigPath/src/aws/dependencies/sshtunnelFunction.sh source $manageConfigPath/src/aws/dependencies/reverseShell.sh source $manageConfigPath/src/aws/dependencies/updateOrAppend.sh +source $manageConfigPath/src/utils/dependencies/config.sh +source $manageConfigPath/src/utils/dependencies/array.sh +source $manageConfigPath/src/utils/dependencies/read.sh +source $manageConfigPath/src/utils/dependencies/replace.sh +source $manageConfigPath/src/utils/dependencies/retrieve.sh + +source $manageConfigPath/src/utils/create.sh +source $manageConfigPath/src/utils/update.sh +source $manageConfigPath/src/utils/delete.sh +source $manageConfigPath/src/utils/callUpdate.sh +source $manageConfigPath/src/utils/driver.sh + source $manageConfigPath/src/aws/init.sh source $manageConfigPath/src/aws/delete.sh source $manageConfigPath/src/aws/stop.sh diff --git a/src/utils/callUpdate.sh b/src/utils/callUpdate.sh index 6285a971..0494cd58 100644 --- a/src/utils/callUpdate.sh +++ b/src/utils/callUpdate.sh @@ -1,6 +1,6 @@ #!/bin/bash -function update(){ +function updateSshConfigInterface(){ local host=$1 local newKey=$2 local newValue=$3 diff --git a/src/utils/driver.sh b/src/utils/driver.sh index ea70c59f..8cd963a7 100644 --- a/src/utils/driver.sh +++ b/src/utils/driver.sh @@ -15,7 +15,7 @@ function sshConfigManagerUsage() { echo " -h, --help Show help information" } -function driver() { +function configDriver() { # Check if at least one argument is provided if [ $# -eq 0 ]; then @@ -28,7 +28,7 @@ function driver() { createSshConfig "${@:2}" ;; update) - update "${@:2}" + updateSshConfigInterface "${@:2}" ;; delete) deleteSshConfig "${@:2}" From 4d6d6a92d1ef971618e9d3e9902117263ca79128 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Thu, 13 Jun 2024 04:03:57 +0100 Subject: [PATCH 67/99] feat: edit actual config --- main.sh | 0 src/utils/dependencies/config.sh | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 main.sh diff --git a/main.sh b/main.sh old mode 100644 new mode 100755 diff --git a/src/utils/dependencies/config.sh b/src/utils/dependencies/config.sh index 937ab62d..df85a563 100644 --- a/src/utils/dependencies/config.sh +++ b/src/utils/dependencies/config.sh @@ -1,2 +1,2 @@ -#CONFIG=~/.ssh/config -CONFIG=~/Projects/luftballon/config # Test \ No newline at end of file +CONFIG=~/.ssh/config +#CONFIG=~/Projects/luftballon/config # Test From 1e8f675d22b5a7b1189a075e611605981c3dc44e Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 12 Jun 2024 22:23:04 -0500 Subject: [PATCH 68/99] feat: test call configDriver.sh --- src/aws/callUtils.sh | 4 ++++ src/aws/driver.sh | 3 +++ src/aws/load.sh | 1 + src/utils/dependencies/config.sh | 4 ++-- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/aws/callUtils.sh diff --git a/src/aws/callUtils.sh b/src/aws/callUtils.sh new file mode 100644 index 00000000..7fa66b6e --- /dev/null +++ b/src/aws/callUtils.sh @@ -0,0 +1,4 @@ + +function testConfigDriver() { + configDriver "myserver" "example.com" "user" "22" "~/.ssh/id_rsa" "8888:80,9999:443" +} \ No newline at end of file diff --git a/src/aws/driver.sh b/src/aws/driver.sh index d3ef119a..e26e3a53 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -33,6 +33,9 @@ function awsDriver() { install) installAwsCli "${@:2}" ;; + test) + testConfigDriver + ;; *) echo "Error: Invalid command." awsUsage diff --git a/src/aws/load.sh b/src/aws/load.sh index ecea5956..5d155746 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -29,5 +29,6 @@ source $manageConfigPath/src/aws/delete.sh source $manageConfigPath/src/aws/stop.sh source $manageConfigPath/src/aws/restart.sh source $manageConfigPath/src/aws/installAwsCli.sh +source $manageConfigPath/src/aws/callUtils.sh source $manageConfigPath/src/aws/driver.sh diff --git a/src/utils/dependencies/config.sh b/src/utils/dependencies/config.sh index df85a563..892cb196 100644 --- a/src/utils/dependencies/config.sh +++ b/src/utils/dependencies/config.sh @@ -1,2 +1,2 @@ -CONFIG=~/.ssh/config -#CONFIG=~/Projects/luftballon/config # Test +#CONFIG=~/.ssh/config +CONFIG=~/Projects/luftballon/config # Test From e016f6ebdd524ec326cdef3d9b071eec6298bce5 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 19 Jun 2024 21:19:21 -0500 Subject: [PATCH 69/99] open ssh tunnel from ssh/config --- src/aws/dependencies/reverseShell.sh | 6 ++++-- src/aws/driver.sh | 2 +- src/aws/init.sh | 3 +-- src/aws/restart.sh | 1 - src/utils/dependencies/config.sh | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index 8eaeb408..a0714d78 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -72,9 +72,11 @@ function openSSHTunnel(){ ssh -i /root/.ssh/$sshkey root@$instanceIp 'screen -m -d bash -c "service ssh restart"' sleep 2 - treehouses sshtunnel add host "$monitorPort" root@"$instanceIp" + #treehouses sshtunnel add host "$monitorPort" root@"$instanceIp" #deleteUnusedSShtunnel $instanceIp $sshtunnelPortArray - openNonDefaultSShtunnel $instanceIp $sshtunnelPortArray + #openNonDefaultSShtunnel $instanceIp $sshtunnelPortArray + createSshConfig "myserver" $instanceIp "user" "22" "~/.ssh/id_rsa" "8888:80,9999:443" + autossh -f -T -N -q -4 -M 2200 myserver echo "Below sshtunnels are configured" treehouses sshtunnel ports diff --git a/src/aws/driver.sh b/src/aws/driver.sh index e26e3a53..b3c34077 100755 --- a/src/aws/driver.sh +++ b/src/aws/driver.sh @@ -34,7 +34,7 @@ function awsDriver() { installAwsCli "${@:2}" ;; test) - testConfigDriver + testConfigDriver "${@:2}" ;; *) echo "Error: Invalid command." diff --git a/src/aws/init.sh b/src/aws/init.sh index 084bddc6..fc609d99 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -188,8 +188,7 @@ function init { isOpen=$(waitForOutput "ssh-keyscan -H $publicIp | grep ecdsa-sha2-nistp256") echo "Opened ssh tunnel" - updateOrAppend $instanceName $publicIp - openSSHTunnel $instanceName $portConfigArray + openSSHTunnel $publicIp $portConfigArray storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName } diff --git a/src/aws/restart.sh b/src/aws/restart.sh index 3ecde38d..a9f04b27 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -30,5 +30,4 @@ function restart(){ echo "the new ip address is $publicIp" updateIPAddress $balloonName $publicIp - updateOrAppend $instanceName $publicIp } \ No newline at end of file diff --git a/src/utils/dependencies/config.sh b/src/utils/dependencies/config.sh index 892cb196..df85a563 100644 --- a/src/utils/dependencies/config.sh +++ b/src/utils/dependencies/config.sh @@ -1,2 +1,2 @@ -#CONFIG=~/.ssh/config -CONFIG=~/Projects/luftballon/config # Test +CONFIG=~/.ssh/config +#CONFIG=~/Projects/luftballon/config # Test From a6e05e88b5c613cf95447dc0fd904d7a95d8f008 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 19 Jun 2024 21:54:18 -0500 Subject: [PATCH 70/99] add ssh port and change the user name from user to root --- src/aws/dependencies/reverseShell.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index a0714d78..9b34f969 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -75,10 +75,8 @@ function openSSHTunnel(){ #treehouses sshtunnel add host "$monitorPort" root@"$instanceIp" #deleteUnusedSShtunnel $instanceIp $sshtunnelPortArray #openNonDefaultSShtunnel $instanceIp $sshtunnelPortArray - createSshConfig "myserver" $instanceIp "user" "22" "~/.ssh/id_rsa" "8888:80,9999:443" + createSshConfig "myserver" $instanceIp "root" "22" "~/.ssh/id_rsa" "8888:80,9999:443,2222:22" autossh -f -T -N -q -4 -M 2200 myserver - echo "Below sshtunnels are configured" - treehouses sshtunnel ports } From 0fe0ae22814b9e99a7449ce4b78e73ec47301349 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 19 Jun 2024 22:03:08 -0500 Subject: [PATCH 71/99] delete configuration --- src/aws/delete.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aws/delete.sh b/src/aws/delete.sh index 84aee785..040c27a0 100755 --- a/src/aws/delete.sh +++ b/src/aws/delete.sh @@ -54,6 +54,7 @@ function delete(){ fi done + deleteSshConfig myserver deleteObsoleteKeyValue $balloonName } From d86a52b8d2667d8edd80dd5e6b6b814a7e9ad98c Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 21 Jun 2024 22:32:58 -0500 Subject: [PATCH 72/99] Refactor to use .ssh/config and update port handling - Modified code to utilize .ssh/config for SSH configurations instead of the treehouses sshtunnel command. - Defined portArray as a string rather than an array. - Created default port pairs for the reverse SSH tunnel. - Implemented a function to convert the new portArray format ([port1]:[port2],[port3]:[port4]...) into an array of port numbers. - Updated the code to use the new portArray and instance name to create specific configurations in .ssh/config. --- src/aws/dependencies/reverseShell.sh | 56 +++--------------------- src/aws/dependencies/utilitiyFunction.sh | 16 +++++++ src/aws/init.sh | 15 ++----- 3 files changed, 25 insertions(+), 62 deletions(-) diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index 9b34f969..fe908fd1 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -9,53 +9,18 @@ sshkey=`treehouses sshtunnel key name | cut -d ' ' -f 5` #luftballonHostPort=2222 #serverPort=22 -function openNonDefaultSShtunnel(){ - local instanceIp=$1 - local configuredSshTunnelPortArray=("$2") - local defaultSshtunnelPortArray=($(getSshtunnelConfiguration | sed 's/\n//g'| sed 's/ /,/g' )) - - for _sshtunnelPortSet in "${configuredSshTunnelPortArray[@]}"; do - if [ -z $(echo "$_sshtunnelPortSet" | grep "$defaultSshtunnelPortArray") ] - then - local sshtunnelPortSet=($(echo $_sshtunnelPortSet | sed 's/:/ /')) - local luftballonHosPport=${sshtunnelPortSet[0]} - local serverPort=${sshtunnelPortSet[1]} - treehouses sshtunnel add port actual "$serverPort" "$luftballonHosPport" root@"$instanceIp" - fi - done -} - - -function deleteUnusedSShtunnel(){ - local instanceIp=$1 - local configuredSshTunnelPortArray="$2" - local defaultSshtunnelPortArray=($(getSshtunnelConfiguration | sed 's/\n//g'| sed 's/ /,/g' )) - - for _sshtunnelPortSet in "${defaultSshtunnelPortArray[@]}"; do - if [ -z $(echo "$configuredSshTunnelPortArray" | grep "$_sshtunnelPortSet") ] - then - local sshtunnelPortSet=($(echo $_sshtunnelPortSet | sed 's/:/ /')) - local luftballonHostPort=${sshtunnelPortSet[0]} - treehouses sshtunnel remove port $luftballonHostPort root@"$instanceIp" - fi - done -} - - function addKeyFingerprintToKnownHost(){ local instanceIp=$1 ssh-keyscan -H $instanceIp | grep ecdsa-sha2-nistp256 >> /home/pi/.ssh/known_hosts } function openSSHTunnel(){ - local instanceIp=$1 - local serverPort=$2 - local luftballonHostPort=$3 - local monitorPort=$4 - local sshtunnelPortArray=$luftballonHostPort:$serverPort + local instanceName=$1 + local instanceIp=$2 + local sshtunnelPortArray=$3 + local monitorPort=2200 addKeyFingerprintToKnownHost $instanceIp - addKeyFingerprintToKnownHost luftballon treehouses sshtunnel key name $sshkey sleep 2 @@ -65,18 +30,9 @@ function openSSHTunnel(){ ssh -i /root/.ssh/$sshkey root@$instanceIp 'echo "GatewayPorts yes" >> /etc/ssh/sshd_config' sleep 2 - # Restart SSH service on the remote machine in a detached screen session - # Use `screen` to run the command in the background, - # ensuring it completes even if the SSH connection is lost. - # This is necessary to apply the changes made to the SSH configuration. ssh -i /root/.ssh/$sshkey root@$instanceIp 'screen -m -d bash -c "service ssh restart"' sleep 2 - #treehouses sshtunnel add host "$monitorPort" root@"$instanceIp" - #deleteUnusedSShtunnel $instanceIp $sshtunnelPortArray - #openNonDefaultSShtunnel $instanceIp $sshtunnelPortArray - createSshConfig "myserver" $instanceIp "root" "22" "~/.ssh/id_rsa" "8888:80,9999:443,2222:22" - autossh -f -T -N -q -4 -M 2200 myserver - - + createSshConfig $instanceName $instanceIp "root" "22" "~/.ssh/id_rsa" $sshtunnelPortArray + autossh -f -T -N -q -4 -M $monitorPort $instanceName } diff --git a/src/aws/dependencies/utilitiyFunction.sh b/src/aws/dependencies/utilitiyFunction.sh index 518751f2..81cf8b62 100644 --- a/src/aws/dependencies/utilitiyFunction.sh +++ b/src/aws/dependencies/utilitiyFunction.sh @@ -26,4 +26,20 @@ setBalloonName() { else echo "$1" fi +} + +function makePortArray { + local portString="$1" + local -a portArray + + IFS=',' read -ra pairs <<< "$portString" + + for pair in "${pairs[@]}"; do + IFS=':' read -ra ports <<< "$pair" + for port in "${ports[@]}"; do + portArray+=("$port") + done + done + + echo "${portArray[@]}" } \ No newline at end of file diff --git a/src/aws/init.sh b/src/aws/init.sh index fc609d99..15f95ecb 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -40,15 +40,6 @@ function addUDPPort() { --cidr 0.0.0.0/0 } -function getNewPortinterval { - local portinterval=$1 - local portint_offset=0 - while grep -qs -e "M $((portinterval - 1))" -e "M $portinterval" -e "M $((portinterval + 1))" /etc/tunnel; do - portinterval=$((portinterval + 1)) - portint_offset=$((portint_offset + 1)) - done - echo $portinterval -} function createSecurityGroups(){ aws ec2 create-security-group \ @@ -57,10 +48,10 @@ function createSecurityGroups(){ if [ -z "$portConfigArray" ] then - portConfigArray="22 2222 $(getNewPortinterval 2200)" + portConfigArray="8080:80,8443:443,2022:22" fi - portArray=($portConfigArray) + portArray=($(makePortArray "$portString1")) for i in "${portArray[@]}" do @@ -188,7 +179,7 @@ function init { isOpen=$(waitForOutput "ssh-keyscan -H $publicIp | grep ecdsa-sha2-nistp256") echo "Opened ssh tunnel" - openSSHTunnel $publicIp $portConfigArray + openSSHTunnel $instanceName $publicIp $portConfigArray storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName } From 9b8b5845aecbc3511611fef5ac37b3c768b3ac39 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 21 Jun 2024 22:34:59 -0500 Subject: [PATCH 73/99] delete a specific configuration in the .ssh/config --- src/aws/delete.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/delete.sh b/src/aws/delete.sh index 040c27a0..27bccbc9 100755 --- a/src/aws/delete.sh +++ b/src/aws/delete.sh @@ -54,7 +54,7 @@ function delete(){ fi done - deleteSshConfig myserver + deleteSshConfig $balloonName deleteObsoleteKeyValue $balloonName } From 15d5cf8f0b72b29e4ad83ef63284d1c975a1dbc6 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 21 Jun 2024 22:53:22 -0500 Subject: [PATCH 74/99] fix the bug --- src/aws/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/init.sh b/src/aws/init.sh index 15f95ecb..5802f80f 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -51,7 +51,7 @@ function createSecurityGroups(){ portConfigArray="8080:80,8443:443,2022:22" fi - portArray=($(makePortArray "$portString1")) + portArray=($(makePortArray "$portConfigArray")) for i in "${portArray[@]}" do From 3b074d2d43b21f10ca206a51291698777c97e82b Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 26 Jun 2024 22:32:28 -0500 Subject: [PATCH 75/99] feat: restart ssh tunnel --- src/aws/dependencies/getProcessNumber.sh | 23 ++++++++++++++++++++ src/aws/dependencies/reverseShell.sh | 14 ++++++++++++ src/aws/load.sh | 1 + src/aws/restart.sh | 3 +++ allTest.sh => tests/allTest.sh | 2 -- tests/load.sh | 7 ++++++ tests/testGetProcessNumber.sh | 27 ++++++++++++++++++++++++ 7 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/aws/dependencies/getProcessNumber.sh rename allTest.sh => tests/allTest.sh (97%) create mode 100644 tests/load.sh create mode 100644 tests/testGetProcessNumber.sh diff --git a/src/aws/dependencies/getProcessNumber.sh b/src/aws/dependencies/getProcessNumber.sh new file mode 100644 index 00000000..9b696699 --- /dev/null +++ b/src/aws/dependencies/getProcessNumber.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +getProcessNumber() { + local targetString="$1" + local processInfo="$2" + local processNumber=$( + echo "$processInfo" \ + | \ + awk -v target="$targetString" '$0 ~ /\/usr\/lib\/autossh\/autossh/ && $0 ~ target {print $2}' + ) + + if [ -n "$processNumber" ]; then + echo "$processNumber" + else + echo "" + fi +} + +getProcessInfo() { + local processInfo=$(ps aux | grep ssh) + echo "$processInfo" +} + diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index fe908fd1..ed1117cb 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -36,3 +36,17 @@ function openSSHTunnel(){ createSshConfig $instanceName $instanceIp "root" "22" "~/.ssh/id_rsa" $sshtunnelPortArray autossh -f -T -N -q -4 -M $monitorPort $instanceName } + +function closeSSHTunnel(){ + local instanceName=$1 + local processNumber=$(getProcessNumber "$instanceName" "$(getProcessInfo)") + if [ -n "$processNumber" ]; then + kill -9 $processNumber + fi +} + +function restartSSHTunnel(){ + local instanceName=$1 + local instanceIp=$2 + updateSshConfigInterface $instanceName HostName $instanceIp +} diff --git a/src/aws/load.sh b/src/aws/load.sh index 5d155746..558ac37d 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -11,6 +11,7 @@ source $manageConfigPath/src/aws/dependencies/manageConfig.sh source $manageConfigPath/src/aws/dependencies/sshtunnelFunction.sh source $manageConfigPath/src/aws/dependencies/reverseShell.sh source $manageConfigPath/src/aws/dependencies/updateOrAppend.sh +source $manageConfigPath/src/aws/dependencies/getProcessNumber.sh source $manageConfigPath/src/utils/dependencies/config.sh source $manageConfigPath/src/utils/dependencies/array.sh diff --git a/src/aws/restart.sh b/src/aws/restart.sh index a9f04b27..ad2ab616 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -30,4 +30,7 @@ function restart(){ echo "the new ip address is $publicIp" updateIPAddress $balloonName $publicIp + closeSSHTunnel + restartSSHTunnel + echo "open ssh tunnel" } \ No newline at end of file diff --git a/allTest.sh b/tests/allTest.sh similarity index 97% rename from allTest.sh rename to tests/allTest.sh index 32bf5623..9869b7fc 100644 --- a/allTest.sh +++ b/tests/allTest.sh @@ -1,5 +1,3 @@ -source array.sh -source replace.sh test_extractBlocks() { local input_string="$1" diff --git a/tests/load.sh b/tests/load.sh new file mode 100644 index 00000000..cd379391 --- /dev/null +++ b/tests/load.sh @@ -0,0 +1,7 @@ + +manageConfigPath=$(pwd) + +source $manageConfigPath/src/utils/load.sh +source $manageConfigPath/src/aws/load.sh + +source $manageConfigPath/tests/testGetProcessNumber.sh \ No newline at end of file diff --git a/tests/testGetProcessNumber.sh b/tests/testGetProcessNumber.sh new file mode 100644 index 00000000..8e6143dd --- /dev/null +++ b/tests/testGetProcessNumber.sh @@ -0,0 +1,27 @@ +testGetProcessNumber() { + local luftballon="luftballon" + + # Test case 1: Find process number + local processInfo1="root 1923245 0.0 0.0 2216 84 ? Ss 03:18 0:00 /usr/lib/autossh/autossh -T -N -q -4 -M 2200 luftballon" + local result1=$(getProcessNumber "$luftballon" "$processInfo1") + echo "Test case 1 - Process number: $result1" + + # Test case 2: No /usr/lib/autossh/autossh + local processInfo2="root 1922602 0.0 0.1 19736 10404 ? Ss 03:16 0:00 sshd: root@pts/0" + local result2=$(getProcessNumber "$luftballon" "$processInfo2") + echo "Test case 2 - Process number: $result2" + + # Test case 3: No luftballon + local processInfo3="root 1923245 0.0 0.0 2216 84 ? Ss 03:18 0:00 /usr/lib/autossh/autossh -T -N -q -4 -M 2200 not_found" + local result3=$(getProcessNumber "$luftballon" "$processInfo3") + echo "Test case 3 - Process number: $result3" + + # Test case 4: Multiple /usr/lib/autossh/autossh + local processInfo4="root 1923245 0.0 0.0 2216 84 ? Ss 03:18 0:00 /usr/lib/autossh/autossh -T -N -q -4 -M 2200 luftballon +root 1923246 0.3 0.1 14476 8072 ? S 03:18 0:00 /usr/lib/autossh/autossh -T -N -q -4 -M 2200 luftballon" + local result4=$(getProcessNumber "$luftballon" "$processInfo4") + echo "Test case 4 - Process number: $result4" + + local result5=$(getProcessNumber "$luftballon" "$(getProcessInfo)") + echo "Test case 5 - Process number: $result5" +} From 4f41c41f2297eaf7e5494c23189a2486b8130cb0 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 26 Jun 2024 22:42:16 -0500 Subject: [PATCH 76/99] start ssh tunnel --- src/aws/dependencies/reverseShell.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index ed1117cb..4f207bec 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -48,5 +48,7 @@ function closeSSHTunnel(){ function restartSSHTunnel(){ local instanceName=$1 local instanceIp=$2 + local monitorPort=2200 updateSshConfigInterface $instanceName HostName $instanceIp + autossh -f -T -N -q -4 -M $monitorPort $instanceName } From 7bae4997c470817b8e6c14dc539f799b97beff4a Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 26 Jun 2024 22:53:04 -0500 Subject: [PATCH 77/99] fix the issue --- src/aws/restart.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/restart.sh b/src/aws/restart.sh index ad2ab616..add6a915 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -31,6 +31,6 @@ function restart(){ updateIPAddress $balloonName $publicIp closeSSHTunnel - restartSSHTunnel + restartSSHTunnel $balloonName $publicIp echo "open ssh tunnel" } \ No newline at end of file From 872c4222b84d9dc21c84dcc747295327f278e6da Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 28 Jun 2024 22:54:13 -0500 Subject: [PATCH 78/99] update - kill ssh tunnel process - connect ssh before starting the ssh tunnel --- src/aws/dependencies/getProcessNumber.sh | 13 +++++++++++ src/aws/dependencies/reverseShell.sh | 22 ++++++++++++++++--- src/aws/restart.sh | 5 ++++- tests/testGetProcessNumber.sh | 28 +++++++++++++++++++++++- 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/aws/dependencies/getProcessNumber.sh b/src/aws/dependencies/getProcessNumber.sh index 9b696699..8cc91b1a 100644 --- a/src/aws/dependencies/getProcessNumber.sh +++ b/src/aws/dependencies/getProcessNumber.sh @@ -16,6 +16,19 @@ getProcessNumber() { fi } +getProcessNumberSsh() { + local targetString="$1" + local processInfo="$2" + + local processNumber=$(echo "$processInfo" | awk -v target="$targetString" '$0 ~ /\/usr\/bin\/ssh/ && $0 ~ target {print $2}') + + if [ -n "$processNumber" ]; then + echo "$processNumber" + else + echo "" + fi +} + getProcessInfo() { local processInfo=$(ps aux | grep ssh) echo "$processInfo" diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index 4f207bec..4b5b2223 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -37,18 +37,34 @@ function openSSHTunnel(){ autossh -f -T -N -q -4 -M $monitorPort $instanceName } +killProcess() { + local processNumber="$1" + + if [ -n "$processNumber" ]; then + kill -9 "$processNumber" + echo "Killed process $processNumber" + else + echo "No process to kill" + fi +} + function closeSSHTunnel(){ local instanceName=$1 local processNumber=$(getProcessNumber "$instanceName" "$(getProcessInfo)") - if [ -n "$processNumber" ]; then - kill -9 $processNumber - fi + killProcess $processNumber + processNumber=$(getProcessNumber "$instanceName" "$(getProcessNumberSsh)") + killProcess $processNumber } function restartSSHTunnel(){ local instanceName=$1 local instanceIp=$2 local monitorPort=2200 + + ssh -i /root/.ssh/$sshkey root@$instanceIp 'echo hello world' + sleep 2 + updateSshConfigInterface $instanceName HostName $instanceIp + sleep 2 autossh -f -T -N -q -4 -M $monitorPort $instanceName } diff --git a/src/aws/restart.sh b/src/aws/restart.sh index add6a915..5c83ee71 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -31,6 +31,9 @@ function restart(){ updateIPAddress $balloonName $publicIp closeSSHTunnel + echo "remove old ssh tunnel settings" + sleep 5 + restartSSHTunnel $balloonName $publicIp - echo "open ssh tunnel" + echo "open new ssh tunnel" } \ No newline at end of file diff --git a/tests/testGetProcessNumber.sh b/tests/testGetProcessNumber.sh index 8e6143dd..26d8e672 100644 --- a/tests/testGetProcessNumber.sh +++ b/tests/testGetProcessNumber.sh @@ -18,10 +18,36 @@ testGetProcessNumber() { # Test case 4: Multiple /usr/lib/autossh/autossh local processInfo4="root 1923245 0.0 0.0 2216 84 ? Ss 03:18 0:00 /usr/lib/autossh/autossh -T -N -q -4 -M 2200 luftballon -root 1923246 0.3 0.1 14476 8072 ? S 03:18 0:00 /usr/lib/autossh/autossh -T -N -q -4 -M 2200 luftballon" +root 1923246 0.3 0.1 14476 8072 ? S 03:18 0:00 /usr/lib/autossh/autossh -T -N -q -4 -M 2200 myballon" local result4=$(getProcessNumber "$luftballon" "$processInfo4") echo "Test case 4 - Process number: $result4" local result5=$(getProcessNumber "$luftballon" "$(getProcessInfo)") echo "Test case 5 - Process number: $result5" } + +testGetProcessNumberSsh() { + local luftballon="luftballon" + + local processInfo1="root 1923245 0.0 0.0 2216 84 ? Ss 03:18 0:00 /usr/bin/ssh -L 2200:127.0.0.1:2200 -R 2200:127.0.0.1:2201 -T -N -q -4 luftballon" + local result1=$(getProcessNumberSsh "$luftballon" "$processInfo1") + echo "Test case 1 - Process number: $result1" + + local processInfo2="root 1922602 0.0 0.1 19736 10404 ? Ss 03:16 0:00 sshd: root@pts/0" + local result2=$(getProcessNumberSsh "$luftballon" "$processInfo2") + echo "Test case 2 - Process number: $result2" + + local processInfo3="root 1923245 0.0 0.0 2216 84 ? Ss 03:18 0:00 /usr/bin/ssh -L 2200:127.0.0.1:2200 -R 2200:127.0.0.1:2201 -T -N -q -4 not_found" + local result3=$(getProcessNumberSsh "$luftballon" "$processInfo3") + echo "Test case 3 - Process number: $result3" + + local processInfo4="root 1923245 0.0 0.0 2216 84 ? Ss 03:18 0:00 /usr/bin/ssh -L 2200:127.0.0.1:2200 -R 2200:127.0.0.1:2201 -T -N -q -4 luftballon +root 1923246 0.3 0.1 14476 8072 ? S 03:18 0:00 /usr/bin/ssh -L 2200:127.0.0.1:2200 -R 2200:127.0.0.1:2201 -T -N -q -4 myballon" + local result4=$(getProcessNumberSsh "$luftballon" "$processInfo4") + echo "Test case 4 - Process number: $result4" + + local processInfo5="root 1923245 0.0 0.0 2216 84 ? Ss 03:18 0:00 /usr/bin/ssh -L 2200:127.0.0.1:2200 -R 2200:127.0.0.1:2201 -T -N -q -4 not_found +root 1923246 0.3 0.1 14476 8072 ? S 03:18 0:00 /usr/bin/ssh -L 2200:127.0.0.1:2200 -R 2200:127.0.0.1:2201 -T -N -q -4 another_string" + local result5=$(getProcessNumberSsh "$luftballon" "$processInfo5") + echo "Test case 5 - Process number: $result5" +} From 0d67499b9c65bd42becd6adb6e3aafd3efcdc166 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 28 Jun 2024 23:02:04 -0500 Subject: [PATCH 79/99] disable host key verification --- src/aws/dependencies/reverseShell.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index 4b5b2223..2b783c4c 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -61,7 +61,7 @@ function restartSSHTunnel(){ local instanceIp=$2 local monitorPort=2200 - ssh -i /root/.ssh/$sshkey root@$instanceIp 'echo hello world' + ssh -i /root/.ssh/$sshkey -o StrictHostKeyChecking=no root@$instanceIp 'echo hello world' sleep 2 updateSshConfigInterface $instanceName HostName $instanceIp From 2c90cb460efa6b8534d969646a185cb0949dd893 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 28 Jun 2024 23:34:30 -0500 Subject: [PATCH 80/99] add comments --- src/aws/dependencies/reverseShell.sh | 34 +++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index 2b783c4c..32311659 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -9,11 +9,29 @@ sshkey=`treehouses sshtunnel key name | cut -d ' ' -f 5` #luftballonHostPort=2222 #serverPort=22 +# Fetches the SSH host key of the remote server and adds it to known_hosts +# to prevent SSH from asking for confirmation during automated connections function addKeyFingerprintToKnownHost(){ local instanceIp=$1 ssh-keyscan -H $instanceIp | grep ecdsa-sha2-nistp256 >> /home/pi/.ssh/known_hosts } +function establishPersistenceSSHTunnel(){ + local monitorPort=$1 + local instanceName=$2 + + # autossh command breakdown: + # -f: Run in the background before executing the command. + # -T: Disable pseudo-tty allocation. + # -N: Do not execute remote commands. + # -q: Enable quiet mode, suppresses most warning and diagnostic messages. + # -4: Use IPv4 addresses only. + # -M $monitorPort: Set up the monitoring port for autossh to keep the connection alive. + # $instanceName: The hostname or IP address of the remote server. + + autossh -f -T -N -q -4 -M $monitorPort $instanceName +} + function openSSHTunnel(){ local instanceName=$1 local instanceIp=$2 @@ -56,15 +74,25 @@ function closeSSHTunnel(){ killProcess $processNumber } +# This step is necessary because the client, being behind a firewall or NAT, +# may not be directly accessible from outside its network. +# By connecting to the remote server, the client creates a pathway +# through which connections can be routed. +function establishSSHConnectionBeforeEstablishSSHTunnel(){ + local instanceIp=$1 + ssh -i /root/.ssh/$sshkey -o StrictHostKeyChecking=no root@$instanceIp 'echo hello world' + sleep 2 +} + function restartSSHTunnel(){ local instanceName=$1 local instanceIp=$2 local monitorPort=2200 - ssh -i /root/.ssh/$sshkey -o StrictHostKeyChecking=no root@$instanceIp 'echo hello world' - sleep 2 + addKeyFingerprintToKnownHost $instanceIp + establishSSHConnectionBeforeEstablishSSHTunnel $instanceIp updateSshConfigInterface $instanceName HostName $instanceIp sleep 2 - autossh -f -T -N -q -4 -M $monitorPort $instanceName + establishPersistenceSSHTunnel $monitorPort $instanceName } From 26a4a84ff35cc231fa2aff9af7d644b72923177d Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 10 Jul 2024 22:05:48 -0500 Subject: [PATCH 81/99] small bug fixes --- archive/jsonController.sh | 2 +- src/aws/dependencies/jsonOperations.sh | 2 +- src/aws/dependencies/reverseShell.sh | 2 +- src/aws/init.sh | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/archive/jsonController.sh b/archive/jsonController.sh index 2e5660da..ee990b2e 100644 --- a/archive/jsonController.sh +++ b/archive/jsonController.sh @@ -138,7 +138,7 @@ function getBucketByBucketKey(){ function stringfy(){ local data="$1" - local string=$(echo "$data" | jq '.|tostring' |tr -d '\' | sed 's/"{/{/' | sed 's/}"/}/' ) + local string=$(echo "$data" | jq '.|tostring' |tr -d '\' | sed 's/"{/{/' | sed 's/}"/}/' 2>/dev/null) echo $string } diff --git a/src/aws/dependencies/jsonOperations.sh b/src/aws/dependencies/jsonOperations.sh index b9d658fd..ec7c06af 100644 --- a/src/aws/dependencies/jsonOperations.sh +++ b/src/aws/dependencies/jsonOperations.sh @@ -109,7 +109,7 @@ function merge(){ function stringfy(){ local data="$1" - local string=$(echo "$data" | jq '.|tostring' |tr -d '\' | sed 's/"{/{/' | sed 's/}"/}/' ) + local string=$(echo "$data" | jq '.|tostring' |tr -d '\' | sed 's/"{/{/' | sed 's/}"/}/' 2>/dev/null) echo $string } diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index 32311659..471626c4 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -80,7 +80,7 @@ function closeSSHTunnel(){ # through which connections can be routed. function establishSSHConnectionBeforeEstablishSSHTunnel(){ local instanceIp=$1 - ssh -i /root/.ssh/$sshkey -o StrictHostKeyChecking=no root@$instanceIp 'echo hello world' + ssh -i /root/.ssh/$sshkey -o StrictHostKeyChecking=no root@$instanceIp sleep 2 } diff --git a/src/aws/init.sh b/src/aws/init.sh index 5802f80f..9b04608b 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -82,7 +82,6 @@ function createEc2(){ --instance-type t2.micro \ --key-name $keyname \ --security-groups $groupName - --user-data file://./setupIpTables.txt } function findData(){ From cbc46f15f13081216198e63f7f480d59d330f3f8 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 10 Jul 2024 22:18:11 -0500 Subject: [PATCH 82/99] bug fixes --- archive/jsonController.sh | 2 +- src/aws/dependencies/jsonOperations.sh | 2 +- src/aws/dependencies/reverseShell.sh | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/archive/jsonController.sh b/archive/jsonController.sh index ee990b2e..6d046ee3 100644 --- a/archive/jsonController.sh +++ b/archive/jsonController.sh @@ -138,7 +138,7 @@ function getBucketByBucketKey(){ function stringfy(){ local data="$1" - local string=$(echo "$data" | jq '.|tostring' |tr -d '\' | sed 's/"{/{/' | sed 's/}"/}/' 2>/dev/null) + local string=$(echo "$data" | jq '.|tostring' |tr -d '\' 2>/dev/null | sed 's/"{/{/' | sed 's/}"/}/') echo $string } diff --git a/src/aws/dependencies/jsonOperations.sh b/src/aws/dependencies/jsonOperations.sh index ec7c06af..0d869f3e 100644 --- a/src/aws/dependencies/jsonOperations.sh +++ b/src/aws/dependencies/jsonOperations.sh @@ -109,7 +109,7 @@ function merge(){ function stringfy(){ local data="$1" - local string=$(echo "$data" | jq '.|tostring' |tr -d '\' | sed 's/"{/{/' | sed 's/}"/}/' 2>/dev/null) + local string=$(echo "$data" | jq '.|tostring' |tr -d '\' 2>/dev/null | sed 's/"{/{/' | sed 's/}"/}/') echo $string } diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index 471626c4..e0d97b37 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -81,6 +81,7 @@ function closeSSHTunnel(){ function establishSSHConnectionBeforeEstablishSSHTunnel(){ local instanceIp=$1 ssh -i /root/.ssh/$sshkey -o StrictHostKeyChecking=no root@$instanceIp + echo "Established SSH connection to $instanceIp" sleep 2 } From 72d6f444dee78616afef9b02d657dce0a631bc8d Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Wed, 10 Jul 2024 22:33:14 -0500 Subject: [PATCH 83/99] bug fix --- src/aws/dependencies/reverseShell.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/aws/dependencies/reverseShell.sh b/src/aws/dependencies/reverseShell.sh index e0d97b37..762eb70b 100755 --- a/src/aws/dependencies/reverseShell.sh +++ b/src/aws/dependencies/reverseShell.sh @@ -80,8 +80,7 @@ function closeSSHTunnel(){ # through which connections can be routed. function establishSSHConnectionBeforeEstablishSSHTunnel(){ local instanceIp=$1 - ssh -i /root/.ssh/$sshkey -o StrictHostKeyChecking=no root@$instanceIp - echo "Established SSH connection to $instanceIp" + ssh -i /root/.ssh/$sshkey -o StrictHostKeyChecking=no root@$instanceIp 'echo A new IP address is acquired' sleep 2 } From 784d2ca75621cde8c70ea248c2befc40e06d6ca0 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:48:00 -0400 Subject: [PATCH 84/99] Delete config.txt --- config.txt | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 config.txt diff --git a/config.txt b/config.txt deleted file mode 100644 index 36918230..00000000 --- a/config.txt +++ /dev/null @@ -1,22 +0,0 @@ - -Host remoteserver - HostName newremoteserver.com - User newremoteuser - Port newremoteport - IdentityFile /new/path/to/remote/server/private/key - RemoteForward 2223 localhost:80 - ServerAliveInterval 30 - ServerAliveCountMax 3 - ExitOnForwardFailure yes - TCPKeepAlive yes - -Host remoteserver1 - HostName newremoteserver.com - User newremoteuser - Port newremoteport - IdentityFile /new/path/to/remote/server/private/key - RemoteForward 2223 localhost:80 - ServerAliveInterval 30 - ServerAliveCountMax 3 - ExitOnForwardFailure yes - TCPKeepAlive yes From 732516ed6fc08b0adacc6aa0b1d63e8841da4519 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:50:34 -0400 Subject: [PATCH 85/99] Update replace.sh --- src/utils/dependencies/replace.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/dependencies/replace.sh b/src/utils/dependencies/replace.sh index 8091a974..32cc314e 100644 --- a/src/utils/dependencies/replace.sh +++ b/src/utils/dependencies/replace.sh @@ -8,4 +8,4 @@ replaceFirstOccurrence() { fi echo "$all" -} \ No newline at end of file +} From 8f442c0802bcecf3f69ca60ba6895e9d5b1a1004 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:51:05 -0400 Subject: [PATCH 86/99] Update driver.sh --- src/utils/driver.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/driver.sh b/src/utils/driver.sh index 8cd963a7..be140b6e 100644 --- a/src/utils/driver.sh +++ b/src/utils/driver.sh @@ -39,4 +39,4 @@ function configDriver() { ;; esac -} \ No newline at end of file +} From d5c1baed138df95640d922b09917c6d1afde5c86 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:51:36 -0400 Subject: [PATCH 87/99] Update allTest.sh --- tests/allTest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/allTest.sh b/tests/allTest.sh index 9869b7fc..68670135 100644 --- a/tests/allTest.sh +++ b/tests/allTest.sh @@ -34,4 +34,4 @@ test_replaceFirstOccurrence "8888:80,9999:443" "9999:443" "9998:442" "8888:80,99 test_replaceFirstOccurrence "8888:80,9999:443" "7777:77" "7776:76" "8888:80,9999:443" test_replaceFirstOccurrence "8888:80,8888:80" "8888:80" "8887:81" "8887:81,8888:80" test_replaceFirstOccurrence "" "8888:80" "8887:81" "" -echo "Tests completed." \ No newline at end of file +echo "Tests completed." From ccf85cd932b3a1cbae17a252077cb7db40fa6a75 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:51:59 -0400 Subject: [PATCH 88/99] Update load.sh --- tests/load.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/load.sh b/tests/load.sh index cd379391..aa958df3 100644 --- a/tests/load.sh +++ b/tests/load.sh @@ -4,4 +4,4 @@ manageConfigPath=$(pwd) source $manageConfigPath/src/utils/load.sh source $manageConfigPath/src/aws/load.sh -source $manageConfigPath/tests/testGetProcessNumber.sh \ No newline at end of file +source $manageConfigPath/tests/testGetProcessNumber.sh From 4d58079e1de49ce9184062c9e6c68fa477178f90 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:52:31 -0400 Subject: [PATCH 89/99] Update callUpdate.sh --- src/utils/callUpdate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/callUpdate.sh b/src/utils/callUpdate.sh index 0494cd58..5cdc1b88 100644 --- a/src/utils/callUpdate.sh +++ b/src/utils/callUpdate.sh @@ -63,4 +63,4 @@ function updateSshConfigInterface(){ } -#update $host "RemoteForward" "8888:80" "8887:81" \ No newline at end of file +#update $host "RemoteForward" "8888:80" "8887:81" From 397e14356a698914511aa2ca65a734e02fd65279 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:53:11 -0400 Subject: [PATCH 90/99] Update stop.sh --- src/aws/stop.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/stop.sh b/src/aws/stop.sh index 2d92a24b..96ca37ac 100644 --- a/src/aws/stop.sh +++ b/src/aws/stop.sh @@ -26,4 +26,4 @@ function stop(){ aws ec2 stop-instances --instance-ids $instanceId -} \ No newline at end of file +} From 8dc801a4625e8dc9059699a8494cc62f383cc690 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:53:32 -0400 Subject: [PATCH 91/99] Update restart.sh --- src/aws/restart.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/restart.sh b/src/aws/restart.sh index 5c83ee71..10f3afd5 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -36,4 +36,4 @@ function restart(){ restartSSHTunnel $balloonName $publicIp echo "open new ssh tunnel" -} \ No newline at end of file +} From 20cd6b93479f965a55f792884f7415158f27759c Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:53:58 -0400 Subject: [PATCH 92/99] Update load.sh --- src/aws/load.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/aws/load.sh b/src/aws/load.sh index 558ac37d..ed3e2bc3 100644 --- a/src/aws/load.sh +++ b/src/aws/load.sh @@ -32,4 +32,3 @@ source $manageConfigPath/src/aws/restart.sh source $manageConfigPath/src/aws/installAwsCli.sh source $manageConfigPath/src/aws/callUtils.sh source $manageConfigPath/src/aws/driver.sh - From a47a0c4db97016dc82fb71aa860d10e4dd997b86 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:54:21 -0400 Subject: [PATCH 93/99] Update installAwsCli.sh --- src/aws/installAwsCli.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/aws/installAwsCli.sh b/src/aws/installAwsCli.sh index 97fe44a2..909f208b 100755 --- a/src/aws/installAwsCli.sh +++ b/src/aws/installAwsCli.sh @@ -4,4 +4,3 @@ function installAwsCli(){ apt update; apt install awscli } - From 8f76c9fccc58c878b4f35619d0ed78a7ee67d0c2 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:54:48 -0400 Subject: [PATCH 94/99] Update init.sh --- src/aws/init.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/aws/init.sh b/src/aws/init.sh index 9b04608b..f6bb3f00 100644 --- a/src/aws/init.sh +++ b/src/aws/init.sh @@ -182,5 +182,3 @@ function init { storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName } - - From a8c45311c78cfda4b70353f92eedff9ad07dc7ea Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:55:10 -0400 Subject: [PATCH 95/99] Update utilitiyFunction.sh --- src/aws/dependencies/utilitiyFunction.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aws/dependencies/utilitiyFunction.sh b/src/aws/dependencies/utilitiyFunction.sh index 81cf8b62..702f4a77 100644 --- a/src/aws/dependencies/utilitiyFunction.sh +++ b/src/aws/dependencies/utilitiyFunction.sh @@ -42,4 +42,4 @@ function makePortArray { done echo "${portArray[@]}" -} \ No newline at end of file +} From 2b9a23f10895a115bb3b653b023a0dfc6e87a029 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:55:49 -0400 Subject: [PATCH 96/99] Update jsonOperations.sh --- src/aws/dependencies/jsonOperations.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/aws/dependencies/jsonOperations.sh b/src/aws/dependencies/jsonOperations.sh index 0d869f3e..9791cdef 100644 --- a/src/aws/dependencies/jsonOperations.sh +++ b/src/aws/dependencies/jsonOperations.sh @@ -1,4 +1,3 @@ - function addKeyValue(){ local input="$1" local name="$2" @@ -145,4 +144,3 @@ function getBucketByBucketKey(){ local theBucketWithKey=$(makeBucket "$emptyBucket" "$key" "$theBucket" ) echo "$theBucketWithKey" } - From 1d628dcaadeff35dc526299caba5b1c8620b7bb7 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:56:14 -0400 Subject: [PATCH 97/99] Update getProcessNumber.sh --- src/aws/dependencies/getProcessNumber.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/aws/dependencies/getProcessNumber.sh b/src/aws/dependencies/getProcessNumber.sh index 8cc91b1a..b5a4fc87 100644 --- a/src/aws/dependencies/getProcessNumber.sh +++ b/src/aws/dependencies/getProcessNumber.sh @@ -33,4 +33,3 @@ getProcessInfo() { local processInfo=$(ps aux | grep ssh) echo "$processInfo" } - From 4c8d5f83e21565c546fd895e92947b634899fb26 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:56:45 -0400 Subject: [PATCH 98/99] Update configOperations.sh From 7c0ac2a475c6a02c5f912e364f2e9e3acf781c08 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 10 Jul 2024 23:57:23 -0400 Subject: [PATCH 99/99] Update callUtils.sh --- src/aws/callUtils.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/aws/callUtils.sh b/src/aws/callUtils.sh index 7fa66b6e..eecfe5fb 100644 --- a/src/aws/callUtils.sh +++ b/src/aws/callUtils.sh @@ -1,4 +1,3 @@ - function testConfigDriver() { configDriver "myserver" "example.com" "user" "22" "~/.ssh/id_rsa" "8888:80,9999:443" -} \ No newline at end of file +}