ipfs_OPEN_ports.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. ################################################################################
  3. # Author: Fred (support@qo-op.com)
  4. # Version: 0.1
  5. # License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
  6. ################################################################################
  7. # Activate SUPPORT MODE: open ssh over IPFS
  8. MY_PATH="`dirname \"$0\"`" # relative
  9. MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
  10. ########################################################################
  11. YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) || er+=" ipfs daemon not running"
  12. IPFSNODEID=$(ipfs id -f='<id>\n') || er+=" ipfs id problem"
  13. WHOAMI=$(sbotc whoami | jq -r .id) || er+=" sbotc whoami problem"
  14. [[ "$YOU" == "" || "$IPFSNODEID" == "" || "$WHOAMI" == "" ]] && echo "ERROR : $er " && exit 1
  15. ########################################################################
  16. # TODO ESTABLISH A PORT FORWARD STRATEGY (depending on Node Flavour)
  17. # Arrange local port forwarded to swarm
  18. # GET _uidna (means g1sms/init.sh been run)
  19. [[ -f /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna ]] && UIDNA=$(cat /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna)
  20. if [[ $(which gammu) ]]; then
  21. # I am a g1sms NODE, pushing my web interface
  22. ipfs p2p listen /x/g1sms /ip4/127.0.0.1/tcp/10099
  23. else
  24. # Looking for g1sms NODE in my swarm
  25. SMSNODE=$(ls /home/$YOU/.zen/ipfs_swarm/.Qm*/G1SSB/_g1sms | shuf -n 1 | cut -d '/' -f 6 | cut -d '.' -f 2)
  26. sleep $((1 + RANDOM % 10)) # Wait for DHT to propagate.... Then forward /x/g1sms
  27. [[ $SMSNODE ]] && ipfs p2p forward /x/g1sms /ip4/127.0.0.1/tcp/10097 /p2p/$SMSNODE
  28. fi
  29. # ipfs p2p close --all
  30. # ipfs p2p listen /x/ssh-$UIDNA /ip4/127.0.0.1/tcp/22
  31. # ipfs p2p listen /x/http-$UIDNA /ip4/127.0.0.1/tcp/80
  32. # ipfs p2p listen /x/https-$UIDNA /ip4/127.0.0.1/tcp/443
  33. ipfs p2p ls