#!/bin/sh set -e # Exit on failure if [ $# -lt 1 ]; then echo "Error: No argument provided. Please specify '0gchaind' or 'geth' as the first argument." exit 1 fi MODE="$1" shift case "$MODE" in 0gchaind) # Continue with 0gchaind-specific logic (rest of script) ;; geth) GETH_DATA_DIR="/root/.ethereum/" if [ -z "$(ls -A "$GETH_DATA_DIR")" ]; then /0g/bin/geth init --datadir $GETH_DATA_DIR /0g/genesis.json else echo "Datadir not empty, continuing!" >&2 fi exec /0g/bin/geth $@ exit 0 ;; *) echo "Error: Unknown argument '$MODE'. Please specify '0gchaind' or 'geth'." exit 1 ;; esac echo "MONIKER: $MONIKER" AUTH_RPC=${AUTH_RPC:-http://0g-$CHAIN_NAME:8551} # just as example HOME_DIR="/root/.0g" mkdir -p $HOME_DIR CONFIG_DIR="$HOME_DIR/config" DATA_DIR="$HOME_DIR/data" mkdir $CONFIG_DIR mkdir $DATA_DIR env 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 exec /0g/bin/0gchaind $@