You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

103 lines
6.7 KiB

#!/bin/bash
########################################################################
# Author:
# Version: 0.1
# 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) && [[ ! $YOU ]] && echo "ipfs NOT RUNNING. EXIT" && exit 1
G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) && [[ ! $G1PUB ]] && echo "ERREUR G1PUB. EXIT" && exit 1
IPFSNODEID=$(ipfs id -f='<id>\n')
[[ -f ~/.zen/ipfs/.$IPFSNODEID/_xbian.zuid ]] && AXID=$(cat ~/.zen/ipfs/.$IPFSNODEID/_xbian.zuid);
[[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title ]] && XZUID=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title)
########################################################################
## MANAGE "Stargates" 1 to 5.
## Create and renew ~/.zen/key/
## Place them into ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/*
########################################################################
[[ ! -d ~/.zen/key/ ]] && mkdir -p ~/.zen/key/1 ~/.zen/key/2 ~/.zen/key/3 ~/.zen/key/4 ~/.zen/key/5
########################################################################
## ipns key generation procedure
########################################################################
if [[ ! $(ipfs key list -l | grep "star_") ]]; then
[[ ! -d ~/.zen/key/ ]] && mkdir -p ~/.zen/key/1 ~/.zen/key/2 ~/.zen/key/3 ~/.zen/key/4 ~/.zen/key/5
# TODO key name are always the same... =$(~/.zen/astrXbian/zen/tools/give_me_keystore_filename.py "star_1")
stargate_1=$(ipfs key gen star_1) && key_1=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_1 ~/.zen/key/1/ && echo "$stargate_1" > ~/.zen/key/1/stargate
stargate_2=$(ipfs key gen star_2) && key_2=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_2 ~/.zen/key/2/ && echo "$stargate_2" > ~/.zen/key/2/stargate
stargate_3=$(ipfs key gen star_3) && key_3=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_3 ~/.zen/key/3/ && echo "$stargate_3" > ~/.zen/key/3/stargate
stargate_4=$(ipfs key gen star_4) && key_4=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_4 ~/.zen/key/4/ && echo "$stargate_4" > ~/.zen/key/4/stargate
stargate_5=$(ipfs key gen star_5) && key_5=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_5 ~/.zen/key/5/ && echo "$stargate_5" > ~/.zen/key/5/stargate
else
ipfs key list -l | grep "star_"
echo "IPNS star keys already existing... Please remove all 'star_*' ipns keys before running"
exit 1
fi
echo "******************************************************************"
echo "STARGATE1 http://127.0.0.1:8181/ipns/$(cat ~/.zen/key/1/stargate)"
echo "STARGATE2 http://127.0.0.1:8181/ipns/$(cat ~/.zen/key/2/stargate)"
echo "STARGATE3 http://127.0.0.1:8181/ipns/$(cat ~/.zen/key/3/stargate)"
echo "STARGATE4 http://127.0.0.1:8181/ipns/$(cat ~/.zen/key/4/stargate)"
echo "STARGATE5 http://127.0.0.1:8181/ipns/$(cat ~/.zen/key/5/stargate)"
echo "******************************************************************"
########################################################################
## ipns 5 stargates keys distribution to friends
########################################################################
for friendgate in $(ls -d ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/*/); do
echo "*************************************************************"
fg1pub=$(echo $friendgate | cut -d '/' -f 8 )
stars=$(cat ${friendgate}stars.level)
echo "OPENING $stars STARGATES"
echo "FRIEND : $fg1pub"
echo "$friendgate"
[[ "$stars" == "" && "$fg1pub" != "" ]] && echo "NO STAR NO FRIEND" && rm -Rf ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub && continue
# DELETE OLD TRANSMITED STARGATES IPNS LINKS
rm -f ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate*
# DISTRIBUTE ENCRYPT AND PUBLISH NEW STARGATES KEY
case $stars in
1)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
;;
2)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
;;
3)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt"
;;
4)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/4/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate4.encrypt"
;;
5)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/4/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate4.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/5/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate5.encrypt"
;;
esac
ls ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/
echo "http://127.0.0.1:8181/ipns/$IPFSNODEID/.$IPFSNODEID/FRIENDS/$fg1pub/"
echo ""
done
# REFRESH IPNS SELF PUBLISH
########################################################################
~/.zen/astrXbian/zen/ipns_self_publish.sh
########################################################################
exit 0