127 lines
5.6 KiB
Bash
127 lines
5.6 KiB
Bash
|
#!/bin/bash
|
||
|
################################################################################
|
||
|
# Author: Fred (support@qo-op.com)
|
||
|
# Version: 0.1
|
||
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
||
|
################################################################################
|
||
|
# EVERY minute cron
|
||
|
################################################################################
|
||
|
MY_PATH="`dirname \"$0\"`" # relative
|
||
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
||
|
ME="${0##*/}"
|
||
|
|
||
|
ipfsnodeid=$(ipfs id -f='<id>\n')
|
||
|
[[ ! -f ~/.ssb/secret.dunikey ]] && $MY_PATH/tools/secret2dunikey.sh
|
||
|
g1pub=$(cat ~/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
|
||
|
|
||
|
timebar=$(date +%H:%M)
|
||
|
|
||
|
function ipfs_swarm_wallets_refresh (){
|
||
|
|
||
|
mkdir -p "~/.zen/ipfs_swarm"
|
||
|
echo '
|
||
|
___ _ _ __ __ _ _ _ _ _ _ __
|
||
|
| |_)|_(_ (_\ //\ |_)|\/| |_)|_|_|_)|_(_ |_|
|
||
|
_|_| | __) __)\/\//--\| \| | | \|_| | \|___)| |
|
||
|
|
||
|
'
|
||
|
|
||
|
# GET IPNS published wallets from ALL SWARM NODES / TODO: IF NODES MISSING, check ./wallets_swarm/.QmNODES...
|
||
|
#log "__SUB:ipfs_swarm_wallets_refresh: IPFS: ipfs get --output=./wallets_swarm/ /ipns/$IPFSNODEID"
|
||
|
su $YOU -c "ipfs get --output=./wallets_swarm/ /ipns/$IPFSNODEID"
|
||
|
count=1
|
||
|
# Search for All peers Nodes. TODO: To be changed when Swarm is too bug or not expendanding
|
||
|
#for id in ./wallets/.Qm*/;
|
||
|
for id in $(su $YOU -c "ipfs swarm peers" | awk -F '/' '{print $7}');
|
||
|
do
|
||
|
count=$((count+1))
|
||
|
id=$(echo $id | cut -d '.' -f 3 | cut -d '/' -f 1)
|
||
|
log "__SUB:ipfs_swarm_wallets_refresh: IPFS: ipfs get --output=./wallets_swarm/ /ipns/$id"
|
||
|
rm -Rf ./wallets_swarm/.$id
|
||
|
./shell/timeout.sh -t 20 su $YOU -c "ipfs get --output=./wallets_swarm/ /ipns/$id"
|
||
|
done
|
||
|
|
||
|
##################################################################
|
||
|
if [[ "$1" == "" ]]; then
|
||
|
##################################################################
|
||
|
echo "It is $timebar in the morning, or in the night? It depends on your day..."
|
||
|
exit
|
||
|
fi
|
||
|
##################################################################
|
||
|
|
||
|
##################################################################
|
||
|
if [[ "$1" == "PRINT" ]]; then
|
||
|
##################################################################
|
||
|
##################################################################
|
||
|
# Refresh All peers SWARM Wallets.
|
||
|
##################################################################
|
||
|
ipfs_swarm_wallets_refresh "SIMPLE"
|
||
|
|
||
|
################################################################################
|
||
|
# PRINT G1Tag PRINTED FROM ANOTHER NODE (TODO: Correct BAD Cypher KEY + BUG why last image png layers are not printed???)
|
||
|
# 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 "$NODE_G1AUTHFILE" -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
|
||
|
fi
|
||
|
##################################################################
|
||
|
|
||
|
##################################################################
|
||
|
if [[ "$1" == "KALKUN" ]]; then
|
||
|
##################################################################
|
||
|
for number in ./wallets/*; do
|
||
|
member=""
|
||
|
phone=$(echo $number | cut -d '/' -f 3);
|
||
|
if [[ -f $number/$phone.uidname ]]; then member=$(cat $number/$phone.uidname); fi
|
||
|
if [[ ! $member ]]; then member=$phone; fi
|
||
|
if [[ $phone && $member ]]; then add_contact $phone $member; log "__SUB:cron_MINUTE.sh: KALKUN add_contact $phone $member"; fi
|
||
|
done
|
||
|
fi
|
||
|
##################################################################
|
||
|
|
||
|
##################################################################
|
||
|
if [[ "$1" == "TAG" ]]; then
|
||
|
##################################################################
|
||
|
for tag in ./TAG/*; do
|
||
|
echo $tag
|
||
|
done
|
||
|
fi
|
||
|
##################################################################
|