Last active
March 2, 2021 06:34
-
-
Save Kubuxu/0cafd6dc71114349875827c2c379fa1f to your computer and use it in GitHub Desktop.
Tunnel IPFS API via SSH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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