Skip to content

Instantly share code, notes, and snippets.

@jamiew
Forked from Kubuxu/ipfs-daemon-remote.sh
Created December 4, 2018 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiew/c249f4c7c202f7d3885167623dac376d to your computer and use it in GitHub Desktop.
Save jamiew/c249f4c7c202f7d3885167623dac376d to your computer and use it in GitHub Desktop.
Tunnel IPFS API via SSH
#!/usr/bin/env bash
REMOTE_HOST=${1-"YOUR REMOTE HOST HERE"}
DEFAULT_API_FILE="$HOME/.ipfs/api"
API_FILE="${IPFS_PATH-$DEFAULT_API_FILE}"
if [ -e "$API_FILE" ]; then
echo "IPFS API is already running"
exit 1
fi
PORT=5001
ssh -N -L ${PORT}:localhost:5001 $REMOTE_HOST &
SSH_PID=$!
function cleanupAndExit() {
rm -f "$API_FILE"
echo
echo "Killing ssh."
kill "$SSH_PID"
exit
}
trap cleanupAndExit INT
printf "/ip4/127.0.0.1/tcp/$PORT" > "$API_FILE"
echo "Linked local API to $REMOTE_HOST."
wait $SSH_PID
rm -f "$API_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment