TAG REFRESH

This commit is contained in:
qo-op 2019-12-17 17:22:06 +01:00
parent 975963b9b6
commit 014634e840
3 changed files with 86 additions and 32 deletions

83
shell/cron_G1TAG_REFRESH.sh Executable file
View File

@ -0,0 +1,83 @@
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
###########################################################################################
# cron_G1TAG_REFRESH.sh
# Scan all TAG created by current $IPFSNODEID
# Update local and Publish it
# Remove too old or empty ones
##################################################################
YOU=$(ps aux --sort=+utime | grep ipfs | tail -n 1 | cut -d " " -f 1)
IPFSNODEID=$(su $YOU -c "ipfs id -f='<id>\n'")
NANODATE=$(date -u +%s%N) #1569692075385428020
# PROTECT from null HASH
for tag in ./wallets/.$IPFSNODEID/TAG/*; do
function rmtag () {
echo "__SUB:cron_G1TAG_REFRESH.sh: rm -Rf ./wallets/.$IPFSNODEID/TAG/${tagj}"
rm -Rf ./TAG/${tagj}
rm -f ./wallets/.$IPFSNODEID/TAG/${tagj}
rm -f ./wallets_swarm/.$IPFSNODEID/TAG/${tagj}
rm -f /home/$YOU/.ipfs/keystore/${tagj}
}
# Refresh G1Tag created by this NODE
tagj=$(echo $tag | cut -d '/' -f 5)
if [[ "${tagj}" == "" ]]; then echo "__SUB:cron_G1TAG_REFRESH.sh: EMPTY"; continue; fi
echo "__SUB:cron_G1TAG_REFRESH.sh: WORKING ON ${tagj}"
RR=$(./shell/timeout.sh -t 8 su $YOU -c "ipfs cat /ipns/${tagj}/TAG_id | sed s/\ //g");
if [[ "$RR" == "" ]]; then
echo "__SUB:cron_G1TAG_REFRESH.sh: G1Tag Destroyed !!!??";
rmtag
continue;
fi
# RE-SYNC LOCAL & SWARM G1TAG - TODO Check for G1Tag chain corruption
mv ./TAG/${RR} ./TAG/${RR}.old
mkdir -p ./TAG/${RR}
chown -R $YOU ./TAG/${RR}
su $YOU -c "ipfs get --output=./TAG/${RR} /ipns/${tagj}"
oldtagval=$(cat ./TAG/${RR}.old/TAG_amount)
curtagval=$(cat ./TAG/${RR}/TAG_amount)
oldtagn=$(cat ./TAG/${RR}.old/TAG_n)
curtagn=$(cat ./TAG/${RR}/TAG_n)
oldtagchain=$(cat ./TAG/${RR}.old/TAG_chain)
curtagchain=$(cat ./TAG/${RR}/TAG_chain)
echo "__SUB:cron_G1TAG_REFRESH.sh: ./TAG/$RR VALUE: ($oldtagn) $oldtagval ZEN -> ($curtagn) $curtagval ZEN"
echo "__SUB:cron_G1TAG_REFRESH.sh: $oldtagchain -> $curtagchain"
rm -Rf ./TAG/${RR}.old
if [[ $curtagval -eq 0 || "$curtagval" == "" ]]; then rmtag; continue; fi
# SHOULD PUBLISH ONLY MORE THAN 6h NO USE G1TAG
last=$(cat ./TAG/${RR}/TAG_nanodate)
timediff=$( echo "${NANODATE} - ${last}" | bc -l )
# G1TAG TIME SYNC 21600 milliards de nanosecondes = 6h
if [[ $timediff -gt 21600000000000 ]]; then
# GET PUBLISHKEY for that G1TAG
if [[ ! -f /home/$YOU/.ipfs/keystore/${RR} ]]; then
echo "__SUB:cron_G1TAG_REFRESH.sh: GET PUBLISHKEY for that G1TAG";
su $YOU -c "ipfs get -o /home/$YOU/.ipfs/keystore/${RR}.crypt /ipns/$tagj/TAG_publishkey.MASTER.crypt"
if [[ ! -f /home/$YOU/.ipfs/keystore/${RR}.crypt ]]; then log "__SUB:cron_MINUTE.sh: error getting publishkey"; continue; fi
./shell/natools.py decrypt -k "$MASTERKEYFILE" -i /home/$YOU/.ipfs/keystore/${RR}.crypt -o /home/$YOU/.ipfs/keystore/$RR
rm /home/$YOU/.ipfs/keystore/${RR}.crypt
fi
echo "__SUB:cron_G1TAG_REFRESH.sh: G1Tag PUBLISHKEY OK : /home/$YOU/.ipfs/keystore/${RR}"
# PUBLISH VERIFIED G1Tag VERSION
I=$(su $YOU -c "ipfs add -qr ./TAG/${RR} | tail -n 1")
# RECORD TAG_chain And HASH again
echo "$I" > "./TAG/${JDESTRR}/TAG_chain"
I=$(su $YOU -c "ipfs add -qr ./TAG/${RR} | tail -n 1")
# IPNS $JDESTRR PUBLISH
J=$(su $YOU -c "ipfs name publish -k ${RR} --quieter /ipfs/${I}")
echo "__SUB:cron_G1TAG_REFRESH.sh: G1Tag IPNS PUBLISH"
fi
done
##################################################################

View File

@ -26,7 +26,7 @@ if [[ "$YOU" == "" || "$YOU" == "root" ]]; then echo "BAD IPFS. Aucune installat
ipfs_swarm_wallets_refresh "SIMPLE"
################################################################################
# PRINT G1Tag
# PRINT G1Tag PRINTED FROM ANOTHER NODE
# CREATE and REMOVE rr.bin -> done.rr
if [[ -d "./wallets_swarm/.$IPFSNODEID/PRINT/" ]]; then
log "__SUB:cron_MINUTE.sh: SEARCH NEW PRINT FOR ME .$IPFSNODEID"
@ -74,36 +74,7 @@ fi
##################################################################
if [[ "$timebar" == "0300" ]]; then
##################################################################
##################################################################
# Refresh G1Tag created by this NODE
# PROTECT from null HASH
for tag in ./wallets/.$IPFSNODEID/TAG/*; do
tagj=$(echo $tag | cut -d '/' -f 5)
log "__SUB:cron_MINUTE.sh: WORKING ON ${tagj}"
RR=$(su $YOU -c "ipfs cat /ipns/${tagj}/TAG_id | sed s/\ //g");
if [[ ! $RR && "${tagj}" != "" ]]; then echo "G1 Tag Destroyed"; echo "TODO: rm -Rf ./wallets/.$IPFSNODEID/TAG/${tagj} ???"; continue; fi
# GET PUBLISHKEY for that G1TAG
su $YOU -c "ipfs get -o /home/$YOU/.ipfs/keystore/${RR}.crypt /ipns/$tagj/TAG_publishkey.MASTER.crypt"
if [[ ! -f /home/$YOU/.ipfs/keystore/${RR}.crypt ]]; then log "__SUB:cron_MINUTE.sh: error getting publishkey"; continue; fi
./shell/natools.py decrypt -k "$MASTERKEYFILE" -i /home/$YOU/.ipfs/keystore/${RR}.crypt -o /home/$YOU/.ipfs/keystore/$RR
log "__SUB:cron_MINUTE.sh: G1Tag PUBLISHKEY decrypted and loaded in /home/$YOU/.ipfs/keystore/${RR}"
# RE-SYNC LOCAL & SWARM G1TAG (TODO Check G1Tag chain validity)
rm -f ./TAG/${RR}/*
su $YOU -c "ipfs get --output=./TAG/${RR} /ipns/${tagj}"
# PUBLISH VERIFIED G1Tag VERSION
I=$(su $YOU -c "ipfs add -qr ./TAG/${RR} | tail -n 1")
# RECORD TAG_chain And HASH again
echo "$I" > "./TAG/${JDESTRR}/TAG_chain"
I=$(su $YOU -c "ipfs add -qr ./TAG/${RR} | tail -n 1")
# IPNS $JDESTRR PUBLISH
J=$(su $YOU -c "ipfs name publish -k ${RR} --quieter /ipfs/${I}")
done
##################################################################
echo "It is 3 in the morning, or in the night? It depends on your day..."
fi
##################################################################

View File

@ -47,7 +47,7 @@ if [[ -f ./wallets/.$IPFSNODEID/$IPFSNODEID.nanodate ]]; then
last=$(cat ./wallets/.$IPFSNODEID/$IPFSNODEID.nanodate)
timediff=$( echo "${NANODATE} - ${last}" | bc -l )
# Get median nanodate before
# NODE TIME SYNC 120 milliards de nanosecondes
# NODE TIME SYNC 120 milliards de nanosecondes = 120s
if [[ $timediff -gt 120000000000 ]]; then
log "__SUB:ntpdate pool.ntp.org: $timediff $(ntpdate pool.ntp.org)"
export NANODATE=$(date -u +%s%N)