Skip to content

Commit

Permalink
full cycle up/stop/start/down (fixes #34) (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
hiroTochigi and dogi authored Jul 11, 2024
1 parent 125f9d8 commit aef3e7b
Show file tree
Hide file tree
Showing 50 changed files with 1,105 additions and 442 deletions.
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

0 comments on commit aef3e7b

Please sign in to comment.