#!/bin/bash
if [[ ! $(ipfs p2p ls | grep x/ssh-12D3KooWL2FcDJ41U9SyLuvDmA5qGzyoaj2RoEHiJPpCvY8jvx9u) ]]; then
    ipfs --timeout=10s ping -n 4 /p2p/12D3KooWL2FcDJ41U9SyLuvDmA5qGzyoaj2RoEHiJPpCvY8jvx9u
    [[ $? == 0 ]] \
        && ipfs p2p forward /x/ssh-12D3KooWL2FcDJ41U9SyLuvDmA5qGzyoaj2RoEHiJPpCvY8jvx9u /ip4/127.0.0.1/tcp/22154 /p2p/12D3KooWL2FcDJ41U9SyLuvDmA5qGzyoaj2RoEHiJPpCvY8jvx9u \
        && ssh \$USER@127.0.0.1 -p 22154 \
        || echo "CONTACT IPFSNODEID FAILED - ERROR -"
fi

