astrXbian/zen/gchange_INIT.sh

171 lines
8.2 KiB
Bash
Raw Normal View History

2020-12-12 01:26:39 +01:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
2021-01-31 14:19:15 +01:00
# Version: 0.2
2020-12-12 01:26:39 +01:00
# 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##*/}"
2021-01-12 18:35:22 +01:00
# Retrieve Gchange profil data
# Sends "ipfstryme" messages to liked linking_me NODES
# If NODE is from "A_boostrap_nodes.txt" then auto-linking
2020-12-12 01:26:39 +01:00
########################################################################
2021-01-31 14:19:15 +01:00
# INITIALISATION & CONTROL
2020-12-12 01:26:39 +01:00
########################################################################
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='<id>\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
2021-01-31 14:19:15 +01:00
########################################################################
# NODE DISK PERFORMANCE
2020-12-12 01:26:39 +01:00
[[ -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)
2020-12-25 19:27:26 +01:00
echo "DISK PERFORMANCE TESTING : $diskperf"
2020-12-12 01:26:39 +01:00
2021-01-31 14:19:15 +01:00
########################################################################
# CREATNG IPFS LOCAL REPOSITORY for Node G1 Identity : G1SSB
2020-12-12 01:26:39 +01:00
mkdir -p ~/.zen/ipfs/.$IPFSNODEID/G1SSB
2021-01-31 14:19:15 +01:00
########################################################################
# CREATING MY tryme.addr
2020-12-24 16:29:36 +01:00
~/.zen/astrXbian/zen/tools/add_externIP_to_ipfstryme.sh
2020-12-12 01:26:39 +01:00
cat ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
2021-01-31 14:19:15 +01:00
########################################################################
2020-12-12 01:26:39 +01:00
# ADD GCHANGE+ informations
2021-01-31 14:19:15 +01:00
########################################################################
2020-12-12 01:26:39 +01:00
GCHANGE="https://data.gchange.fr"
2021-01-31 14:19:15 +01:00
# CREATE _g1.gchange_title
rm -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title
2020-12-12 01:26:39 +01:00
title=$(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq -r '._source.title')
2021-01-31 14:19:15 +01:00
[[ $title ]] && echo "$title" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title
2020-12-12 01:26:39 +01:00
# CREATE _g1.astroport_title with city
2021-01-31 14:19:15 +01:00
rm -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.astroport_title
title="Station $USER@$(hostname)"
2020-12-12 01:26:39 +01:00
city=$(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq -r '._source.city')
[[ "$city" != "null" ]] && title="$title in $city"
2021-01-31 14:19:15 +01:00
echo "$title" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.astroport_title
2020-12-12 01:26:39 +01:00
2021-01-31 14:19:15 +01:00
# DESACTIVATED
# CREATE "_g1.gchange_geoPoint.lat" AND "_g1.gchange_geoPoint.lon"
# rm -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_geoPoint.lat
# echo $(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq '._source.geoPoint.lat') > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_geoPoint.lat
# rm -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_geoPoint.lon
# echo $(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq '._source.geoPoint.lon') > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_geoPoint.lon
2020-12-12 01:26:39 +01:00
2021-01-31 14:19:15 +01:00
# CREATE _g1.gchange_avatar.png
curl -s ${GCHANGE}/user/profile/${G1PUB} | jq -r '._source.avatar._content' | base64 -d > "/home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_avatar.png"
2020-12-12 01:26:39 +01:00
2021-01-31 14:19:15 +01:00
# CREATE _nodename
2020-12-12 01:26:39 +01:00
[[ -f /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename ]] && nodename=$(cat /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename)
if [[ $nodename == "" ]]; then
2021-01-31 14:19:15 +01:00
nodename=$(hostname)
2020-12-12 01:26:39 +01:00
extension=$(echo $nodename | cut -d '.' -f 2)
if [[ $extension == $nodename ]]; then
nodename=$nodename.home
fi
2021-01-31 14:19:15 +01:00
echo "$nodename" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename
2020-12-12 01:26:39 +01:00
fi
########################################################################
# DUNITER G1 Wallet balance
export LC_ALL=C.UTF-8 #attipix
export LANG=C.UTF-8 #attipix
2021-01-31 14:19:15 +01:00
# _g1.pubkey
2020-12-12 01:26:39 +01:00
echo "$G1PUB" > ~/.zen/ipfs/.${IPFSNODEID}/G1SSB/_g1.pubkey
2021-01-31 14:19:15 +01:00
# IPFS Adresses
2020-12-12 01:26:39 +01:00
ipfs id | jq -r .Addresses[] > ~/.zen/ipfs/.${IPFSNODEID}/Addresses
2021-01-31 14:19:15 +01:00
# IPFS AgentVersion
2020-12-12 01:26:39 +01:00
ipfs id | jq -r .AgentVersion > ~/.zen/ipfs/.${IPFSNODEID}/AgentVersion
2021-01-31 14:19:15 +01:00
# IPFS repo.stat
2020-12-12 01:26:39 +01:00
ipfs repo stat > ~/.zen/ipfs/.${IPFSNODEID}/repo.stat
2021-01-31 14:19:15 +01:00
# NODE disk.perf
2020-12-12 01:26:39 +01:00
echo "$diskperf" > ~/.zen/ipfs/.${IPFSNODEID}/disk.perf
2021-01-31 14:19:15 +01:00
# NODE disk.bytes
2020-12-12 01:26:39 +01:00
echo $(df ~/.ipfs/ | tail -n 1 | awk '{print $4}') > ~/.zen/ipfs/.${IPFSNODEID}/disk.bytes
###
#### FRIENDS && BOOTSTRAP ipfstryme MESSAGE sending procedure
2020-12-25 19:27:26 +01:00
########################################################################
2021-01-31 14:19:15 +01:00
# GET LIST of issuer(s) who likes me & A_boostrap_nodes.txt
2021-02-21 21:35:23 +01:00
IamBOOTSTRAP=$(cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep "$G1PUB") # AM I A BOOTSTRAP ?
################## AUTO PINNING
2021-02-22 02:17:21 +01:00
if [[ "$IamBOOTSTRAP" == "$G1PUB" ]]; then
## AUTO PIN FRIENDS ACTIVATION
# /home/fred/.zen/ipfs_swarm/.12D3KooWB2PWQegymKFGdhKGQbyvnp5RQvjFPzz6KC6sxeo3juaB/PIN/QmbkFKpmfaZyFTBNGbnsLDuaQULzLTAS5DBYHjSYVDrFen/2D2LfX7GaQynDooqn1Eb21zavbgcNJucMbjrafe9qxrF
2021-02-22 02:40:09 +01:00
for ipfsfile in $(ls ~/.zen/ipfs_swarm/.*/PIN/*/* | grep -Ev ${IPFSNODEID} | cut -d '/' -f 8 | sort | uniq | shuf );
2021-02-22 02:17:21 +01:00
do
# /home/fred/.zen/ipfs_swarm/.12D3KooWB2PWQegymKFGdhKGQbyvnp5RQvjFPzz6KC6sxeo3juaB/PIN/QmbkFKpmfaZyFTBNGbnsLDuaQULzLTAS5DBYHjSYVDrFen/2D2LfX7GaQynDooqn1Eb21zavbgcNJucMbjrafe9qxrF
# PINNING NEW FILE
2021-02-22 02:30:10 +01:00
astrofile=$(~/.zen/astrXbian/zen/tools/timeout.sh -t 5 ipfs ls $ipfsfile 2>/dev/null | cut -d ' ' -f 1)
2021-02-22 02:17:21 +01:00
echo "PINNING ~/.zen/ipfs/.${IPFSNODEID}/PIN/${astrofile} ??"
2021-02-22 02:30:10 +01:00
if [[ ! -d ~/.zen/ipfs/.${IPFSNODEID}/PIN/${astrofile} && "${astrofile}" != "" ]];
2021-02-22 02:17:21 +01:00
then
2021-02-22 02:49:20 +01:00
echo "TRYING TO PIN : $astrofile"
2021-02-22 02:56:08 +01:00
~/.zen/astrXbian/zen/tools/timeout.sh -t 5 ipfs ls ${ipfsfile} && ipfs pin add --progress /ipfs/${ipfsfile} && mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/PIN/${ipfsfile}/ && echo "PUBLISHING MY PIN" || continue
2021-02-22 02:51:47 +01:00
[[ -d ~/.zen/ipfs/.${IPFSNODEID}/PIN/${ipfsfile} ]] && echo "0" > ~/.zen/ipfs/.${IPFSNODEID}/PIN/${ipfsfile}/$G1PUB && break
2021-02-22 02:17:21 +01:00
fi
done
fi
2021-02-21 21:35:23 +01:00
################## AUTO PINNING
for liking_me in $(~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey stars | jq -r '.likes[].issuer' && cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep -Ev "#");
2020-12-12 01:26:39 +01:00
do
2021-03-05 19:50:21 +01:00
# BOOTSTRAP AUTO LIKE BACK (NOT liking Myself)
2021-02-20 01:47:40 +01:00
if [[ "$IamBOOTSTRAP" == "$G1PUB" ]]; then
2021-02-22 02:17:21 +01:00
echo "I AM A BOOTSTRAP AUTO LIKING $liking_me FRIEND"
2021-03-05 19:50:21 +01:00
if [[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/tryme.addr && "$liking_me" != "$G1PUB" ]]; then
2021-02-20 01:47:40 +01:00
echo "SENDING 1 STAR AUTO LIKE to $liking_me"
/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey unstars -p $liking_me
2021-02-20 01:47:40 +01:00
sleep $((1 + RANDOM % 2)) # SLOW DOWN
/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey stars -p $liking_me -n 1
2021-02-20 01:47:40 +01:00
sleep $((1 + RANDOM % 2)) # SLOW DOWN
fi
2020-12-25 19:27:26 +01:00
fi
2021-01-31 15:04:35 +01:00
# CHECKING IF WE LIKE EACH OTHER (AVOID LIKING MYSELF)
friend_of_mine=$(~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey stars -p $liking_me | jq -r '.yours');
2021-01-31 15:04:35 +01:00
if [[ "$friend_of_mine" != "null" && "$liking_me" != "$G1PUB" ]]
then
# ADD $liking_me TO MY ipfs FRIENDS list
mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me
# SEND jaklis message if tryme.addr is different from last one
if [[ $(diff ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/tryme.addr 2>&1) ]]
then
echo "I AM $G1PUB"
echo "Sending IPFSTRYME message to $liking_me"
~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey send -d $liking_me -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
else
echo "tryme.addr MESSAGE ALREADY SEND TO $liking_me"
fi
# MEMORIZE actual tryme.addr
cp -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/
2021-02-21 21:23:26 +01:00
fi
sleep $((1 + RANDOM % 2)) # SLOW DOWN
2021-03-05 19:54:18 +01:00
# TODO: REMOVE NOT ANYMORE FRIENDS ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/
# Memorize $friend_of_mine loop and remove extra directories
2020-12-24 16:43:37 +01:00
done
2021-02-24 22:32:26 +01:00
## ADD tiddlywiki #TODO REMOVE #PUT in ISOConfig for next install
[[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/index.html ]] && mkdir -p ~/.zen/ipfs/.${IPFSNODEID} && cp ~/.zen/astrXbian/.install/templates/tiddlywiki/index.html ~/.zen/ipfs/.${IPFSNODEID}/index.html
# REFRESH IPNS SELF PUBLISH
########################################################################
~/.zen/astrXbian/zen/ipns_self_publish.sh
########################################################################
2021-01-31 14:19:15 +01:00
2020-12-12 01:26:39 +01:00
exit 0