Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add small functions #47

Merged
merged 105 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
77eabb8
store all scripts related to AWS in the AWS directory
hiroTochigi Jan 13, 2024
070b215
send argument
hiroTochigi Jan 18, 2024
2368ff9
execute command
hiroTochigi Jan 18, 2024
087eb3b
Refactor delete.sh into a function and integrate into driver.sh
hiroTochigi Jan 18, 2024
cbefbfb
add source declaration for delete.sh in driver.sh
hiroTochigi Jan 18, 2024
49ce51e
add test command to driver.sh for storeConfigIntoTreehousesConfigAsSt…
hiroTochigi Jan 18, 2024
7825fb0
add call to test function callStoreConfigIntoTreehousesConfigAsString…
hiroTochigi Jan 18, 2024
5bf9396
debug
hiroTochigi Jan 18, 2024
218e649
Merge branch 'add-driver-aws' of github.com:treehouses/luftballon int…
hiroTochigi Jan 18, 2024
95c785a
debug delete.sh
hiroTochigi Jan 20, 2024
2c76cdb
Merge branch 'add-driver-aws' of github.com:treehouses/luftballon int…
hiroTochigi Jan 20, 2024
066d4b6
debug getValueByAttribute
hiroTochigi Jan 20, 2024
a300594
Merge branch 'add-driver-aws' of github.com:treehouses/luftballon int…
hiroTochigi Jan 20, 2024
79f0053
debug getValueByAttribute
hiroTochigi Jan 20, 2024
e65da93
Merge branch 'add-driver-aws' of github.com:treehouses/luftballon int…
hiroTochigi Jan 20, 2024
b0621da
debug getValueByAttribute
hiroTochigi Jan 20, 2024
b0c2503
debug getValueByAttribute
hiroTochigi Jan 20, 2024
22e1c1e
debuf
hiroTochigi Jan 20, 2024
0d02df8
debug
hiroTochigi Jan 20, 2024
92611b4
debug
hiroTochigi Jan 20, 2024
00e68ab
debug
hiroTochigi Jan 20, 2024
694f9e4
debug
hiroTochigi Jan 20, 2024
1a437f0
debug
hiroTochigi Jan 20, 2024
5ace3a7
debug
hiroTochigi Jan 20, 2024
f8d0da8
debug
hiroTochigi Jan 20, 2024
fa61305
debug
hiroTochigi Jan 20, 2024
6bbd2db
debug
hiroTochigi Jan 20, 2024
5791757
remove getTreehousesConfigValue
hiroTochigi Jan 25, 2024
e2a0e27
replace init with initJqObject
hiroTochigi Jan 25, 2024
f7d6c26
use getTreehousesConfigValue
hiroTochigi Jan 25, 2024
c554e3d
try to use delete.sh
hiroTochigi Jan 25, 2024
72427b0
remove test script and set executable permission for driver.sh
hiroTochigi Jan 27, 2024
afcf859
Add README.md with detailed usage instructions for driver.sh
hiroTochigi Jan 27, 2024
1c00fe2
add restart and stop command in the driver
hiroTochigi Feb 1, 2024
c7bbb56
fix case command
hiroTochigi Feb 1, 2024
2ee421a
add SSH tunnel configuration to the config file when the VM is stopped
hiroTochigi Feb 3, 2024
2fba038
fix bag
hiroTochigi Feb 3, 2024
b3fac6c
move function before removing SSH tunnel
hiroTochigi Feb 3, 2024
25dbd8d
Add port array into config file
hiroTochigi Feb 3, 2024
852f911
generate ssh tunnel config
hiroTochigi Feb 3, 2024
f2d7fdb
execute aws command from the root level
hiroTochigi Feb 8, 2024
8917ece
Update usage messages in driver.sh and init.sh scripts
hiroTochigi Feb 8, 2024
929c593
Fix variable interpolation in usage messages
hiroTochigi Feb 8, 2024
2fee056
Fix usage message in AWS driver script
hiroTochigi Feb 8, 2024
dbdd27a
Fix invalid command error message in awsUsage function
hiroTochigi Feb 8, 2024
b8ee4d5
tribial
hiroTochigi Feb 8, 2024
8cecc01
Update usage messages in driver.sh and init.sh scripts
hiroTochigi Feb 8, 2024
1e42576
Merge branch 'add-small-functions' of github.com:treehouses/luftballo…
hiroTochigi Feb 8, 2024
c504d0f
set 'balloonName' to a default value in the delete, restart, and stop…
hiroTochigi Feb 8, 2024
9873915
Merge branch 'add-small-functions' of github.com:treehouses/luftballo…
hiroTochigi Feb 8, 2024
2efebb6
not delete sshtunnel
hiroTochigi Feb 10, 2024
944a7c7
check out ip address
hiroTochigi Feb 10, 2024
46c2668
Add replaceIp function and use it to update IP address in restart.sh
hiroTochigi Feb 10, 2024
6b1ca5f
import replaceIp
hiroTochigi Feb 10, 2024
f52339e
debug
hiroTochigi Feb 10, 2024
f6f8417
Remove test.sh and update load.sh
hiroTochigi Feb 15, 2024
573471e
Add test/experiment to .gitignore and remove src/aws/test.sh
hiroTochigi Feb 15, 2024
e2dbe9b
Add installAwsCli function to driver.sh
hiroTochigi Feb 22, 2024
8998336
put AWS CLI check and SSH key check in init.sh
hiroTochigi Feb 22, 2024
67b9bf7
Add updateOrAppend function to update or append IP and name pairs to …
hiroTochigi Feb 22, 2024
8b6a467
use updateOrAppend function
hiroTochigi Feb 24, 2024
25aec13
make crud functions
hiroTochigi Mar 27, 2024
812f0a4
create several forward lines at once
hiroTochigi Apr 18, 2024
61cd4bc
Refactor extractBlocks to format output and adopt camelCase variables
hiroTochigi Apr 18, 2024
90e9528
Add test_extractBlocks function to validate extractBlocks output
hiroTochigi Apr 18, 2024
0d63785
update RemoteForward argument
hiroTochigi Apr 25, 2024
4b13aaf
Refactor: Organize Bash scripts and introduce centralized configuration
hiroTochigi Apr 27, 2024
440b6a4
call functions from the main.sh
hiroTochigi May 11, 2024
ba452ed
make explanation for how to call sshConfigManager
hiroTochigi May 11, 2024
4beb8db
Added detailed comments and minor improvements to openSSHTunnel function
hiroTochigi Jun 1, 2024
4d42a20
fix: prevent the deletion of the RemoteForward when update other attr…
hiroTochigi Jun 13, 2024
d9430c7
fix: Rename functions to avoid name collision
hiroTochigi Jun 13, 2024
4d6d6a9
feat: edit actual config
hiroTochigi Jun 13, 2024
1e8f675
feat: test call configDriver.sh
hiroTochigi Jun 13, 2024
e016f6e
open ssh tunnel from ssh/config
hiroTochigi Jun 20, 2024
a6e05e8
add ssh port and change the user name from user to root
hiroTochigi Jun 20, 2024
0fe0ae2
delete configuration
hiroTochigi Jun 20, 2024
d86a52b
Refactor to use .ssh/config and update port handling
hiroTochigi Jun 22, 2024
9b8b584
delete a specific configuration in the .ssh/config
hiroTochigi Jun 22, 2024
15d5cf8
fix the bug
hiroTochigi Jun 22, 2024
3b074d2
feat: restart ssh tunnel
hiroTochigi Jun 27, 2024
4f41c41
start ssh tunnel
hiroTochigi Jun 27, 2024
7bae499
fix the issue
hiroTochigi Jun 27, 2024
872c422
update
hiroTochigi Jun 29, 2024
0d67499
disable host key verification
hiroTochigi Jun 29, 2024
2c90cb4
add comments
hiroTochigi Jun 29, 2024
26a4a84
small bug fixes
hiroTochigi Jul 11, 2024
cbc46f1
bug fixes
hiroTochigi Jul 11, 2024
72d6f44
bug fix
hiroTochigi Jul 11, 2024
784d2ca
Delete config.txt
dogi Jul 11, 2024
732516e
Update replace.sh
dogi Jul 11, 2024
8f442c0
Update driver.sh
dogi Jul 11, 2024
d5c1bae
Update allTest.sh
dogi Jul 11, 2024
ccf85cd
Update load.sh
dogi Jul 11, 2024
4d58079
Update callUpdate.sh
dogi Jul 11, 2024
397e143
Update stop.sh
dogi Jul 11, 2024
8dc801a
Update restart.sh
dogi Jul 11, 2024
20cd6b9
Update load.sh
dogi Jul 11, 2024
a47a0c4
Update installAwsCli.sh
dogi Jul 11, 2024
8f76c9f
Update init.sh
dogi Jul 11, 2024
a8c4531
Update utilitiyFunction.sh
dogi Jul 11, 2024
2b9a23f
Update jsonOperations.sh
dogi Jul 11, 2024
1d628dc
Update getProcessNumber.sh
dogi Jul 11, 2024
4c8d5f8
Update configOperations.sh
dogi Jul 11, 2024
7c0ac2a
Update callUtils.sh
dogi Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/test
/experiment

#confs
/vpn/conf/*
Expand Down
310 changes: 155 additions & 155 deletions LICENSE

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 6 additions & 3 deletions archive/jsonController.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function deleteKeyValue(){
echo "$output"
}

function init(){
function initJqObject(){
local name="$1"
local output=$( echo null \
| jq --arg name $name \
Expand Down Expand Up @@ -131,14 +131,14 @@ 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"
}

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 '\' 2>/dev/null | sed 's/"{/{/' | sed 's/}"/}/')
echo $string
}

Expand All @@ -163,7 +163,10 @@ function printAllConfig(){
function getValueByAttribute(){
local instanceName=$1
local attribute=$2
echo "instanceName: $instanceName"
echo "attribute: $attribute"
local backet=$(getBucketByBucketKey "$(getConfigAsJson)" $instanceName)
echo "backet: $backet"
local keyName=$(echo "$backet" | \
jq -r --arg instanceName "$instanceName" \
--arg attribute "$attribute" \
Expand Down
69 changes: 0 additions & 69 deletions delete.sh

This file was deleted.

77 changes: 0 additions & 77 deletions dependencies/reverseShell.sh

This file was deleted.

5 changes: 0 additions & 5 deletions installAwsCli.sh

This file was deleted.

32 changes: 32 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

manageConfigPath=$(pwd)

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
}

# 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
awsDriver "${@:2}"
;;
sshConfigManager)
source $manageConfigPath/src/utils/load.sh
configDriver "${@:2}"
;;
*)
echo "Error: Invalid command."
usage
;;
esac
45 changes: 0 additions & 45 deletions restart.sh

This file was deleted.

53 changes: 53 additions & 0 deletions src/aws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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]
```

### 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:

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


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

BASE=/home/pi
groupName=luftballons-sg

Expand Down
Loading
Loading