G1sms/shell/cron_MINUTE.sh

116 lines
5.5 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
################################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
if [[ -f $MY_PATH/.install/.GPATH ]]; then source $MY_PATH/.install/.GPATH; fi
if [[ -f $MY_PATH/../.install/.GPATH ]]; then source $MY_PATH/../.install/.GPATH; fi
YOU=$(ps aux --sort=+utime | grep ipfs | tail -n 1 | cut -d " " -f 1)
if [[ "$USER" != "root" ]]; then echo "Hey, $USER you must at least be admin of your system (sudo $0)"; exit; fi
if [[ "$YOU" == "" || "$YOU" == "root" ]]; then echo "BAD IPFS. Aucune installation IPFS satisfaisante ici... Ciao $YOU !"; exit; fi
IPFSNODEID=$(su $YOU -c "ipfs id -f='<id>\n'")
cd $GPATH
source ./shell/init.sh
source ./shell/functions.sh
timebar=$(date +%H:%M)
##################################################################
if [[ "$1" == "" ]]; then
##################################################################
echo "It is $timebar in the morning, or in the night? It depends on your day..."
exit
fi
##################################################################
################################################################################
# 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"
## mkdir -p ./wallets/.$IPFSNODEID/PRINT/
##################################################################
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_G1PRIVKEYFILE" -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
##################################################################