2021-04-04 22:42:15 +02:00
|
|
|
#!/bin/bash
|
|
|
|
########################################################################
|
|
|
|
# Author:
|
|
|
|
# Version: 0.1
|
|
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
|
|
########################################################################
|
2021-04-05 00:27:06 +02:00
|
|
|
# Take care about Astroport/Wordpress "do/done" publication process
|
2021-04-04 22:42:15 +02:00
|
|
|
########################################################################
|
|
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
|
|
ME="${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 "ERREUR G1PUB. EXIT" && exit 1
|
|
|
|
IPFSNODEID=$(ipfs id -f='<id>\n')
|
|
|
|
[[ -f ~/.zen/ipfs/.$IPFSNODEID/_xbian.zuid ]] && AXID=$(cat ~/.zen/ipfs/.$IPFSNODEID/_xbian.zuid);
|
|
|
|
[[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title ]] && XZUID=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title)
|
|
|
|
|
2021-04-07 01:55:36 +02:00
|
|
|
channel="$1" && [[ "$channel" == "" ]] && channel="wordpress"
|
|
|
|
|
2021-04-04 22:42:15 +02:00
|
|
|
## CREATION DE LA ZONE DE DIALOGUE IPFS SWARM
|
2021-04-07 01:55:36 +02:00
|
|
|
for wpcall in $(ls -d ~/.zen/ipfs_swarm/.12D*/astroport/${channel}/*);
|
2021-04-04 22:42:15 +02:00
|
|
|
do
|
2021-04-05 01:14:11 +02:00
|
|
|
echo "$wpcall" && ls $wpcall
|
2021-04-04 22:42:15 +02:00
|
|
|
ipfnodesource=$(echo "$wpcall" | cut -d '/' -f 6 | cut -d '.' -f 2 )
|
|
|
|
g1pubsource=$($MY_PATH/tools/ipfs_to_g1.py $ipfnodesource)
|
|
|
|
mediakey=$(echo "$wpcall" | cut -d '/' -f 9 )
|
2021-04-05 01:20:13 +02:00
|
|
|
|
2021-04-05 02:34:38 +02:00
|
|
|
if [[ -f $wpcall/do ]]; then
|
|
|
|
istodo=$(cat "$wpcall/do") && echo "istodo=$istodo"
|
2021-04-07 01:55:36 +02:00
|
|
|
istodoswarm=$(ipfs cat /ipns/$ipfnodesource/.$ipfnodesource/astroport/${channel}/$mediakey/do) && echo "istodoswarm=$istodoswarm"
|
2021-04-06 01:38:06 +02:00
|
|
|
[[ "$istodo" != "$istodoswarm" && "$istodoswarm" != "" ]] && itodo="$istodoswarm"
|
2021-04-05 02:34:38 +02:00
|
|
|
isdone=$(cat "$wpcall/done") && echo "isdone=$isdone"
|
2021-04-07 01:55:36 +02:00
|
|
|
isdoneswarm=$(ipfs cat /ipns/$istodo/.$ipfnodesource/astroport/${channel}/$mediakey/done) && echo "isdoneswarm=$isdoneswarm"
|
2021-04-06 01:38:06 +02:00
|
|
|
[[ "$isdone" != "$isdoneswarm" && "$isdoneswarm" != "" ]] && isdone="$isdoneswarm"
|
|
|
|
else
|
|
|
|
continue
|
2021-04-05 02:34:38 +02:00
|
|
|
fi
|
2021-04-06 01:38:06 +02:00
|
|
|
echo "istodo=$istodo isdone=$isdone"
|
2021-04-08 04:05:57 +02:00
|
|
|
if [[ "$ipfnodesource" != "$IPFSNODEID" ]]; then
|
2021-04-05 00:27:06 +02:00
|
|
|
[[ ! $(which wp) ]] && continue # MUST RUN WORDPRESS and wp-cli
|
|
|
|
if [[ $istodo && ! $isdone ]]; then
|
2021-04-05 01:06:51 +02:00
|
|
|
[[ "$istodo" == "$IPFSNODEID" ]] && echo "Already DONE by $istodo" && continue
|
2021-04-05 00:27:06 +02:00
|
|
|
## I am the destination of that "todo / not done" wpcall
|
|
|
|
echo "$ipfnodesource wants to publish $mediakey"
|
|
|
|
## GET ipns link + title + xzuid
|
2021-04-06 14:46:23 +02:00
|
|
|
title=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/.title | sed "s/_/ /g")
|
2021-04-05 00:27:06 +02:00
|
|
|
xzuid=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/_xbian.zuid)
|
2021-04-06 19:36:43 +02:00
|
|
|
tags=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/video.json | jq -c .tags | sed 's/[][]//g' | sed "s/\"//g" )
|
2021-04-05 00:27:06 +02:00
|
|
|
|
|
|
|
mynodename=$(cat ~/.zen/ipfs_swarm/.$IPFSNODEID/G1SSB/_nodename)
|
2021-04-06 01:38:06 +02:00
|
|
|
genres="$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/ajouter_video.txt | cut -d ';' -f 6 | sed 's/|/,/g' | awk '{print tolower($0)}')"
|
2021-04-08 04:22:31 +02:00
|
|
|
[[ "$tags" != "null" ]] && tags="$genres,$tags" || tags="$genres"
|
2021-04-06 19:36:43 +02:00
|
|
|
|
|
|
|
description=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/video.json | jq -cr .description)
|
2021-04-08 03:49:52 +02:00
|
|
|
[[ $description ]] && description=$(echo "${description//$'\n'/<br>}") || description="SAUVEGARDE VIDEO ASTROPORT"
|
2021-04-05 00:27:06 +02:00
|
|
|
|
2021-04-06 03:20:16 +02:00
|
|
|
## USE .ipns.link
|
|
|
|
# ipnsid=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/.ipns.link)
|
|
|
|
## USE .ipfs.filelink
|
|
|
|
if [[ -f ~/.zen/ipfs_swarm/.${ipfnodesource}/KEY/${mediakey}/${g1pubsource}/${G1PUB}/.ipfs.filelink.encrypt ]]; then
|
|
|
|
$MY_PATH/tools/natools.py decrypt -f pubsec -k "$HOME/.zen/secret.dunikey" -i "$HOME/.zen/ipfs_swarm/.${ipfnodesource}/KEY/${mediakey}/${g1pubsource}/${G1PUB}/.ipfs.filelink.encrypt" -o "/tmp/filelink_$mediakey.txt"
|
2021-04-07 01:50:36 +02:00
|
|
|
hipfs=$(cat /tmp/filelink_$mediakey.txt | cut -d '/' -f 3)
|
|
|
|
gname="$(cat /tmp/filelink_$mediakey.txt | cut -d '/' -f 4 | jq -Rr @uri)"
|
2021-05-14 13:55:00 +02:00
|
|
|
zeeurl="https://$mynodename/ipfs/$hipfs/$gname"
|
2021-04-07 01:50:36 +02:00
|
|
|
else
|
|
|
|
echo ".ipfs.filelink.encrypt is missing"
|
2021-04-06 03:20:16 +02:00
|
|
|
fi
|
|
|
|
|
2021-04-08 04:32:44 +02:00
|
|
|
## Prefer IPNS link to later control access
|
|
|
|
ipnsid=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/.ipns.link)
|
2021-05-14 13:55:00 +02:00
|
|
|
[[ "$zeeurl" == "" ]] && zurl="https://$mynodename/ipns/$ipnsid" || zurl="$zeeurl"
|
2021-04-08 04:32:44 +02:00
|
|
|
|
2021-04-05 00:27:06 +02:00
|
|
|
# 1=DIY, Habiter=2, Guerir=3, Divertir=4, Déplacer=5, Energie=6, Cultiver=7
|
2021-04-07 01:55:36 +02:00
|
|
|
cd /var/www/${channel}/
|
2021-04-06 02:47:04 +02:00
|
|
|
# isWPuser=$(wp user list | grep "$xzuid")
|
2021-05-16 09:21:30 +02:00
|
|
|
wp post create --post_author="$xzuid" --post_content="<h1><a href=\"$zurl\" target=\"_blank\" rel=\"noreferrer noopener\">VIDEO : $title</a></h1><center><video width='640' height='480'><source src=\"$zeeurl\"></video></center><p>$description</p>" --post_title="VIDEO : $title" --post_excerpt="$description" --post_category="105" --tags_input="$tags" --porcelain
|
2021-04-06 02:47:04 +02:00
|
|
|
|
2021-04-07 01:55:36 +02:00
|
|
|
# REPLY IN ~/.zen/ipfs/.$ipfnodesource/astroport/${channel}/$mediakey/done
|
2021-04-05 00:27:06 +02:00
|
|
|
responsedir="$(echo "$wpcall" | sed 's/ipfs_swarm/ipfs/g')"
|
|
|
|
mkdir -p $responsedir
|
2021-04-05 01:06:51 +02:00
|
|
|
echo "$IPFSNODEID" > $responsedir/do
|
2021-04-06 01:38:06 +02:00
|
|
|
echo "$IPFSNODEID" > $responsedir/done
|
2021-04-08 03:54:24 +02:00
|
|
|
else
|
|
|
|
echo '## I am the source of that "done" wpcall remove "do"'
|
|
|
|
[[ $isdone ]] && echo "DONE! Removing my do" && rm -Rf ~/.zen/ipfs/.$ipfnodesource/astroport/${channel}/$mediakey/do* && rm -f ~/.zen/ipfs_swarm/.$ipfnodesource/astroport/${channel}/$mediakey/do*
|
2021-04-05 00:27:06 +02:00
|
|
|
fi
|
|
|
|
else
|
2021-04-05 01:33:41 +02:00
|
|
|
echo '## I am the source of that "done" wpcall remove "do"'
|
2021-04-07 01:55:36 +02:00
|
|
|
[[ $isdone ]] && echo "DONE! Removing my do" && rm -Rf ~/.zen/ipfs/.$ipfnodesource/astroport/${channel}/$mediakey/do* && rm -f ~/.zen/ipfs_swarm/.$ipfnodesource/astroport/${channel}/$mediakey/do*
|
2021-04-05 00:27:06 +02:00
|
|
|
fi
|
2021-04-04 22:42:15 +02:00
|
|
|
|
2021-04-06 01:38:06 +02:00
|
|
|
## I am the destination of that "done / not todo" wpcall
|
2021-04-07 01:55:36 +02:00
|
|
|
[[ "$isdone" == "$IPFSNODEID" && ! $istodo ]] && echo "DONE not TODO. removing done" && rm -f ~/.zen/ipfs/.$ipfnodesource/astroport/${channel}/$mediakey/do* && rm -f ~/.zen/ipfs_swarm/.$ipfnodesource/astroport/${channel}/$mediakey/do*
|
2021-04-06 01:38:06 +02:00
|
|
|
|
2021-04-04 22:42:15 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
# REFRESH IPNS SELF PUBLISH
|
|
|
|
########################################################################
|
|
|
|
echo "******************************************************************"
|
|
|
|
echo "REFRESH IPNS SELF PUBLISH"
|
|
|
|
~/.zen/astrXbian/zen/ipns_self_publish.sh
|
|
|
|
########################################################################
|