@@ -14,11 +14,29 @@ export PATH=$PWD/bin:$PATH
1414
1515source ./scripts/nodes-configuration.sh
1616
17- UNAME=$( uname -s) SED=
18- case $UNAME in
19- Darwin) SED=" gsed" ;;
20- Linux) SED=" sed" ;;
21- esac
17+ # We need this when running in Docker Desktop on macOS. `sed -i` doesn’t work well with VOLUMEs
18+ # there, unless it can create its temporary files outside of a VOLUME, which requires $TMPDIR.
19+ export TMPDIR=" ${TMPDIR:-/ tmp} "
20+ export TMP=" ${TMP:-/ tmp} "
21+
22+ UNAME=$( uname -s)
23+
24+ # Normal `sed -i` is a bit stubborn, and really wants to create its temporary files in the
25+ # directory of the target file. It is not a true in-place edit, and often braks permissions.
26+ # Let’s use this wrapper instead.
27+ sed_i () {
28+ local tmpfile=$( mktemp)
29+ local sed_bin=sed
30+ if [ " $UNAME " == " Darwin" ] ; then sed_bin=gsed ; fi
31+ if $sed_bin " $@ " > " $tmpfile " ; then
32+ cat " $tmpfile " > " ${@: -1} " # Replace the last argument file (in-place file) with tmpfile content
33+ rm " $tmpfile "
34+ else
35+ echo " sed failed." >&2
36+ rm " $tmpfile "
37+ return 1
38+ fi
39+ }
2240
2341case $( uname) in
2442Darwin) date=' gdate' ;;
@@ -109,7 +127,7 @@ cp templates/babbage/alonzo-babbage-test-genesis.json "${ROOT}/genesis.alonzo.sp
109127cp templates/babbage/conway-babbage-test-genesis.json " ${ROOT} /genesis.conway.spec.json"
110128cp templates/babbage/byron-configuration.yaml " ${ROOT} /configuration.yaml"
111129
112- $SED -i " ${ROOT} /configuration.yaml " \
130+ sed_i \
113131 -e ' s/Protocol: RealPBFT/Protocol: Cardano/' \
114132 -e ' s|GenesisFile: genesis.json|ByronGenesisFile: genesis/byron/genesis.json|' \
115133 -e ' /ByronGenesisFile/ aShelleyGenesisFile: genesis/shelley/genesis.json' \
@@ -119,7 +137,8 @@ $SED -i "${ROOT}/configuration.yaml" \
119137 -e ' s/LastKnownBlockVersion-Major: 0/LastKnownBlockVersion-Major: 6/' \
120138 -e ' s/LastKnownBlockVersion-Minor: 2/LastKnownBlockVersion-Minor: 0/' \
121139 -e " s/minSeverity: Info/minSeverity: ${CARDANO_NODE_LOG_LEVEL} /" \
122- -e " s/cardano.node.ChainDB: Notice/cardano.node.ChainDB: ${CARDANO_NODE_CHAINDB_LOG_LEVEL} /"
140+ -e " s/cardano.node.ChainDB: Notice/cardano.node.ChainDB: ${CARDANO_NODE_CHAINDB_LOG_LEVEL} /" \
141+ " ${ROOT} /configuration.yaml"
123142
124143echo " " >> " ${ROOT} /configuration.yaml"
125144echo " PBftSignatureThreshold: 0.6" >> " ${ROOT} /configuration.yaml"
@@ -248,8 +267,8 @@ for NODE in ${SP_NODES}; do
248267done
249268
250269echo " Update start time in genesis files"
251- $SED -i -E " s/\" startTime\" : [0-9]+/\" startTime\" : ${timeUnix} /" ${ROOT} /genesis/byron/genesis.json
252- $SED -i -E " s/\" systemStart\" : \" .*\" /\" systemStart\" : \" ${timeISO} \" /" ${ROOT} /genesis/shelley/genesis.json
270+ sed_i -E " s/\" startTime\" : [0-9]+/\" startTime\" : ${timeUnix} /" ${ROOT} /genesis/byron/genesis.json
271+ sed_i -E " s/\" systemStart\" : \" .*\" /\" systemStart\" : \" ${timeISO} \" /" ${ROOT} /genesis/shelley/genesis.json
253272
254273byronGenesisHash=$( cardano-cli byron genesis print-genesis-hash --genesis-json ${ROOT} /genesis/byron/genesis.json)
255274shelleyGenesisHash=$( cardano-cli genesis hash --genesis ${ROOT} /genesis/shelley/genesis.json)
@@ -261,10 +280,10 @@ echo "Shelley genesis hash: $shelleyGenesisHash"
261280echo " Alonzo genesis hash: $alonzoGenesisHash "
262281echo " Conway genesis hash: $conwayGenesisHash "
263282
264- $SED -i -E " s/ByronGenesisHash: '.*'/ByronGenesisHash: '${byronGenesisHash} '/" ${ROOT} /configuration.yaml
265- $SED -i -E " s/ShelleyGenesisHash: '.*'/ShelleyGenesisHash: '${shelleyGenesisHash} '/" ${ROOT} /configuration.yaml
266- $SED -i -E " s/AlonzoGenesisHash: '.*'/AlonzoGenesisHash: '${alonzoGenesisHash} '/" ${ROOT} /configuration.yaml
267- $SED -i -E " s/ConwayGenesisHash: '.*'/ConwayGenesisHash: '${conwayGenesisHash} '/" ${ROOT} /configuration.yaml
283+ sed_i -E " s/ByronGenesisHash: '.*'/ByronGenesisHash: '${byronGenesisHash} '/" ${ROOT} /configuration.yaml
284+ sed_i -E " s/ShelleyGenesisHash: '.*'/ShelleyGenesisHash: '${shelleyGenesisHash} '/" ${ROOT} /configuration.yaml
285+ sed_i -E " s/AlonzoGenesisHash: '.*'/AlonzoGenesisHash: '${alonzoGenesisHash} '/" ${ROOT} /configuration.yaml
286+ sed_i -E " s/ConwayGenesisHash: '.*'/ConwayGenesisHash: '${conwayGenesisHash} '/" ${ROOT} /configuration.yaml
268287
269288# Create config folder
270289rm -rf ./config/*
@@ -277,15 +296,17 @@ cp ./templates/babbage/db-sync-config.json ./config/network/cardano-db-sync/conf
277296cp ./templates/babbage/node-config.json ./config/network/cardano-node/config.json
278297cp ./templates/babbage/submit-api-config.json ./config/network/cardano-submit-api/config.json
279298
280- $SED -i -E " s/\" ByronGenesisHash\" : \" .*\" /\" ByronGenesisHash\" : \" ${byronGenesisHash} \" /" ./config/network/cardano-node/config.json
281- $SED -i -E " s/\" ShelleyGenesisHash\" : \" .*\" /\" ShelleyGenesisHash\" : \" ${shelleyGenesisHash} \" /" ./config/network/cardano-node/config.json
282- $SED -i -E " s/\" AlonzoGenesisHash\" : \" .*\" /\" AlonzoGenesisHash\" : \" ${alonzoGenesisHash} \" /" ./config/network/cardano-node/config.json
283- $SED -i -E " s/\" ConwayGenesisHash\" : \" .*\" /\" ConwayGenesisHash\" : \" ${conwayGenesisHash} \" /" ./config/network/cardano-node/config.json
299+ sed_i -E " s/\" ByronGenesisHash\" : \" .*\" /\" ByronGenesisHash\" : \" ${byronGenesisHash} \" /" ./config/network/cardano-node/config.json
300+ sed_i -E " s/\" ShelleyGenesisHash\" : \" .*\" /\" ShelleyGenesisHash\" : \" ${shelleyGenesisHash} \" /" ./config/network/cardano-node/config.json
301+ sed_i -E " s/\" AlonzoGenesisHash\" : \" .*\" /\" AlonzoGenesisHash\" : \" ${alonzoGenesisHash} \" /" ./config/network/cardano-node/config.json
302+ sed_i -E " s/\" ConwayGenesisHash\" : \" .*\" /\" ConwayGenesisHash\" : \" ${conwayGenesisHash} \" /" ./config/network/cardano-node/config.json
284303
285304cp ./templates/babbage/topology.json ./config/network/cardano-node/topology.json
286305# docker hostname in topology.json isn't working, so need to specify ip of local network
287306CONTAINER_IP=$( hostname -I | xargs)
288- $SED -i " s/172.17.0.1/$CONTAINER_IP /g" ./config/network/cardano-node/topology.json
307+ sed_i " s/172.17.0.1/$CONTAINER_IP /g" ./config/network/cardano-node/topology.json
308+ # Note: for some reason, the first cardano-node (on port 3001) isn’t immediately responsive to the outside world, so:
309+ sed_i " s/3001/3002/g" ./config/network/cardano-node/topology.json
289310
290311cp " ${ROOT} " /genesis/byron/genesis.json ./config/network/cardano-node/genesis/byron.json
291312cp " ${ROOT} " /genesis/byron/genesis.json ./config/network/genesis/byron.json
0 commit comments