2021-09-20 23:45:44 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
########################################################################
|
|
|
|
|
# Author: Astrocrew
|
|
|
|
|
# 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##*/}"
|
|
|
|
|
countMErunning=$(ps auxf --sort=+utime | grep -w $ME | grep -v -E 'color=auto|grep' | wc -l)
|
|
|
|
|
[[ $countMErunning -gt 2 ]] && echo "$ME already running $countMErunning time" && exit 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 "NO ~/.zen/secret.dunikey EXIT" && exit 1
|
|
|
|
|
IPFSNODEID=$(ipfs --timeout=20s id -f='<id>\n' 2>/dev/null) && [[ "$IPFSNODEID" == "" ]] && echo 'NO IPFS RUNNING. EXIT' && exit 1
|
|
|
|
|
[ ! -d ~/.zen/ipfs/.$IPFSNODEID/astroport ] && echo 'ASTROPORT NOT READY' && exit 1
|
|
|
|
|
|
2021-09-29 22:48:34 +02:00
|
|
|
|
|
|
|
|
|
###### MOVE MAP FROM SELF IPNS INDEX
|
|
|
|
|
if [ ! -d ~/.zen/ipfs/map ]; then
|
|
|
|
|
mv ~/.zen/ipfs/.$IPFSNODEID/astroport/map ~/.zen/
|
|
|
|
|
else
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
## TODO CREATE SPECIAL IPNS KEY FOR SHARING
|
|
|
|
|
|
2021-09-20 23:45:44 +02:00
|
|
|
|
##############################################################"
|
|
|
|
|
## DO NOT RECORD output.pdf, bu convert to jpg and link throug index.html REDIRECT
|
|
|
|
|
##############################################################"
|
|
|
|
|
|
|
|
|
|
for pdflink in $(ls ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/*/bulle.pdf); do
|
|
|
|
|
lid=$(echo $pdflink | cut -d '/' -f 11)
|
|
|
|
|
## PDF convert and crop to JPG / ipfs add / index.html for redirect
|
|
|
|
|
convert -density 200 -quality 80 $pdflink /tmp/bulle.jpg
|
|
|
|
|
convert -crop 1260x420+55+30 /tmp/bulle.jpg /tmp/$lid.jpg
|
|
|
|
|
|
|
|
|
|
IPFS=$(ipfs add -wq "/tmp/$lid.jpg") ## Add $lid.pdf to IPFS
|
|
|
|
|
IPFSREPFILEID=$(echo $IPFS | cut -d ' ' -f 2) ## Get repertory ipfs link
|
|
|
|
|
[[ "$IPFSREPFILEID" == "" ]] && echo "IPFS ADD TROUBLE. CONTINUE" && exit 1
|
|
|
|
|
## Create index.html with Redirect to /ipfs/$IPFSREPFILEID/$lid.jpg
|
|
|
|
|
echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=/ipfs/$IPFSREPFILEID/$lid.jpg\"></head></html>" > ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/index.html
|
|
|
|
|
# mv ./output.pdf ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/bulle.pdf
|
|
|
|
|
rm ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/bulle.pdf 2>/dev/null
|
|
|
|
|
echo "NOW LIEU redirect to http://127.0.0.1:8181/ipfs/$IPFSREPFILEID/$lid.jpg"
|
|
|
|
|
cat ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/index.html
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
exit 0
|