You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

102 lines
6.1 KiB

#!/bin/bash
########################################################################
# Author:
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
# Take care about Astroport/Wordpress "do/done" publication process
########################################################################
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)
channel="$1" && [[ "$channel" == "" ]] && channel="wordpress"
## CREATION DE LA ZONE DE DIALOGUE IPFS SWARM
for wpcall in $(ls -d ~/.zen/ipfs_swarm/.12D*/astroport/${channel}/*);
do
echo "$wpcall" && ls $wpcall
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 )
if [[ -f $wpcall/do ]]; then
istodo=$(cat "$wpcall/do") && echo "istodo=$istodo"
istodoswarm=$(ipfs cat /ipns/$ipfnodesource/.$ipfnodesource/astroport/${channel}/$mediakey/do) && echo "istodoswarm=$istodoswarm"
[[ "$istodo" != "$istodoswarm" && "$istodoswarm" != "" ]] && itodo="$istodoswarm"
isdone=$(cat "$wpcall/done") && echo "isdone=$isdone"
isdoneswarm=$(ipfs cat /ipns/$istodo/.$ipfnodesource/astroport/${channel}/$mediakey/done) && echo "isdoneswarm=$isdoneswarm"
[[ "$isdone" != "$isdoneswarm" && "$isdoneswarm" != "" ]] && isdone="$isdoneswarm"
else
continue
fi
echo "istodo=$istodo isdone=$isdone"
if [[ "$ipfnodesource" != "$IPFSNODEID" ]]; then
[[ ! $(which wp) ]] && continue # MUST RUN WORDPRESS and wp-cli
if [[ $istodo && ! $isdone ]]; then
[[ "$istodo" == "$IPFSNODEID" ]] && echo "Already DONE by $istodo" && continue
## I am the destination of that "todo / not done" wpcall
echo "$ipfnodesource wants to publish $mediakey"
## GET ipns link + title + xzuid
title=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/.title | sed "s/_/ /g")
xzuid=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/_xbian.zuid)
tags=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/video.json | jq -c .tags | sed 's/[][]//g' | sed "s/\"//g" )
mynodename=$(cat ~/.zen/ipfs_swarm/.$IPFSNODEID/G1SSB/_nodename)
genres="$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/ajouter_video.txt | cut -d ';' -f 6 | sed 's/|/,/g' | awk '{print tolower($0)}')"
[[ "$tags" != "null" ]] && tags="$genres,$tags" || tags="$genres"
description=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/video.json | jq -cr .description)
[[ $description ]] && description=$(echo "${description//$'\n'/<br>}") || description="SAUVEGARDE VIDEO ASTROPORT"
## 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"
hipfs=$(cat /tmp/filelink_$mediakey.txt | cut -d '/' -f 3)
gname="$(cat /tmp/filelink_$mediakey.txt | cut -d '/' -f 4 | jq -Rr @uri)"
zeeurl="https://$mynodename/ipfs/$hipfs/$gname"
else
echo ".ipfs.filelink.encrypt is missing"
fi
## Prefer IPNS link to later control access
ipnsid=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/.ipns.link)
[[ "$zeeurl" == "" ]] && zurl="https://$mynodename/ipns/$ipnsid" || zurl="$zeeurl"
# 1=DIY, Habiter=2, Guerir=3, Divertir=4, Déplacer=5, Energie=6, Cultiver=7
cd /var/www/${channel}/
# isWPuser=$(wp user list | grep "$xzuid")
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=\"$zurl\"></video></center><p>$description</p>" --post_title="VIDEO : $title" --post_excerpt="$description" --post_category="105" --tags_input="$tags" --porcelain
# REPLY IN ~/.zen/ipfs/.$ipfnodesource/astroport/${channel}/$mediakey/done
responsedir="$(echo "$wpcall" | sed 's/ipfs_swarm/ipfs/g')"
mkdir -p $responsedir
echo "$IPFSNODEID" > $responsedir/do
echo "$IPFSNODEID" > $responsedir/done
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*
fi
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*
fi
## I am the destination of that "done / not todo" wpcall
[[ "$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*
done
# REFRESH IPNS SELF PUBLISH
########################################################################
echo "******************************************************************"
echo "REFRESH IPNS SELF PUBLISH"
~/.zen/astrXbian/zen/ipns_self_publish.sh
########################################################################