astrXbian/zen/wordpress_channel.sh

74 lines
3.7 KiB
Bash
Executable File

#!/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)
## CREATION DE LA ZONE DE DIALOGUE IPFS SWARM
for wpcall in $(ls -d ~/.zen/ipfs_swarm/.12D*/astroport/wordpress/*);
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 )
## REFRESH SWARM cache
$MY_PATH/tools/timeout.sh -t 12 ipfs get --output=/home/$YOU/.zen/ipfs_swarm/ /ipns/$ipfnodesource
[[ -f $wpcall/do ]] && istodo=$(cat $wpcall/do)
[[ -f $wpcall/done ]] && isdone=$(cat $wpcall/done)
[[ ! $isdone && ! $istodo ]] && continue
if [[ "$ipfsnodeid" != "$IPFSNODEID" ]]; then
[[ ! $(which wp) ]] && continue # MUST RUN WORDPRESS and wp-cli
## I am the destination of that "done / not todo" wpcall
[[ $isdone && ! $istodo ]] && echo rm -Rf ~/.zen/ipfs/.$ipfnodesource/astroport/wordpress/$mediakey
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
ipnsid=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/.ipns.link)
title=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/KEY/$mediakey/$g1pubsource/.title)
xzuid=$(cat ~/.zen/ipfs_swarm/.$ipfnodesource/_xbian.zuid)
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')"
# 1=DIY, Habiter=2, Guerir=3, Divertir=4, Déplacer=5, Energie=6, Cultiver=7
cd /var/www/wordpress/
isWPuser=$(wp user list | grep "$xzuid")
wp post create --post_author="$xzuid" --post_content="<p><a href=\"https://$mynodename/ipns/$ipnsid\" target=\"_blank\" rel=\"noreferrer noopener\">$title</a></p>" --post_title="$title" --post_excerpt="$g1pubsource" --tags_input="$genres" --porcelain
# REPLY IN ~/.zen/ipfs/.$ipfnodesource/astroport/wordpress/$mediakey/done
responsedir="$(echo "$wpcall" | sed 's/ipfs_swarm/ipfs/g')"
mkdir -p $responsedir
echo "$IPFSNODEID" > $responsedir/do
echo "1" > $responsedir/done
fi
else
## I am the source of that "done" wpcall remove "do"
[[ $isdone ]] && echo rm -f ~/.zen/ipfs/.$ipfnodesource/astroport/wordpress/$mediakey/do
fi
done
# REFRESH IPNS SELF PUBLISH
########################################################################
echo "******************************************************************"
echo "REFRESH IPNS SELF PUBLISH"
~/.zen/astrXbian/zen/ipns_self_publish.sh
########################################################################