Skip to content

Commit 51ee418

Browse files
committed
refactor: cross-platform sed for setup script
1 parent 173438e commit 51ee418

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

e2e/setup_test_identities.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
# This script sets up identities for testing with separate test database paths
55
set -e
66

7+
# Cross-platform sed in-place function
8+
# macOS requires backup extension, Linux doesn't
9+
sed_inplace() {
10+
if [[ "$OSTYPE" == "darwin"* ]]; then
11+
# macOS
12+
sed -i '' "$@"
13+
else
14+
# Linux and others
15+
sed -i "$@"
16+
fi
17+
}
18+
719
# Number of test nodes
820
NUM_NODES=3
921
BASE_DIR="$(pwd)"
@@ -97,14 +109,14 @@ if [ -f "test_event_initiator.identity.json" ]; then
97109
# Update all test node config files with the actual public key and password
98110
for i in $(seq 0 $((NUM_NODES-1))); do
99111
# Update public key using sed with | as delimiter (safer than /)
100-
sed -i "s|event_initiator_pubkey:.*|event_initiator_pubkey: $PUBKEY|g" "$BASE_DIR/test_node$i/config.yaml"
112+
sed_inplace "s|event_initiator_pubkey:.*|event_initiator_pubkey: $PUBKEY|g" "$BASE_DIR/test_node$i/config.yaml"
101113
# Update password using sed with | as delimiter and escaped password
102-
sed -i "s|badger_password:.*|badger_password: $ESCAPED_PASSWORD|g" "$BASE_DIR/test_node$i/config.yaml"
114+
sed_inplace "s|badger_password:.*|badger_password: $ESCAPED_PASSWORD|g" "$BASE_DIR/test_node$i/config.yaml"
103115
done
104116

105117
# Also update the main config.test.yaml
106-
sed -i "s|event_initiator_pubkey:.*|event_initiator_pubkey: $PUBKEY|g" "$BASE_DIR/config.test.yaml"
107-
sed -i "s|badger_password:.*|badger_password: $ESCAPED_PASSWORD|g" "$BASE_DIR/config.test.yaml"
118+
sed_inplace "s|event_initiator_pubkey:.*|event_initiator_pubkey: $PUBKEY|g" "$BASE_DIR/config.test.yaml"
119+
sed_inplace "s|badger_password:.*|badger_password: $ESCAPED_PASSWORD|g" "$BASE_DIR/config.test.yaml"
108120

109121
echo "✅ Event initiator public key updated: $PUBKEY"
110122
echo "✅ Badger password updated: $BADGER_PASSWORD"

0 commit comments

Comments
 (0)