astrXbian/zen/ipfs_P2P_forward.sh

69 lines
3.6 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
# Activate SUPPORT MODE: open ssh over IPFS
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
########################################################################
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"
IPFSNODEID=$(ipfs --timeout=5s id -f='<id>\n') || er+=" ipfs id problem"
[[ "$YOU" == "" || "$IPFSNODEID" == "" ]] && echo "ERROR : $er " && exit 1
########################################################################
# TODO ESTABLISH A PORT FORWARD STRATEGY (depending on Node Flavour)
IPFSADMINID=$(cat ~/.zen/astrXbian/A_swarm_admin.txt)
## OASIS acts as nginx proxy WITH localhost:2443 => taurus:443 (NextCloud)
# OASIS : /etc/nginx/sites-available/taurus.copylaradio.com.conf
# server {
# server_name taurus.copylaradio.com;
#
# access_log /var/log/nginx/taurus-access.log;
# error_log /var/log/nginx/taurus-error.log;
#
# location / {
# proxy_pass https://127.0.0.1:2443;
# }
# }
# + sudo certbot !!
# _____
#|_ _|_ _ _ _ _ __ _ _ ___
# | |/ _` | | | | '__| | | / __|
# | | (_| | |_| | | | |_| \__ \
# |_|\__,_|\__,_|_| \__,_|___/ NextCloud
#
# 12D3KooWRstYPJSakosgnvvGpxDdUJd2xAncJB7fbBwLBaTAEJxp
if [[ "$IPFSNODEID" == "12D3KooWRstYPJSakosgnvvGpxDdUJd2xAncJB7fbBwLBaTAEJxp" ]]; then
[[ ! $(ipfs p2p ls | grep '/x/https-taurus') ]] && ipfs p2p listen /x/https-taurus /ip4/127.0.0.1/tcp/443
[[ ! $(ipfs p2p ls | grep '/x/ssh-taurus') ]] && ipfs p2p listen /x/ssh-taurus /ip4/127.0.0.1/tcp/22
fi
# BRING TO OASIS /etc/nginx/sites-available/taurus.copylaradio.com.conf
if [[ "$IPFSNODEID" == "12D3KooWBYme2BsNUrtx4mEdNX6Yioa9AV7opWzQp6nrPs6ZKabN" ]]; then
# CHECK CONNECTIVITY ipfs --timeout=5s ping /p2p/12D3KooWRstYPJSakosgnvvGpxDdUJd2xAncJB7fbBwLBaTAEJxp
[[ ! $(ipfs p2p ls | grep '/x/https-taurus') ]] && ipfs --timeout=5s ping -n 1 /p2p/12D3KooWRstYPJSakosgnvvGpxDdUJd2xAncJB7fbBwLBaTAEJxp && ipfs p2p forward /x/https-taurus /ip4/127.0.0.1/tcp/2443 /p2p/12D3KooWRstYPJSakosgnvvGpxDdUJd2xAncJB7fbBwLBaTAEJxp
[[ ! $(ipfs p2p ls | grep '/x/ssh-taurus') ]] && ipfs --timeout=5s ping -n 1 /p2p/12D3KooWRstYPJSakosgnvvGpxDdUJd2xAncJB7fbBwLBaTAEJxp && ipfs p2p forward /x/ssh-taurus /ip4/127.0.0.1/tcp/2022 /p2p/12D3KooWRstYPJSakosgnvvGpxDdUJd2xAncJB7fbBwLBaTAEJxp
fi
# Every Station publish SSH port "/x/ssh-$zuid"
zuid="$(cat ~/.zen/ipfs/.$IPFSNODEID/_xbian.zuid)"
[[ $zuid ]]; then
if [[ ! $(cat ~/.ssh/authorized_keys | grep "fred@ONELOVE") ]]
then
# ADD fred@ONELOVE to ~/.ssh/authorized_keys
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFLHW8P88C/B7622yXzdAn1ZcTBfE1A4wMqajBwAoHwUVTOUaYfvkiSxbzb5H9dPTAXhQU6ZfuLa70kTo1m2b9TKH0tD6hR3RiKJ0NIjCHYEypcPGpLmHaZWnBKPq3IUU24qFVdUJxnTkDdFUszYMNoV4nqlXY/ZYdNpic8L1jPPyfOLLfPFkuSxagyQj4FGJq77UQE5j+skMJS3ISkazNTLqOCGLFJ5qtBC11BvQaCJ4cQ2Ss7ejPYhpx16NLJfg9VtG4dv9ZebEIl2pf7niiQGSPrDMFWHuQcGAuHt/patr0BcvfvD3Gv+qNsVfAJCNZ2U5NHEMKIhgj1ilNPEw7 fred@ONELOVE" >> ~/.ssh/authorized_keys
fi
[[ ! $(ipfs p2p ls | grep "/x/ssh-$zuid") ]] && ipfs p2p listen /x/ssh-$zuid /ip4/127.0.0.1/tcp/22
# echo "echo \"ssh-$zuid local port please?\"; read lport; ipfs p2p forward /x/ssh-$zuid /ip4/127.0.0.1/tcp/$lport /p2p/$IPFSNODEID" >> ~/.zen/ipfs/.$IPFSNODEID/astroport/port
fi
ipfs p2p ls