diff --git a/A_boostrap_nodes.txt b/A_boostrap_nodes.txt index d74b031..3190204 100644 --- a/A_boostrap_nodes.txt +++ b/A_boostrap_nodes.txt @@ -1,3 +1,3 @@ +# CONTAINS G1PUB of bootstrap PUB Station +# oasis.astroport.com 2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS - -#csmld diff --git a/ISOconfig.sh b/ISOconfig.sh index dce2527..cc33752 100755 --- a/ISOconfig.sh +++ b/ISOconfig.sh @@ -15,34 +15,23 @@ # ~/.zen/ipfs.sync ######################################################################## # CHECK INTERNET CONNECTIVITY & git pull !! +rm -f /tmp/A_booting_log.txt ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || (echo "NO INTERNET CONNEXION" && exit 1) [[ -d ~/.zen/astrXbian ]] && cd ~/.zen/astrXbian && git pull || exit 1 # CHECK IF CONFIG ALREADY DONE !! Remove ~/.zen/ipfs ~/.zen/secret ~/.zen/ipfs.sync if [[ -f ~/.zen/ipfs.sync ]]; then - echo "CONFIG ALREADY DONE" + echo "CONFIG ALREADY DONE.... logging init in /tmp/A_booting_log.txt" source ~/.zen/ipfs.sync - # Wait for ipfs to connect to its swarm, then send ipfstryme to $friend_of_mine - sleep 30 - echo "" > ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr # ERASE - for tryme in $(ipfs id | jq -r .Addresses[]); - do - isLAN=$(echo $tryme | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") - [[ ! $isLAN && $tryme != "" ]] && echo "$tryme" >> ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr && echo "$tryme" - done + # Wait for ipfs to connect to its swarm + sleep 20 + ~/.zen/astrXbian/zen/gchange_INIT.sh >> /tmp/A_booting_log.txt + sleep 10 + ~/.zen/astrXbian/zen/gchange_IPFS_swarm.sh >> /tmp/A_booting_log.txt + sleep 10 + ~/.zen/astrXbian/zen/ipfs_SWARM_refresh.sh >> /tmp/A_booting_log.txt - # NEW BOOT! SEND ipfstryme message to my friends... - cd ~/.zen/astrXbian/zen/jaklis - # GET LIST of issuer(s) who likes me - for liking_me in $(./jaklis.py like | jq -r '.likes[].issuer'); - do - # CHECk if I am liking him either - friend_of_mine=$(./jaklis.py like -p $liking_me | jq -r '.yours'); - echo "Sending IPFSTRYME message to $liking_me" - [[ $friend_of_mine != null ]] && ./jaklis.py send -d $liking_me -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr - done - cd - exit 0 fi @@ -124,15 +113,15 @@ echo "$XZUID" > ~/.zen/ipfs/.${IPFSNODEID}/_xbian.zuid ######################################################################## echo "CREATE + profile" ######################################################################## -~/.zen/astrXbian/zen/jaklis/jaklis.py -n "https://g1.data.e-is.pro" set --name "$XZUID" --avatar "/home/xbian/.zen/astrXbian/logo.png" #CESIUM+ -~/.zen/astrXbian/zen/jaklis/jaklis.py -n "https://data.gchange.fr" set --name "$XZUID" --avatar "/home/xbian/.zen/astrXbian/logo.png" #GCHANGE+ +~/.zen/astrXbian/zen/jaklis/jaklis.py -n "https://g1.data.e-is.pro" set --name "$XZUID" --avatar "/home/$USER/.zen/astrXbian/logo.png" #CESIUM+ +~/.zen/astrXbian/zen/jaklis/jaklis.py -n "https://data.gchange.fr" set --name "$XZUID" --avatar "/home/$USER/.zen/astrXbian/logo.png" #GCHANGE+ ### REVERT # ~/.zen/astrXbian/zen/jaklis/jaklis.py -n "https://g1.data.e-is.pro" erase # ~/.zen/astrXbian/zen/jaklis/jaklis.py -n "https://data.gchange.fr" erase ######################################################################## ######################################################################## -echo "BECOME FRIEND with oasis (1st bootstrap)" +echo "BECOME FRIEND with A_boostrap_nodes.txt (1st bootstrap)" ######################################################################## for g1node in $(cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep -Ev "#") # remove comments do @@ -160,10 +149,12 @@ echo 'EXTEND ~/.bashrc' ######################################################################## ~/.zen/astrXbian/.install/update_bashrc.sh -echo "Configure .kodi/addons/plugin.video.vstream/resources/sites/astroport.py" -cp -f ~/.zen/astrXbian/.install/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py \ +echo "COPY .kodi template " +cp -Rf ~/.zen/astrXbian/.install/.kodi ~/ +# cp -f ~/.zen/astrXbian/.install/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py \ ~/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py +echo "Configure .kodi/addons/plugin.video.vstream/resources/sites/astroport.py" # CREATE xbian IPNSKEY used to publish ~/.zen/ipfs_swarm/xbian (contains all XZUID pastebin files) ipfs key rm xbian IPNSKEY=$(ipfs key gen xbian) diff --git a/cron_MINUTE.sh b/cron_MINUTE.sh index e7e6983..c4822a9 100755 --- a/cron_MINUTE.sh +++ b/cron_MINUTE.sh @@ -75,6 +75,8 @@ fi # /_//_/ /____/|__/|__/\__,_/_/ /_/ /_/ /_/\____/ # ################################################################## +# +[[ "$minute" == "01" ]] && sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/gchange_INIT.sh & # REFRESH IPFS SWARM DATA EVERY 12 & 15 minutes [[ $(($minute % 12)) == 0 ]] && sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/gchange_IPFS_swarm.sh & [[ $(($minute % 15)) == 0 ]] && sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/ipfs_SWARM_refresh.sh & diff --git a/install.sh b/install.sh index 9761ffe..6d00896 100755 --- a/install.sh +++ b/install.sh @@ -49,9 +49,9 @@ sudo fail2ban restart ### Install astrxbian & NGINX config sudo rm -Rf /var/www/astrxbian sudo mkdir -p /var/www/astrxbian -sudo cp -Rf /home/xbian/.zen/astrXbian/www/xbian/* /var/www/astrxbian -sudo chown -R xbian:xbian /var/www/astrxbian -sudo cp -f /home/xbian/.zen/astrXbian/.install/templates/nginx/astrxbian.conf /etc/nginx/conf.d/ +sudo cp -Rf /home/$USER/.zen/astrXbian/www/xbian/* /var/www/astrxbian +sudo chown -R $USER:$USER /var/www/astrxbian +sudo cp -f /home/$USER/.zen/astrXbian/.install/templates/nginx/astrxbian.conf /etc/nginx/conf.d/ # TODO ####################################################################### # echo "Install JUKEBOOX" diff --git a/zen/bash_template.sh b/zen/bash_template.sh new file mode 100644 index 0000000..1cc11be --- /dev/null +++ b/zen/bash_template.sh @@ -0,0 +1,11 @@ +#!/bin/bash +######################################################################## +# Author: Fred (support@qo-op.com) +# Version: 2020.12.25 +# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) +######################################################################## +MY_PATH="`dirname \"$0\"`" # relative +MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized +ME="${0##*/}" +YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); +IPFSNODEID=$(ipfs id -f='\n') diff --git a/zen/cesium_INIT.sh b/zen/cesium_INIT.sh deleted file mode 100755 index e4f5bde..0000000 --- a/zen/cesium_INIT.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/bin/bash -######################################################################## -# Author: Fred (support@qo-op.com) -# Version: 2020.11.30 -# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) -######################################################################## -MY_PATH="`dirname \"$0\"`" # relative -MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized -ME="${0##*/}" - -######################################################################## -# ENVIRONEMENT DETECTION + IPFS ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_info -######################################################################## -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); -IPFSNODEID=$(ipfs id -f='\n') -[[ $IPFSNODEID == "" ]] && echo "ERROR missing IPFS Node id !! EXIT" && exit 1 -######################################################################## -[[ ! -f ~/.zen/secret.dunikey ]] && echo "Missing ~/.zen/secret.dunikey. EXIT" && exit 1 -G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) -[[ $G1PUB == "" ]] && echo "ERROR G1PUB empty !! EXIT" && exit 1 -######################################################################## - -# GET NODE disk performance. TODO, publish and use as IPFS repartition -echo "DISK SIZE AVAILABLE & PERFORMANCE TESTING" -[[ -f ~/.ipfs/test.disk ]] && rm -f ~/.ipfs/test.disk -diskperf=$(dd if=/dev/zero of=~/.ipfs/test.disk bs=10M count=1 oflag=dsync 2>&1 | tail -n 1 | sed s/\,\ /\ -/g | cut -d '-' -f 4) -# echo $diskperf - -# IPFS LOCAL REPOSITORY for Node Identity -mkdir -p ~/.zen/ipfs/.$IPFSNODEID/G1SSB - -# find IPFSTRYME public address -echo "" > ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr -for tryme in $(ipfs id | jq -r .Addresses[]); -do - isLAN=$(echo $tryme | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") - [[ ! $isLAN ]] && echo "$tryme" >> ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr -done -cat ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr - - -################################ -# ADD Cesium+ informations -CESIUMPLUS="https://g1.data.le-sou.org" - -# PREPARE title -# Made from Gchange+ profile tittle and city OR user@hostname -title=$(curl -s ${CESIUMPLUS}/user/profile/${G1PUB} | jq -r '._source.title') -[[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna ]] && uidna=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna) - -# Put in .$IPFSNODEID INDEX: _g1.uidna & _g1.cesium_name (used by Minetest flavour and others) -[[ $uidna ]] && echo "$uidna" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.uidna -[[ $title ]] && echo "$title" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.cesium_name - -[[ $uidna ]] && [[ "$title" == "null" ]] && title="Station $uidna" -[[ "$title" == "null" ]] && title="Station $USER@$(cat /etc/hostname)" - -city=$(curl -s ${CESIUMPLUS}/user/profile/${G1PUB} | jq -r '._source.city') -[[ "$city" != "null" ]] && title="$title in $city" - -# ADD "cesium_geoPoint.lat" AND "cesium_geoPoint.lon" messages in SSB feed -# This way any SSB account is connected to its Cesium+ Geolocalisation. -geopointlat=$(curl -s ${CESIUMPLUS}/user/profile/${G1PUB} | jq '._source.geoPoint.lat') -geopointlon=$(curl -s ${CESIUMPLUS}/user/profile/${G1PUB} | jq '._source.geoPoint.lon') - -# REFRESH Cesium+ Avatar image -curl -s ${CESIUMPLUS}/user/profile/${G1PUB} | jq -r '._source.avatar._content' | base64 -d > "~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.cesium.avatar.png" - -# Get nodename -[[ -f /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename ]] && nodename=$(cat /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename) -if [[ $nodename == "" ]]; then - nodename=$(cat /etc/hostname) - extension=$(echo $nodename | cut -d '.' -f 2) - if [[ $extension == $nodename ]]; then - nodename=$nodename.home - fi - echo "$nodename" > /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename -fi -######################################################################## -# DUNITER G1 Wallet balance -export LC_ALL=C.UTF-8 #attipix -export LANG=C.UTF-8 #attipix - -# COPY NODE G1SSB ID to IPFS -echo "$G1PUB" > ~/.zen/ipfs/.${IPFSNODEID}/G1SSB/_g1.pubkey - -# IPFS Node PUBLISH Adresses so Pub can become bootstrap for ${g1author} -ipfs id | jq -r .Addresses[] > ~/.zen/ipfs/.${IPFSNODEID}/Addresses - -# IPFS Node PUBLISH AgentVersion & repo.stat -ipfs id | jq -r .AgentVersion > ~/.zen/ipfs/.${IPFSNODEID}/AgentVersion -ipfs repo stat > ~/.zen/ipfs/.${IPFSNODEID}/repo.stat - -echo "$diskperf" > ~/.zen/ipfs/.${IPFSNODEID}/disk.perf -echo $(df ~/.ipfs/ | tail -n 1 | awk '{print $4}') > ~/.zen/ipfs/.${IPFSNODEID}/disk.bytes - - -IWALLETS=$(ipfs add -rHq ~/.zen/ipfs | tail -n 1) -NODEIPNS=$(ipfs name publish --allow-offline --quieter /ipfs/$IWALLETS) - -### -# GET ALL MY CESIUMPLUS FRIENDS AND SEND THEM my IPFS Address - -cd ~/.zen/astrXbian/zen/jaklis -# GET LIST of issuer(s) who likes me -for liking_me in $(./jaklis.py like | jq -r '.likes[].issuer'); -do - # CHECk if I am liking him either - friend_of_mine=$(./jaklis.py like -p $liking_me | jq -r '.yours'); - echo "Sending IPFSTRYME message to $liking_me" - [[ $friend_of_mine != null ]] && ./jaklis.py send -d $liking_me -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr -done -cd - - -exit 0 diff --git a/zen/cesium_IPFS_swarm.sh b/zen/cesium_IPFS_swarm.sh deleted file mode 100755 index 2a4530e..0000000 --- a/zen/cesium_IPFS_swarm.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash -######################################################################## -# Author: Fred (support@qo-op.com) -# Version: 2020.12.03 -# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) -######################################################################## -MY_PATH="`dirname \"$0\"`" # relative -MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized -ME="${0##*/}" - -# Connect to IPFS peers with bidirectionnal "like" (Cesium+ friends) - -######################################################################## -# \\/// -# qo-op -############# '$MY_PATH/$ME' -######################################################################## -# ex: ./'$ME' -# GET CESIUM FRIENDS AND FIND THEIR IPFS ID TO "ipfs swarm connect" THEM -########################################################################' - -## TODO : Beware of liking_me FLOOD & Invite $liking_me people to my #Swarm0 (use natools to sign messages?) - - -######################################################################## -# ENVIRONEMENT DETECTION + IPFS ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_info -######################################################################## -IPFSNODEID=$(ipfs id -f='\n') -[[ $IPFSNODEID == "" ]] && echo "ERROR missing IPFS Node id !! IPFS is not installed !?" && exit 1 -isIPFSRunning=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1) -[[ ! $isIPFSRunning ]] && echo "ERROR! ipfs daemon is not running. EXIT" && exit 1 -######################################################################## - -# Force Strict #swarm0 !!? -# ipfs bootstrap rm --all -echo "" > ~/.zen/A_allow_ip.txt - -echo "" > ~/.zen/A_liking_me_NO_ipfstryme.txt # contains "friends" with no "ipfstryme" incoming message -liking_me_count=0 -friend_of_mine_count=0 -######################################################################## -# Let's look for Friends and "IPFS swarm connect" with them -######################################################################## -cd ~/.zen/astrXbian/zen/jaklis -rm -f ~/.zen/A_allow_ipfsid.txt ~/.zen/A_allow_ip.txt - -# 1. Get C+ "liking_me" people list -for liking_me in $(./jaklis.py like | jq -r '.likes[].issuer'); -do - # Check if my like is reverse - friend_of_mine=$(./jaklis.py like -p $liking_me | jq -r '.yours'); - - [[ $friend_of_mine != null ]] && echo "Connect to my friend $liking_me" && friend_of_mine_count=$((friend_of_mine_count+1)) && ipfsadd=0 \ - && for peer in $(./jaklis.py read -n50 -j | jq -r --arg friendKEY "$liking_me" '.[] | select(.pubkey == $friendKEY)' | jq 'select(.title == "ipfstryme")' | jq -r '.content'); - # 2. Searching "ipfstryme" message from friend_of_mine - do - ip=$(echo "$peer" | awk -F '/' '{print $3}') && [[ $ip == "" ]] && continue || echo "Adding $ip to ~/.zen/A_allow_ip.txt" - # Fill a file with friend of mine ip - echo $ip >> ~/.zen/A_allow_ip.txt - # Get its ipfsnodeid - ipfsnodeid=$(echo "$peer" | awk -F '/' '{print $8}') - echo $ipfsnodeid >> ~/.zen/A_allow_ipfsid.txt - - g1id=$(~/.zen/astrXbian/zen/tools/ipfs_to_g1.py "$ipfsnodeid") - if [[ "$g1id" == "$friend_of_mine" ]]; then - # 3. ADD liking_me friend_of_mine to my swarm & bootstrap - ipfs swarm connect $peer; - ipfs bootstrap add $peer; - - ipfsadd=$((ipfsadd+1)) - else - echo "ALERT!!! $friend_of_mine spoofing is happening" - fi - done; - - - if [[ $friend_of_mine != null ]]; then - if [[ $ipfsadd == 0 ]]; then - # Friend of mine with no ipfstryme message (did not install astroport?) - echo "No 'ipfstryme' message... from $liking_me" - echo "$liking_me" >> ~/.zen/A_liking_me_NO_ipfstryme.txt - - else - # REMOVING DUPLICATES OLD ipfstryme MESSAGES - nbmessage=0 - for messageid in $(./jaklis.py read -n50 -j | jq -r --arg friendKEY "$liking_me" '.[] | select(.pubkey == $friendKEY)' | jq 'select(.title == "ipfstryme")' | jq -r '.id') - do - nbmessage=$((nbmessage+1)) - [ $nbmessage -gt 1 ] && echo "Delete OLD 'ipfstryme' messages from $liking_me" && ./jaklis.py delete -i $messageid - done - fi - - fi - - # Automatic level_1 like from oasis.astroport.com (TODO add other default bootstrap) - # TODO get $g1pub from ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.pubkey ?? - # [[ $friend_of_mine == null && $G1PUB == "2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS" ]] && ./jaklis.py like -p $g1pub -s 1 - echo "__________________________________________" - liking_me_count=$((liking_me_count+1)) - -done - - -echo "#################################################### -I have $friend_of_mine_count friends amoung $liking_me_count liking me people -__________________________________________ -My actual #SWARM0" -ipfs swarm peers -echo "__________________________________________" -echo -## Could send message to friends with 'ipfstryme' message -for line in $(cat ~/.zen/A_liking_me_NO_ipfstryme.txt | uniq); do - echo "Liking each other, but no ipfstryme received..." - echo "cd ~/.zen/astrXbian/zen/jaklis" - echo "./jaklis.py send -d $line -t 'Astroport' -m 'Rejoins mon #Swarm0 https://copylaradio.com'" -done - -cd - diff --git a/zen/gchange_INIT.sh b/zen/gchange_INIT.sh index fe6e23e..89b2b4b 100755 --- a/zen/gchange_INIT.sh +++ b/zen/gchange_INIT.sh @@ -21,21 +21,14 @@ G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) ######################################################################## # GET NODE disk performance. TODO, publish and use as IPFS repartition -echo "DISK SIZE AVAILABLE & PERFORMANCE TESTING" [[ -f ~/.ipfs/test.disk ]] && rm -f ~/.ipfs/test.disk diskperf=$(dd if=/dev/zero of=~/.ipfs/test.disk bs=10M count=1 oflag=dsync 2>&1 | tail -n 1 | sed s/\,\ /\ -/g | cut -d '-' -f 4) -# echo $diskperf +echo "DISK PERFORMANCE TESTING : $diskperf" # IPFS LOCAL REPOSITORY for Node Identity mkdir -p ~/.zen/ipfs/.$IPFSNODEID/G1SSB -# find IPFSTRYME public address -echo "" > ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr -for tryme in $(ipfs id | jq -r .Addresses[]); -do - isLAN=$(echo $tryme | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") - [[ ! $isLAN ]] && echo "$tryme" >> ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr -done +# create IPFSTRYME public address file ~/.zen/astrXbian/zen/tools/add_externIP_to_ipfstryme.sh cat ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr @@ -103,16 +96,17 @@ NODEIPNS=$(ipfs name publish --allow-offline --quieter /ipfs/$IWALLETS) ### # GET ALL MY GCHANGE FRIENDS AND SEND THEM my IPFS Address - -cd ~/.zen/astrXbian/zen/jaklis +######################################################################## # GET LIST of issuer(s) who likes me -for liking_me in $(./jaklis.py like | jq -r '.likes[].issuer'); +for liking_me in $(~/.zen/astrXbian/zen/jaklis/jaklis.py like | jq -r '.likes[].issuer'); do # CHECk if I am liking him either - friend_of_mine=$(./jaklis.py like -p $liking_me | jq -r '.yours'); + friend_of_mine=$(~/.zen/astrXbian/zen/jaklis/jaklis.py like -p $liking_me | jq -r '.yours'); echo "Sending IPFSTRYME message to $liking_me" - [[ $friend_of_mine != null ]] && ./jaklis.py send -d $liking_me -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr + [[ $friend_of_mine != null ]] && ~/.zen/astrXbian/zen/jaklis/jaklis.py send -d $liking_me -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr + sleep 3 # SLOW DOWN done + echo 'SEND ipfstryme to A_boostrap_nodes.txt listed PUBs' # Add your bootstrap Pub here for g1node in $(cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep -Ev "#") # remove comments do @@ -120,11 +114,16 @@ if [[ $g1node != "" ]]; then echo "LIKING my BOOTSTRAP node : $g1node" # ~/.zen/astrXbian/zen/jaklis/jaklis.py -n "https://g1.data.le-sou.org" send -d $g1node -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr ~/.zen/astrXbian/zen/jaklis/jaklis.py send -d $g1node -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr + + isG1PUBoot=$(cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep "$G1PUB") # search my G1PUB ? + if [[ $isG1PUBoot == "$G1PUB" ]]; then + for liking_me in $(/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py like | jq -r '.likes[].issuer') + do + echo "SENDING 3 STARS to $liking_me" + /home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py like -p $liking_me -s 3 + done + fi fi done -cd - - -# SHOW RESULT -cat ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr exit 0 diff --git a/zen/gchange_IPFS_swarm.sh b/zen/gchange_IPFS_swarm.sh index cd89698..ef98dca 100755 --- a/zen/gchange_IPFS_swarm.sh +++ b/zen/gchange_IPFS_swarm.sh @@ -8,20 +8,9 @@ MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized ME="${0##*/}" -# Connect to IPFS peers with bidirectionnal "like" (Gchange or Cesium+ friends) -# configured in jaklis/.env - -######################################################################## -# \\/// -# qo-op -############# '$MY_PATH/$ME' -######################################################################## -# ex: ./'$ME' -# GET GCHANGE FRIENDS AND FIND THEIR IPFS ID TO "ipfs swarm connect" THEM -########################################################################' - -## TODO : Beware of liking_me FLOOD & Invite $liking_me people to my #Swarm0 - +# create swarm_map and my_swam files +echo "" > ~/.zen/A_my_swarm.txt +echo "" > ~/.zen/A_swarm_map.txt ######################################################################## # ENVIRONEMENT DETECTION + IPFS ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_info @@ -34,86 +23,65 @@ isIPFSRunning=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|gr # Force Strict #swarm0 !!? # ipfs bootstrap rm --all -echo "" > ~/.zen/A_allow_ip.txt - -echo "" > ~/.zen/A_liking_me_NO_ipfstryme.txt # contains "friends" with no "ipfstryme" incoming message liking_me_count=0 friend_of_mine_count=0 + ######################################################################## # Let's look for Friends and "IPFS swarm connect" with them ######################################################################## -cd ~/.zen/astrXbian/zen/jaklis -rm -f ~/.zen/A_allow_ipfsid.txt ~/.zen/A_allow_ip.txt - # 1. Get Gchange "liking_me" people list -for liking_me in $(./jaklis.py like | jq -r '.likes[].issuer'); +for liking_me in $(~/.zen/astrXbian/zen/jaklis/jaklis.py like | jq -r '.likes[].issuer'); do + [[ "$liking_me" == "" ]] && continue + # DE TOUS CEUX QUI M'AIMENT JE VAIS LIRE LES MESSAGES pour collecter les ipfstryme vers ~/.zen/A_swarm_map.txt + # SI JE SUIS LEUR AMI EN RETOUR, je conserve leur ID dans ~/.zen/A_my_swarm.txt # Check if my like is reverse - friend_of_mine=$(./jaklis.py like -p $liking_me | jq -r '.yours'); - - [[ $friend_of_mine != null ]] && echo "Connect to my friend $liking_me" && friend_of_mine_count=$((friend_of_mine_count+1)) && ipfsadd=0 \ - && for peer in $(./jaklis.py read -n50 -j | jq -r --arg friendKEY "$liking_me" '.[] | select(.pubkey == $friendKEY)' | jq 'select(.title == "ipfstryme")' | jq -r '.content'); - # 2. Searching "ipfstryme" message from friend_of_mine - do - ip=$(echo "$peer" | awk -F '/' '{print $3}') && [[ $ip == "" ]] && continue || echo "Adding $ip to ~/.zen/A_allow_ip.txt" - # Fill a file with friend of mine ip - echo $ip >> ~/.zen/A_allow_ip.txt - # Get its ipfsnodeid - ipfsnodeid=$(echo "$peer" | awk -F '/' '{print $7}') - echo $ipfsnodeid >> ~/.zen/A_allow_ipfsid.txt - - g1id=$(~/.zen/astrXbian/zen/tools/ipfs_to_g1.py "$ipfsnodeid") - if [[ "$g1id" == "$friend_of_mine" ]]; then - # 3. ADD liking_me friend_of_mine to my swarm & bootstrap - ipfs swarm connect $peer; - ipfs bootstrap add $peer; - - ipfsadd=$((ipfsadd+1)) - else - echo "ALERT!!! $friend_of_mine spoofing is happening" - fi - done; - - - if [[ $friend_of_mine != null ]]; then - if [[ $ipfsadd == 0 ]]; then - # Friend of mine with no ipfstryme message (did not install astroport) - echo "No 'ipfstryme' message... from $liking_me" - echo "$liking_me" >> ~/.zen/A_liking_me_NO_ipfstryme.txt - - else - # REMOVING DUPLICATES OLD ipfstryme MESSAGES - nbmessage=0 - for messageid in $(./jaklis.py read -n50 -j | jq -r --arg friendKEY "$liking_me" '.[] | select(.pubkey == $friendKEY)' | jq 'select(.title == "ipfstryme")' | jq -r '.id') - do - nbmessage=$((nbmessage+1)) - [ $nbmessage -gt 1 ] && echo "Delete OLD 'ipfstryme' messages from $liking_me" && ./jaklis.py delete -i $messageid - done - fi - - fi - - # Automatic level_1 like from oasis.astroport.com (TODO add other default bootstrap) - # TODO get $g1pub from ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.pubkey ?? - # [[ $friend_of_mine == null && $G1PUB == "2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS" ]] && ./jaklis.py like -p $g1pub -s 1 - echo "__________________________________________" liking_me_count=$((liking_me_count+1)) + echo ">>>>>> CHECKING my friend n° $liking_me_count" + echo "READING 'ipfstryme' message from $liking_me" + for peerline in $(~/.zen/astrXbian/zen/jaklis/jaklis.py read -n50 -j | jq -r --arg friendKEY "$liking_me" '.[] | select(.pubkey == $friendKEY)' | jq 'select(.title == "ipfstryme")' | jq -r '.content'); + do + echo "PEERLINE: $peerline" + # KEEP A_swarm_map.txt uniq "$peerline" line + echo $peerline >> ~/.zen/A_swarm_map.txt + cat ~/.zen/A_swarm_map.txt | uniq > /tmp/A_swarm_map.txt + cp -f /tmp/A_swarm_map.txt ~/.zen/A_swarm_map.txt + + # Get ipfsnodeid + ipfsnodeid=$(echo "$peerline" | awk -F '/' '{print $8}') + [[ "$ipfsnodeid" == "" ]] && continue + whoisg1=$(~/.zen/astrXbian/zen/tools/ipfs_to_g1.py $ipfsnodeid) + echo "Am I friend whith $whoisg1 ?" + friend_of_mine=$(~/.zen/astrXbian/zen/jaklis/jaklis.py like -p $whoisg1 | jq -r '.yours.pseudo'); # must contains my XZUID + if [[ "$friend_of_mine" != "" ]]; then + friend_of_mine_count=$((friend_of_mine_count+1)) + echo "YEAH FRIEND ° $friend_of_mine_count !!!" + echo $peerline >> ~/.zen/A_my_swarm.txt + # REMOVING OLD ipfstryme MESSAGES + nbmessage=0 + for messageid in $(~/.zen/astrXbian/zen/jaklis/jaklis.py read -n50 -j | jq -r --arg friendKEY "$whoisg1" '.[] | select(.pubkey == $friendKEY)' | jq 'select(.title == "ipfstryme")' | jq -r '.id') + do + nbmessage=$((nbmessage+1)) + [ $nbmessage -gt 1 ] && echo "Delete OLD 'ipfstryme' messages from $whoisg1" && ~/.zen/astrXbian/zen/jaklis/jaklis.py delete -i $messageid + sleep 0.5 + done + fi + done; + + echo "__________________________________________" done +# UNIQ file +cat ~/.zen/A_my_swarm.txt | uniq > /tmp/A_my_swarm.txt +cp -f /tmp/A_my_swarm.txt ~/.zen/A_my_swarm.txt echo "#################################################### I have $friend_of_mine_count friends amoung $liking_me_count liking me people __________________________________________ My actual #SWARM0" ipfs swarm peers -echo "__________________________________________" -echo -## Could send message to friends with 'ipfstryme' message -for line in $(cat ~/.zen/A_liking_me_NO_ipfstryme.txt | uniq); do - echo "Liking each other, but no ipfstryme received..." - echo "cd ~/.zen/astrXbian/zen/jaklis" - echo "./jaklis.py send -d $line -t 'Astroport' -m 'Rejoins mon #Swarm0 https://copylaradio.com'" -done -cd - +# HONTO SEND MESSAGE ~/.zen/astrXbian/zen/jaklis/jaklis.py send -d $line -t 'Astroport' -m 'Rejoins mon #Swarm0 https://copylaradio.com'" + + diff --git a/zen/ipfs_BOOTSTRAP_me.sh b/zen/ipfs_BOOTSTRAP_me.sh deleted file mode 100755 index cbfa88e..0000000 --- a/zen/ipfs_BOOTSTRAP_me.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -######################################################################## -# Author: Fred (support@qo-op.com) -# Version: 2020.12.22 -# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) -######################################################################## -# Auto maticaly accept incoming frendship sending back 3 stars like -# AstrXbian NODE running it starts acting like a "SSB" PUB -# Best using 24/24 public IP node + 1 TB - -# GET XZUID -[[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/_xbian.zuid ]] && echo "ERROR no _xbian.zuid" && exit 1 -XZUID=$(cat ~/.zen/ipfs/.${IPFSNODEID}/_xbian.zuid) # Should be hostname... but like that can be changed... - -isG1PUBoot=$(cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep "$G1PUB") # search my G1PUB ? - -if [[ $isG1PUBoot == "$G1PUB" ]]; then - for liking_me in $(/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py like | jq -r '.likes[].issuer') - do - echo "SENDING 3 STARS to $liking_me" - /home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py like -p $liking_me -s 3 - echo "Our SWARM will join during ipfs_SWARM_refresh.sh RUN" - done -fi - -~/.zen/astrXbian/zen/ipfs_SWARM_refresh.sh - -echo "Share collected indexes as mine" -cp /var/www/astrxbian/FASTRXBIAN ~/.zen/ipfs/xbian/F${XZUID} - diff --git a/zen/ipfs_SWARM_refresh.sh b/zen/ipfs_SWARM_refresh.sh index c7912e6..52d230d 100755 --- a/zen/ipfs_SWARM_refresh.sh +++ b/zen/ipfs_SWARM_refresh.sh @@ -37,48 +37,44 @@ rm -Rf /home/$YOU/.zen/ipfs_swarm/.Qm* rm -Rf /home/$YOU/.zen/ipfs_swarm/* count=1 -for peer in $(ipfs swarm peers); +for peerline in $(ipfs swarm peers && cat ~/.zen/A_swarm_map.txt); do - ipfsnodeid=$(echo "$peer" | awk -F '/' '{print $8}') - ip=$(echo "$peer" | awk -F '/' '{print $3}') + ipfsnodeid=$(echo "$peerline" | awk -F '/' '{print $8}') + [[ "$ipfsnodeid" == "" ]] && continue + whoisg1=$(~/.zen/astrXbian/zen/tools/ipfs_to_g1.py $ipfsnodeid) + + ip=$(echo "$peerline" | awk -F '/' '{print $3}') + isLAN=$(echo $ip | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") + nowdate=$(date) timestamp=$(date -u +%s%N | cut -b1-13) - echo "$nowdate - $ipfsnodeid - $ip" - foundIp=$(cat ~/.zen/A_allow_ip.txt | grep "$ip") - foundIpfs=$(cat ~/.zen/A_allow_ipfsid.txt | grep "$ipfsnodeid") - isLAN=$(echo $ip | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") - - if [[ ! $foundIpfs && ! $isLAN ]] ; then - echo "${ip} of peer ${id} is not in the authorized ip list." - echo "${peer} will be removed from the swarm" - - ipfs swarm disconnect $peer - ipfs bootstrap rm $peer - - echo "# FAIL2BAN # $USER must activate no password sudo (Rpi & Xbian OK)" - if [[ $USER == "pi" || $USER == "xbian" ]]; then - echo "TODO BAN $ip ($ipfsnodeid)" - # sudo fail2ban-client add recidive 2>/dev/null 1>&2 - # sudo fail2ban-client start recidive - # sudo fail2ban-client set recidive banip $ip - # Show banned IP - # sudo fail2ban-client status recidive - fi - else - echo "${peer}" - echo "REFRESH /ipns/$ipfsnodeid INTO ~/.zen/ipfs_swarm/" - $MY_PATH/tools/timeout.sh -t 30 ipfs get --output=/home/$YOU/.zen/ipfs_swarm/ /ipns/$ipfsnodeid - - fi - + echo "### $nowdate ### whoisg1 : $ipfsnodeid - $ip" + echo "${peerline}" + myfriendpeer=$(cat ~/.zen/A_my_swarm.txt | grep $ipfsnodeid ) + if [[ "$myfriendpeer" != "" ]]; then + [[ ! $(ipfs swarm peers | grep $ipfsnodeid) ]] && ipfs swarm connect "$peerline" && ipfs bootstrap add "$peerline" + echo "OK Friend REFRESH /ipns/$ipfsnodeid INTO ~/.zen/ipfs_swarm/" + $MY_PATH/tools/timeout.sh -t 20 ipfs get --output=/home/$YOU/.zen/ipfs_swarm/ /ipns/$ipfsnodeid + else + echo "KO ___________________ # YOU CAN ACTIVATE FAIL2BAN" + # PLEASE ADD $USER NOPASSWD:ALL for fail2ban-client in /etc/sudoers + # sudo fail2ban-client add recidive 2>/dev/null 1>&2 + # sudo fail2ban-client start recidive + # sudo fail2ban-client set recidive banip $ip + # Show banned IP + # sudo fail2ban-client status recidive + echo "?? BAN $ip ($ipfsnodeid)" + fi done +######################################################################## +######################################################################## +######################################################################## echo "$IPFSNODEID PUBLISHING /home/$YOU/.zen/ipfs/ to SWARM" [[ ! -d /home/$YOU/.zen/ipfs ]] && echo "ERROR : /home/$YOU/.zen/ipfs/ NOT FOUND" && exit 1 IWALLETS=$(ipfs add -rHq /home/$YOU/.zen/ipfs | tail -n 1) NODEIPNS=$(ipfs name publish --quieter /ipfs/$IWALLETS) - # Retrieve my own data in /home/$YOU/.zen/ipfs_swarm/ ipfs get --output=/home/$YOU/.zen/ipfs_swarm/ /ipns/$IPFSNODEID diff --git a/zen/no_SPAM.sh b/zen/no_SPAM.sh deleted file mode 100755 index 2d62c9d..0000000 --- a/zen/no_SPAM.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -######################################################################## -# Author: Fred (support@qo-op.com) -# Version: 2020.03.18 -# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) -######################################################################## -MY_PATH="`dirname \"$0\"`" # relative -MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized -######################################################################## -# \\/// -# qo-op -############# -########################## -####################################### -#################################################### -######################################################################## - -######################################################################## -# check /tmp/cmd_received_$SOURCEH and /tmp/cmd_SPAM_$SOURCEH within 1mn - -# Remove older than a minute received COMMAND -find /tmp -cmin +1 -type f -name "cmd_received_*" -exec rm -f '{}' \; 2>/dev/null -# Filter Acknowlegement -if [[ "$CMD" != "ACK" && "$CMD" != "DELIVERED" && "$CMD" != "PENDING" ]]; then - # Still less than a minute with same $SOURCEH - if [[ -f "/tmp/cmd_received_$SOURCEH" ]]; then - # Create SPAM file => Stop answering - if [[ ! -f "/tmp/cmd_SPAM_$SOURCEH" ]]; then - echo $(date) > "/tmp/cmd_SPAM_$SOURCEH" - fi - return 1 - fi - echo "$COMMAND" > "/tmp/cmd_received_$SOURCEH" - # Remove SPAM flag older than one day - find /tmp -ctime +1 -type f -name "cmd_SPAM_*" -exec rm -f '{}' \; 2>/dev/null -else - # THIS IS AN AKNOWLEGEMENT - return 1 -fi -# Remove SPAM flag older than one day -find /tmp -ctime +1 -type f -name "cmd_SPAM_*" -exec rm -f '{}' \; 2>/dev/null -return 0 - - diff --git a/zen/tools/add_externIP_to_ipfstryme.sh b/zen/tools/add_externIP_to_ipfstryme.sh index cb980ba..1cb1349 100755 --- a/zen/tools/add_externIP_to_ipfstryme.sh +++ b/zen/tools/add_externIP_to_ipfstryme.sh @@ -11,12 +11,32 @@ ME="${0##*/}" YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); IPFSNODEID=$(ipfs id -f='\n') -EXTERNIP=$(curl -s http://whatismyip.akamai.com/) +#EXTERNIP=$(curl -s http://whatismyip.akamai.com/) ######################################################################## -echo "ADD $EXTERNIP to /home/$YOU/.zen/ipfs/.${IPFSNODEID}/tryme.addr" +echo "ADDING KNOWN Adresses to /home/$YOU/.zen/ipfs/.${IPFSNODEID}/tryme.addr" ######################################################################## mkdir -p ~/.zen/ipfs/.${IPFSNODEID} -echo "/ip4/$EXTERNIP/udp/4001/astro/p2p/${IPFSNODEID}" >> /home/$YOU/.zen/ipfs/.${IPFSNODEID}/tryme.addr +# echo "/ip4/$EXTERNIP/udp/4001/astro/p2p/${IPFSNODEID}" >> /home/$YOU/.zen/ipfs/.${IPFSNODEID}/tryme.addr +# Doesn't have the right NATed port, so pretty useless... +echo "" > ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr +for tryme in $(ipfs id | jq -r .Addresses[]); +do + isLAN=$(echo $tryme | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") + [[ ! $isLAN ]] && echo "$tryme" >> ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr && echo "ME = $tryme" +done + +# Now adding "ipfs swarm peers" to ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr +for tryme in $(ipfs swarm peers); +do + echo "___________________________________________" + echo "$tryme" + isLAN=$(echo $tryme | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") + [[ ! $isLAN ]] && echo "$tryme" >> ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr && echo "___________________________________________ADDING" +done +# UNIQ TOUT CA +cat ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr | uniq > /tmp/tryme.addr +cp -f /tmp/tryme.addr ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr +rm -f /tmp/tryme.addr exit 0