Skip to content

Commit c7e0875

Browse files
authored
Enhance setup process and scripts (#110)
- Update INSTALLATION.md to include execution permissions for setup.sh. - Add a new 'reset' target in the Makefile to clean the local environment. - Improve error handling and precondition checks in setup_identities.sh and setup_initiator.sh. - Modify setup.sh to execute scripts with proper permissions.
1 parent 4571719 commit c7e0875

5 files changed

Lines changed: 40 additions & 21 deletions

File tree

INSTALLATION.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ go install ./cmd/mpcium-cli
4444
### Set everything up in one go
4545

4646
```bash
47-
. setup.sh
47+
chmod +x ./setup.sh
48+
./setup.sh
4849
```
4950

5051
Detailed steps can be found in [SETUP.md](SETUP.md).

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all build clean mpcium mpc install test test-verbose test-coverage e2e-test e2e-clean cleanup-test-env
1+
.PHONY: all build clean mpcium mpc install reset test test-verbose test-coverage e2e-test e2e-clean cleanup-test-env
22

33
BIN_DIR := bin
44

@@ -69,3 +69,15 @@ clean:
6969

7070
# Full clean (including E2E artifacts)
7171
clean-all: clean e2e-clean
72+
73+
# Reset the entire local environment
74+
reset:
75+
@echo "Removing project artifacts..."
76+
rm -rf $(BIN_DIR)
77+
rm -rf node0 node1 node2
78+
rm -rf event_initiator.identity.json event_initiator.key event_initiator.key.age
79+
rm -rf config.yaml peers.json
80+
rm -f coverage.out coverage.html
81+
@echo "Cleaning E2E artifacts..."
82+
- $(MAKE) e2e-clean || true
83+
@echo "Reset completed."

setup.sh

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ cp config.yaml.template config.yaml
1313
echo "🚀 Registering peers to Consul..."
1414
mpcium-cli register-peers
1515

16-
. setup_initiator.sh
17-
. setup_identities.sh
16+
./setup_initiator.sh
17+
./setup_identities.sh

setup_identities.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
# Number of nodes to create (default is 3)
45
NUM_NODES=3
56

67
echo "🚀 Setting up Node Identities..."
78

9+
# Preconditions
10+
command -v mpcium-cli >/dev/null 2>&1 || { echo "❌ mpcium-cli not found in PATH"; exit 1; }
11+
[ -f config.yaml ] || { echo "❌ config.yaml not found in repo root"; exit 1; }
12+
[ -f peers.json ] || { echo "❌ peers.json not found in repo root"; exit 1; }
13+
814
# Create node directories and copy config files
915
echo "📁 Creating node directories..."
1016
for i in $(seq 0 $((NUM_NODES-1))); do
@@ -21,18 +27,19 @@ done
2127
echo "🔑 Generating identities for each node..."
2228
for i in $(seq 0 $((NUM_NODES-1))); do
2329
echo "📝 Generating identity for node$i..."
24-
cd "node$i"
25-
mpcium-cli generate-identity --node "node$i"
26-
cd ..
30+
( cd "node$i" && mpcium-cli generate-identity --node "node$i" )
2731
done
2832

2933
# Distribute identity files to all nodes
3034
echo "🔄 Distributing identity files across nodes..."
3135
for i in $(seq 0 $((NUM_NODES-1))); do
36+
src="node$i/identity/node${i}_identity.json"
37+
[ -f "$src" ] || { echo "❌ Missing identity file for node$i at $src"; exit 1; }
3238
for j in $(seq 0 $((NUM_NODES-1))); do
3339
if [ $i != $j ]; then
40+
mkdir -p "node$j/identity"
3441
echo "📋 Copying node${i}_identity.json to node$j..."
35-
cp "node$i/identity/node${i}_identity.json" "node$j/identity/"
42+
cp -f "$src" "node$j/identity/"
3643
fi
3744
done
3845
done

setup_initiator.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
echo "🚀 Setting up Event Initiator..."
45

@@ -8,25 +9,23 @@ mpcium-cli generate-initiator
89

910
# Extract the public key from the generated file
1011
if [ -f "event_initiator.identity.json" ]; then
11-
PUBLIC_KEY=$(grep -o '"public_key": *"[^"]*"' event_initiator.identity.json | cut -d'"' -f4)
12-
13-
if [ -n "$PUBLIC_KEY" ]; then
14-
echo "🔑 Found public key: $PUBLIC_KEY"
15-
12+
PUBLIC_KEY=$(grep -o '"public_key": *"[^"]*"' event_initiator.identity.json | cut -d '"' -f4)
13+
14+
if [ -n "${PUBLIC_KEY}" ]; then
15+
echo "🔑 Found public key: ${PUBLIC_KEY}"
16+
1617
# Update config.yaml
1718
if [ -f "config.yaml" ]; then
1819
echo "📝 Updating config.yaml..."
19-
# Check if event_initiator_pubkey already exists
20-
if grep -q "event_initiator_pubkey:" config.yaml; then
21-
# Replace existing line
22-
if [[ "$OSTYPE" == "darwin"* ]]; then
23-
sed -i '' "s/event_initiator_pubkey: ./event_initiator_pubkey: "$PUBLIC_KEY"/" config.yaml
20+
# If key exists, replace the whole line; otherwise append a new line
21+
if grep -q "^\s*event_initiator_pubkey:" config.yaml; then
22+
if [[ "${OSTYPE:-}" == darwin* ]]; then
23+
sed -i '' -E "s|^([[:space:]]*event_initiator_pubkey:).*|\1 \"${PUBLIC_KEY}\"|" config.yaml
2424
else
25-
sed -i "s/event_initiator_pubkey: ./event_initiator_pubkey: "$PUBLIC_KEY"/" config.yaml
25+
sed -i -E "s|^([[:space:]]*event_initiator_pubkey:).*|\1 \"${PUBLIC_KEY}\"|" config.yaml
2626
fi
2727
else
28-
# Add new line
29-
echo "event_initiator_pubkey: \"$PUBLIC_KEY\"" >> config.yaml
28+
printf '\n%s\n' "event_initiator_pubkey: \"${PUBLIC_KEY}\"" >> config.yaml
3029
fi
3130
echo "✅ Successfully updated config.yaml"
3231
else

0 commit comments

Comments
 (0)