Skip to content

Commit

Permalink
Merge pull request #26 from Devolved-AI/psyfercom-patch-1
Browse files Browse the repository at this point in the history
New helper scripts to go along with the guide.
  • Loading branch information
psyfercom authored Jul 26, 2024
2 parents 9879296 + 4277791 commit bf4f80c
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
66 changes: 66 additions & 0 deletions rotate_keys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

# Function to prompt user for input with a custom message
prompt_for_input() {
local prompt_message="$1"
local input_variable
read -p "$prompt_message" input_variable
echo "$input_variable"
}

# Prompt user for base path
base_path=$(prompt_for_input "Enter the base path for the node (e.g., /tmp/node01): ")

# Prompt user for chain specification file
chain_spec=$(prompt_for_input "Enter the chain specification file (e.g., minervaRaw.json): ")

name=$(prompt_for_input "Give your node a unique name (e.g., BestValidatorEver): ")

# Function to generate key and insert into node
generate_and_insert_key() {
local key_type="$1"
local scheme="$2"
local base_path="$3"
local chain_spec="$4"
local name="$5"

echo "Generating $key_type key..."
key_output=$(subkey generate --scheme "$scheme" --output-type json)

# Extract secret phrase and public key from key output
secret_phrase=$(echo "$key_output" | jq -r '.secretPhrase')
public_key=$(echo "$key_output" | jq -r '.publicKey')

echo "Inserting $key_type key..."
./target/release/argochain key insert --base-path "$base_path" --chain "$chain_spec" --scheme "$scheme" --suri "$secret_phrase" --key-type "$key_type"

if [ $? -eq 0 ]; then
echo "$key_type key inserted. Public key: $public_key"
else
echo "Error inserting $key_type key."
fi
}

# Function to rotate keys
rotate_key() {
local key_type="$1"
local scheme="$2"
local base_path="$3"
local chain_spec="$4"
local name="$5"

echo "Rotating $key_type key..."
generate_and_insert_key "$key_type" "$scheme" "$base_path" "$chain_spec"
echo "$key_type key rotated."
}

# Rotate keys for all consensus mechanisms
rotate_key "babe" "Sr25519" "$base_path" "$chain_spec"
rotate_key "gran" "Ed25519" "$base_path" "$chain_spec"
rotate_key "audi" "Sr25519" "$base_path" "$chain_spec"
rotate_key "imon" "Sr25519" "$base_path" "$chain_spec"



echo "Node has now been injected with new validator keys."
./target/release/argochain --chain $chain_spec --name $name
64 changes: 64 additions & 0 deletions update_bootnodes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Function to print messages
print_message() {
MESSAGE=$1
echo "${MESSAGE}"
}

# Function to insert bootnodes into minervaRaw.json
insert_bootnodes() {
python3 <<EOF
import re
import time
from tqdm import tqdm
def insert_bootnodes(original_file, bootnodes_file):
try:
with open(original_file, 'r') as file:
original_content = file.read()
with open(bootnodes_file, 'r') as file:
bootnodes_content = file.read().strip()
# Progress bar for processing the content
for _ in tqdm(range(10), desc="🌟 Processing content", ncols=100, ascii=True, bar_format="{l_bar}{bar} | {n_fmt}/{total_fmt}"):
time.sleep(0.1) # Simulate work being done
# Find the bootNodes section, clear its contents, and insert the new bootnodes content
pattern = re.compile(r'("bootNodes"\\s*:\\s*\\[)[^\\]]*?(\\])', re.DOTALL)
new_content = pattern.sub(r'\\1\n' + bootnodes_content + r'\\2', original_content)
# Progress bar for writing the new content
for _ in tqdm(range(10), desc="🌟 Writing new content", ncols=100, ascii=True, bar_format="{l_bar}{bar} | {n_fmt}/{total_fmt}"):
time.sleep(0.1) # Simulate work being done
# Write the modified content back to the original file
with open(original_file, 'w') as file:
file.write(new_content)
print(f"Successfully inserted bootnodes into {original_file}")
except Exception as e:
print(f"An error occurred: {e}")
def main():
original_file = 'minervaRaw.json' # Path to the original JSON file
bootnodes_file = 'bootnodes.txt' # Path to the bootnodes file
# Progress bar for reading files
for _ in tqdm(range(10), desc="📄 Reading files", ncols=100, ascii=True, bar_format="{l_bar}{bar} | {n_fmt}/{total_fmt}"):
time.sleep(0.1) # Simulate work being done
insert_bootnodes(original_file, bootnodes_file)
if __name__ == "__main__":
main()
EOF
}


# Main script execution
insert_bootnodes

print_message "Boot nodes insertion complete."

0 comments on commit bf4f80c

Please sign in to comment.