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.
 
 
 
 
 
 

69 lines
3.6 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=$(cat ~/.ipfs/config | jq -r .Identity.PeerID)
########################################################################
# SCAN AND MANAGE KEYS BETWEEN MOVIES & FRIENDS
## Control IPNS key $MEDIAKEY.4FRIENDS + create, catch & spread MEDIAKEY to FRIENDS
########################################################################
echo "DEV MODE" && exit 0
read
########################################################################
for FRIEND in $(ls ~/.zen/ipfs/.$IPFSNODEID/FRIENDS); do
[[ "$FRIEND" == "index.html" ]] && continue
echo "$FRIEND ?"
for MEDIAKEY in $(ls ~/.zen/ipfs/.$IPFSNODEID/KEY); do
echo "MEDIAKEY=$MEDIAKEY"
## Do I have this IPNS key?
ISKEY=$(ipfs key list -l | grep "$MEDIAKEY.4FRIENDS" | cut -d ' ' -f 2)
echo "ISKEY=$ISKEY"
## Is there any key already from swarm for that MEDIAKEY
PREVKEY=$(ls ~/.zen/ipfs_swarm/.12D*/KEY/$MEDIAKEY/*/$G1PUB/ 2>/dev/null)
echo "PREVKEY=$ISKEY"
## A key is found in my swam
if [[ $PREVKEY ]]; then
echo "I found a MEDIAKEY for $MEDIAKEY : $PREVKEY"
## Do I have it localy available?
if [[ ! $ISKEY ]]; then
echo "don't have it local..."
# decrypting PREVKEY to my ipfs keystore
$MY_PATH/tools/natools.py decrypt -f pubsec -k "$HOME/.zen/secret.dunikey" -i "~/.zen/ipfs_swarm/.12D*/KEY/$MEDIAKEY/*/$G1PUB/$PREVKEY" -o "$HOME/.ipfs/keystore/${PREVKEY%.*}"
## Checking if ipfs deamon have it
ISKEY=$(ipfs key list -l | grep "$MEDIAKEY.4FRIENDS" | cut -d ' ' -f 2)
echo ".ipfs/keystore/${PREVKEY%.*} added..."
[[ ! $ISKEY ]] && echo "Restarting ipfs..." && sudo service ipfs restart
fi
## Station is Not spreading swarm key... just getting it back.
continue
fi
echo "~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/"
## No swarm or local MEDIAKEY, we are the first $MEDIAKEY creator in the swarm
[[ ! $ISKEY ]] && echo "Creating $MEDIAKEY.4FRIENDS IPNS key" && IPNSKEY=$(ipfs key gen "$MEDIAKEY.4FRIENDS") && IPNSKEYFILE=$(~/.zen/astrXbian/zen/tools/give_me_keystore_filename.py "$MEDIAKEY.4FRIENDS")
## Sending encrypted MEDIAKEY to my swarm (sign if you want more security, but code ipfs signature verification is enough and better)
if [[ ! -d ~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/ ]]; then
echo "MEDIAKEY $MEDIAKEY is missing to my $FRIEND"
mkdir -p "~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/"
$MY_PATH/tools/natools.py encrypt -p $FRIEND -i "~/.ipfs/keystore/$IPNSKEYFILE" -o "~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/$IPNSKEYFILE.encrypt"
echo "Spreading ~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/$IPNSKEYFILE.encrypt"
fi
## TODO : CHECK FOR DISAPEARED FRIENDS.
read
done
read
done