#!/bin/sh

if [ ! `id -u` -eq 0 ] ; then
    echo "
This script requires root priviledges, use sudo.
"
    exit 1
fi

RESP=$(/usr/bin/bee init --config /etc/bee/bee.yaml 2>&1)
case "$RESP" in
    Error*|*'No such file'*)
        echo "
The bee node has returned an error, probably because the bee-clef external signer is enabled, but the node couldn't connect to it.

Check https://docs.ethswarm.org/ for more info.

Fix the configuration and try again.

The node's output was:
        "
        echo "$RESP"
        ;;
    *)
        ETH_ADDRESS=$(echo "$RESP" | grep ethereum | cut -d' ' -f6 | tr -d '"')
        echo "
Please make sure there is sufficient native tokens and BZZ available on the node's Ethereum address at the APPROPRIATE BLOCKCHAIN: 0x$ETH_ADDRESS.

Learn how to fund your node by visiting our docs at at https://docs.ethswarm.org/docs/installation/fund-your-node

Once the node's wallet has received the funds it will begin joining the Swarm network.

See the docs for more at https://docs.ethswarm.org/docs/.
        "
        ;;
esac
