110 lines
4.9 KiB
Bash
Executable File
110 lines
4.9 KiB
Bash
Executable File
#!/bin/bash
|
|
################################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# Version: 0.1
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
################################################################################
|
|
# CE FICHIER cron_MINUTE.sh EST EXECUTE TOUTES LES MINUTES
|
|
# IL CONSTITUE LE BATEMENT DE COEUR DU SYSTEME
|
|
################################################################################
|
|
YOU=$(ps aux --sort=+utime | grep ipfs | tail -n 1 | cut -d " " -f 1)
|
|
IPFSNODEID=$(su $YOU -c "ipfs id -f='<id>\n'")
|
|
CHEMIN="/home/$YOU/G1sms+"
|
|
cd $CHEMIN
|
|
source ./shell/init.sh
|
|
source ./shell/functions.sh
|
|
|
|
timebar=$(date +%H%M)
|
|
|
|
if [[ "$USER" != "root" ]]; then echo "Hey, $USER you must at least be admin of your system. sudo -s ?"; exit; fi
|
|
if [[ "$YOU" == "" || "$YOU" == "root" ]]; then echo "BAD IPFS. Aucune installation IPFS satisfaisante ici... Ciao $YOU !"; exit; fi
|
|
|
|
|
|
##################################################################
|
|
# Refresh All peers SWARM Wallets.
|
|
##################################################################
|
|
ipfs_swarm_wallets_refresh "SIMPLE"
|
|
|
|
################################################################################
|
|
# PRINT G1Tag
|
|
# 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"
|
|
mkdir -p ./wallets/.$IPFSNODEID/PRINT/
|
|
|
|
for qrrtag in ./wallets_swarm/.$IPFSNODEID/PRINT/*.bin; do
|
|
rr=$(echo $qrrtag | cut -d '/' -f 5 | cut -d '.' -f 1)
|
|
if [[ ! -f "./wallets/.$IPFSNODEID/PRINT/done.$rr" ]]; then
|
|
log "__SUB:cron_MINUTE.sh: PRINT G1Tag $rr - START: $(date)"
|
|
./shell/natools.py decrypt -k "$MASTERKEYFILE" -i "${qrrtag}" -o "/tmp/G1Tag.png"
|
|
log "__SUB:cron_MINUTE.sh: natools.py decrypt - $(date)"
|
|
brother_ql_create --model QL-700 "/tmp/G1Tag.png" --label-size 62 > "/tmp/G1Tag.bin"
|
|
log "__SUB:cron_MINUTE.sh: brother_ql_create - $(date)"
|
|
brother_ql_print "/tmp/G1Tag.bin" /dev/usb/lp0
|
|
log "__SUB:cron_MINUTE.sh: brother_ql_print - $(date)"
|
|
# INFORM PRINT DONE
|
|
echo "OK" > ./wallets/.$IPFSNODEID/PRINT/done.$rr
|
|
I=$(ipfs_node_wallets_add)
|
|
else
|
|
lqrrtag=$(echo "${qrrtag}" | sed s/_swarm//g )
|
|
log "__SUB:cron_MINUTE.sh: REMOVE OLD DONE PRINT ${lqrrtag} + ./wallets/.$IPFSNODEID/PRINT/done.$rr"
|
|
rm -f "./wallets/.$IPFSNODEID/PRINT/done.$rr"
|
|
rm -f "${lqrrtag}"
|
|
I=$(ipfs_node_wallets_add)
|
|
fi
|
|
done
|
|
|
|
log "__SUB:cron_MINUTE.sh: REMOVE OLD PRINT MARKED AS DONE"
|
|
for scan in ./wallets_swarm/.Qm*/PRINT/done.*; do
|
|
lscan=$(echo $scan | sed s/_swarm//g )
|
|
lid=$(echo $scan | cut -d '/' -f 3 | cut -d '.' -f 2 )
|
|
lrr=$(echo $scan | cut -d '/' -f 5 | cut -d '.' -f 2 )
|
|
log "__SUB:cron_MINUTE.sh: REMOVE ./wallets/.$lid/PRINT/$lrr.bin OLD PRINT ${lscan} SENT to $lid ($lrr.bin)"
|
|
rm -f ./wallets/.$lid/PRINT/$lrr.bin
|
|
rm -f "${lscan}"
|
|
I=$(ipfs_node_wallets_add)
|
|
done
|
|
|
|
rm "/tmp/G1Tag.bin"
|
|
rm "/tmp/G1Tag.png"
|
|
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
|
|
##################################################################
|
|
fi
|
|
##################################################################
|
|
|