diff --git a/0g/scripts/init.sh b/0g/scripts/init.sh index 296c4089..6031d5a1 100644 --- a/0g/scripts/init.sh +++ b/0g/scripts/init.sh @@ -17,11 +17,10 @@ case "$MODE" in geth) GETH_DATA_DIR="/root/.ethereum/" - if [ ! -f "$GETH_DATA_DIR/initialized" ]; then + if [ -z "$(ls -A "$GETH_DATA_DIR")" ]; then /0g/bin/geth init --datadir $GETH_DATA_DIR /0g/genesis.json - touch "$GETH_DATA_DIR/initialized" else - echo "Already initialized, continuing!" >&2 + echo "Datadir not empty, continuing!" >&2 fi exec /0g/bin/geth $@ @@ -48,8 +47,20 @@ mkdir $DATA_DIR env -if /0g/bin/0gchaind init ${MONIKER} --home $HOME_DIR; then - cp -r /0g/0g-home/0gchain-home/config/* $CONFIG_DIR +if [ ! -f "$HOME_DIR/priv_validator_state.json" ]; then + TMP_DIR=$(mktemp -d) + echo "priv_validator_state.json not found in $HOME_DIR. Proceeding with initialization steps..." + # You can add any additional initialization logic here if needed + if /0g/bin/0gchaind init ${MONIKER} --home $TMP_DIR; then + cp -r /0g/0g-home/0gchaind-home/config/* $CONFIG_DIR + cp $TMP_DIR/data/priv_validator_state.json $DATA_DIR + cp $TMP_DIR/config/node_key.json $CONFIG_DIR + cp $TMP_DIR/config/priv_validator_key.json $CONFIG_DIR + else + echo "Already initialized, continuing!" >&2 + fi + rm -rf $TMP_DIR # delete tmp dir + else echo "Already initialized, continuing!" >&2 fi