forked from axiom-team/astrXbian
384 lines
22 KiB
Bash
Executable File
384 lines
22 KiB
Bash
Executable File
#!/bin/bash -x
|
||
########################################################################
|
||
# Author: Fred (support@qo-op.com)
|
||
# Version: 0.3
|
||
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
||
########################################################################
|
||
# COPY ~/astroport/* files to IPFS
|
||
# Publish INDEX ~/.zen/ipfs/.*/${PREFIX}ASTRXBIAN
|
||
######## #### ### ## #
|
||
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);
|
||
IPFSNODEID=$(ipfs id -f='<id>\n')
|
||
G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
|
||
# ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN
|
||
# Astropot/Kodi/Vstream source reads ${PREFIX}ASTRXBIAN from http://127.0.0.1:8181/.$IPFNODEID/
|
||
# Index File Format (could be enhanced) is using Kodi TMDB enhancement
|
||
# https://github.com/Kodi-vStream/venom-xbmc-addons/wiki/Voir-et-partager-sa-biblioth%C3%A8que-priv%C3%A9e#d%C3%A9clarer-des-films
|
||
########################################################################
|
||
## RUN inotifywait process ~/astroport/ NEW FILE DETECT
|
||
# /usr/bin/inotifywait -r -e close_write -m /home/$YOU/astroport | while read dir flags file; do ~/.zen/astrXbian/zen/new_file_in_astroport.sh "$dir" "$file"; done &
|
||
# mkdir -p ~/astroport/youtube
|
||
# mkdir -p ~/astroport/mp3
|
||
########################################################################
|
||
path="$1"
|
||
# Add trailing / if needed
|
||
length=${#path}
|
||
last_char=${path:length-1:1}
|
||
[[ $last_char != "/" ]] && path="$path/"; :
|
||
|
||
file="$2"
|
||
|
||
echo "~/.zen/astrXbian/zen/new_file_in_astroport.sh PATH/ \"$path\" FILE \"$file\""
|
||
|
||
extension="${file##*.}"
|
||
TITLE="${file%.*}"
|
||
|
||
# .part file false flag correcting (inotify mode)
|
||
[[ ! -f "${path}${file}" ]] && file="${TITLE%.*}" && extension="${TITLE##*.}" && [[ ! -f "${path}${file}" ]] && er="NO FILE" && echo "$er" && exit 1
|
||
|
||
# GET XZUID
|
||
[[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title ]] && XZUID=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title) || XZUID=$(cat /etc/hostname)
|
||
[[ ! $(echo "$path" | cut -d '/' -f 4 | grep 'astroport') ]] && er="Les fichiers sont à placer dans ~/astroport/ MERCI" && echo "$er" && exit 1
|
||
TYPE=$(echo "$path" | cut -d '/' -f 5 ) # ex: /home/$YOU/astroport/... TYPE(film, youtube, mp3)/ REFERENCE /
|
||
CAT=$(echo "$TYPE" | awk '{ print tolower($0) }')
|
||
|
||
PREFIX=$(echo "$TYPE" | head -c 1 | awk '{ print toupper($0) }' ) # ex: F, Y, M ou Y
|
||
# File is placed in ROOT ~/astroport ?
|
||
if [[ $PREFIX == "" ]]
|
||
then
|
||
[[ "$USER" != "xbian" ]] && zenity --warning --width 300 --text "Désolé votre fichier ne peut pas être traité"
|
||
er="$er | WARNING. $TYPE is root file UNTREATED" && echo "$er" && exit 1
|
||
fi
|
||
|
||
[[ ! -d ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/ ]] && mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/
|
||
|
||
########################################################################
|
||
# EXTRACT INDEX REFERENCE : TMDB or YOUTUBE (can be extended with new )
|
||
########################################################################
|
||
case ${CAT} in
|
||
youtube)
|
||
INDEXPREFIX="YOUTUBE_"
|
||
REFERENCE=$(echo "$path" | cut -d '/' -f 6 )
|
||
TITLE="${file%.*}"
|
||
;;
|
||
mp3)
|
||
## DIFFERENT TREATMENT
|
||
INDEXPREFIX="MP3_"
|
||
REFERENCE=$(echo "$path" | cut -d '/' -f 6 )
|
||
TITLE=$(echo "$file" | cut -d "&" -f 2-)
|
||
er="$er | Please use new_mp3_in_astroport.sh ... EXIT"
|
||
echo "$er"
|
||
exit 1
|
||
;;
|
||
film | serie)
|
||
INDEXPREFIX="TMDB_"
|
||
REFERENCE=$(echo "$path" | cut -d '/' -f 6 ) # Path contains TMDB id
|
||
if ! [[ "$REFERENCE" =~ ^[0-9]+$ ]] # ${REFERENCE} NOT A NUMBER
|
||
then
|
||
er="$er | ERROR: $path BAD TMDB code. Get it from https://www.themoviedb.org/ or use your 06 phone number"
|
||
echo "$er"
|
||
exit 1
|
||
fi
|
||
;;
|
||
## TODO ADD "httrack" for website copying
|
||
## httrack "https://wiki.lowtechlab.org" -O "./wiki.lowtechlab.org" "+*.lowtechlab.org/*" -v -%l "fr"
|
||
##
|
||
*)
|
||
er="$CAT inconnu" && echo "$er" && exit 1
|
||
;;
|
||
esac
|
||
|
||
########################################################################
|
||
## CHECK if ${INDEXPREFIX}${REFERENCE} MEDIAKEY exists -> REFRESH DATA
|
||
########################################################################
|
||
echo "SEARCH for ;$REFERENCE; in ${PREFIX}ASTRXBIAN"
|
||
if [[ ${REFERENCE:0:1} != "0" ]]; then ## REFERENCE COULD BE A PHONE NUMBER (not in TMDB copy force)
|
||
isREFERENCEinINDEX=$(grep ";$REFERENCE;" ~/.zen/ipfs_swarm/.12D*/astroport/kodi/vstream/${PREFIX}ASTRXBIAN )
|
||
if [[ ${isREFERENCEinINDEX} ]]
|
||
then
|
||
if [[ -d ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB} ]]
|
||
then
|
||
# FILE IS MINE, NEW VERSION?! replacing it in INDEX
|
||
ipnslink=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.link)
|
||
echo "FOUND IPNS ${INDEXPREFIX}${REFERENCE} = $ipnslink"
|
||
|
||
# DELETING GCHANGE AD, WILL BE CREATED AGAIN
|
||
gchangeAD=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad)
|
||
~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" deleteoffer -i $gchangeAD
|
||
rm ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad
|
||
else
|
||
er="$er | FILE IS ALREADY EXISTING FROM ANOTHER FRIEND" && echo "$er"
|
||
## SEND messages to warn about need to Unify MEDIAKEY IPNS KEY
|
||
ipfsnodeid=$(echo ${isREFERENCEinINDEX} | tail -n 1 | cut -d '.' -f 3- | cut -d '/' -f 1)
|
||
destg1=$(~/.zen/astrXbian/zen/tools/ipfs_to_g1.py $ipfsnodeid)
|
||
[[ "$IPFSNODEID" != "$ipfsnodeid" ]] && ~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" send -d $destg1 -t "MEDIAKEY COLLISION ${INDEXPREFIX}${REFERENCE}" -m "Conflit de MEDIAKEY. Choisir quelle clef IPNS conserver..."
|
||
##
|
||
fi
|
||
fi
|
||
fi
|
||
|
||
########################################################################
|
||
echo "ADDING ${path}${file} to IPFS and create ${PREFIX}ASTRXBIAN INDEX"
|
||
echo "~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN"
|
||
echo "-----------------------------------------------------------------"
|
||
|
||
IPFS=$(ipfs add -wq "${path}${file}")
|
||
IPFSREPFILEID=$(echo $IPFS | cut -d ' ' -f 2)
|
||
IPFSID=$(echo $IPFS | cut -d ' ' -f 1)
|
||
[[ $IPFSREPFILEID == "" ]] && echo "ipfs add ERROR" && exit 1
|
||
echo "-----------------------------------------------------------------"
|
||
echo "IPFS: $file : ipfs ls /ipfs/$IPFSREPFILEID"
|
||
echo "-----------------------------------------------------------------"
|
||
echo "New $TYPE INDEX ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN "
|
||
|
||
URLENCODE_FILE_NAME=$(echo ${file} | jq -Rr @uri)
|
||
|
||
### MEDIAKEY FORGE
|
||
########################################################################
|
||
## CREATE NEW ipns KEY : ${INDEXPREFIX}${REFERENCE}
|
||
########################################################################
|
||
## IPFS SELF IPNS DATA STORAGE
|
||
## ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/
|
||
########################################################################
|
||
if [[ ! $(ipfs key list | grep "${INDEXPREFIX}${REFERENCE}") ]]; then
|
||
## IPNS KEY CREATION
|
||
mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}
|
||
KEY=$(ipfs key gen "${INDEXPREFIX}${REFERENCE}")
|
||
KEYFILE=$(ls -t ~/.ipfs/keystore/ | head -n 1)
|
||
fi
|
||
|
||
## IS IT NEW IPNS KEY?
|
||
if [[ $KEY ]]; then
|
||
# memorize IPNS key filename for easiest exchange
|
||
echo "$KEYFILE" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.key.keystore_filename
|
||
# Publishing IPNS key
|
||
echo "$KEY" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.link
|
||
# CREATE .zen = ZEN economic value
|
||
touch ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.zen
|
||
# CREATE other encrypted copies for friends depending DEFCON & stars
|
||
# > STARGATE 1 - 2 - 3 - 4 - 5 !!
|
||
################ ENCRYPT keystore/$KEYFILE
|
||
else
|
||
## OLD IPNS KEY
|
||
KEY=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.link)
|
||
KEYFILE=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.key.keystore_filename)
|
||
fi
|
||
|
||
[[ ! $KEY ]] && echo "FATAL ERROR" && exit 1
|
||
########################################################################
|
||
## add default metadata (TODO = use json file?)
|
||
########################################################################
|
||
echo "${file}" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipfs.filename
|
||
echo "${TITLE}" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.title
|
||
echo "$(date -u +%s%N | cut -b1-13)" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.timestamp
|
||
## INIT MEDIAKEY .views.counter
|
||
echo "0" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.views.counter
|
||
########################################################################
|
||
|
||
########################################################################
|
||
# Prepare IPFS links (then cyphered to manage exchange regulation)
|
||
########################################################################
|
||
echo "/ipfs/$IPFSREPFILEID/${file}" > /tmp/.ipfs.filelink
|
||
echo "$IPFSID" > /tmp/.ipfsid
|
||
########################################################################
|
||
|
||
########################################################################
|
||
################ ask autoPIN to one shuffle A_boostrap_nodes
|
||
########################################################################
|
||
PINIPFSnode=$(cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep -Ev "#" | shuf | tail -n 1)
|
||
nodeid=${PINIPFSnode##*/}
|
||
PINnode=$(~/.zen/astrXbian/zen/tools/ipfs_to_g1.py $nodeid)
|
||
|
||
echo "ASK AUTOPIN to $PINnode"
|
||
## CREATE $PINnode IPFS communication directory
|
||
[[ ! -d ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/${PINnode} ]] && mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/${PINnode}
|
||
## ENCRYPT .ipfsid & .ipfs.filelink
|
||
$MY_PATH/tools/natools.py encrypt -p $PINnode -i /tmp/.ipfs.filelink -o "~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/${PINnode}/.ipfs.filelink.encrypt"
|
||
$MY_PATH/tools/natools.py encrypt -p $PINnode -i /tmp/.ipfsid -o "~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/${PINnode}/.ipfsid.encrypt"
|
||
|
||
########################################################################
|
||
## GREAT natools can convert IPNS MEDIAKEY into .dunikey file
|
||
########################################################################
|
||
# CREATING QRCODE
|
||
$MY_PATH/tools/natools.py privkey -f ipfs-keystore -k $HOME/.ipfs/keystore/$KEYFILE -F pubsec -o /tmp/${INDEXPREFIX}${REFERENCE}.dunikey
|
||
# PubFromDunikey=$(cat /tmp/${INDEXPREFIX}${REFERENCE}.dunikey | grep "sec" | cut -d ' ' -f2 | base58 -d | tail -c+33 | base58)
|
||
PubFromDunikey=$(cat /tmp/${INDEXPREFIX}${REFERENCE}.dunikey | grep "pub" | cut -d ' ' -f2)
|
||
qrencode -s 6 -o "$HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/QR.png" "$PubFromDunikey"
|
||
|
||
|
||
########################################################################
|
||
## MEDIAKEY => DUNIKEY / 6 DIGITS openssl protection
|
||
########################################################################
|
||
PASS=$(echo "000000${RANDOM:0:6}" | tail -c-7) && echo "$PASS" > /tmp/${INDEXPREFIX}${REFERENCE}.pass
|
||
openssl enc -aes-256-cbc -salt -in /tmp/${INDEXPREFIX}${REFERENCE}.dunikey -out "$HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/dunikey.enc" -k $PASS
|
||
# DECODE openssl enc -aes-256-cbc -d -in file.txt.enc -out file.txt -k $PASS
|
||
|
||
## STATION & BOOTSTRAP ACCESS TO PASS
|
||
$MY_PATH/tools/natools.py encrypt -p $G1PUB -i /tmp/${INDEXPREFIX}${REFERENCE}.pass -o $HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.pass.encrypt
|
||
$MY_PATH/tools/natools.py encrypt -p $PINnode -i /tmp/${INDEXPREFIX}${REFERENCE}.pass -o $HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/${PINnode}/.pass.encrypt
|
||
|
||
|
||
########################################################################
|
||
## PREPARE .ipns.mediakey.encrypt FOR PINnode TO BE ABLE TO REFRESH MEDIAKEY
|
||
# used in ipns_TAG_refresh.sh & autoPINfriends.sh
|
||
########################################################################
|
||
$MY_PATH/tools/natools.py encrypt -p $PINnode -i $HOME/.ipfs/keystore/$KEYFILE -o $HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/${PINnode}/.ipns.mediakey.encrypt
|
||
|
||
## Init zen, views counters & visitor
|
||
echo "0" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/${PINnode}/.zen
|
||
echo "0" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/${PINnode}/.views.counter
|
||
echo "anonymous" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/${PINnode}/.visitor
|
||
########################################################################
|
||
# MEMORIZE my PIN
|
||
mkdir -p ~/.zen/PIN/${IPFSREPFILEID}/
|
||
touch ~/.zen/PIN/${IPFSREPFILEID}/${G1PUB}
|
||
|
||
########################################################################
|
||
## encrypt links for myself
|
||
########################################################################
|
||
$MY_PATH/tools/natools.py encrypt -p ${G1PUB} -i /tmp/.ipfs.filelink -o ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipfs.filelink.natools.encrypt
|
||
$MY_PATH/tools/natools.py encrypt -p ${G1PUB} -i /tmp/.ipfsid -o ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipfsid.encrypt
|
||
rm /tmp/.ipfs.filelink
|
||
rm /tmp/.ipfsid
|
||
########################################################################
|
||
|
||
########################################################################
|
||
## ADD "ajouter_video.txt" and "video.json" will be SELF IPNS publish data
|
||
[[ -f ~/astroport/${TYPE}/${REFERENCE}/ajouter_video.txt ]] && cp -f ~/astroport/${TYPE}/${REFERENCE}/ajouter_video.txt ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/
|
||
[[ -f ~/astroport/${TYPE}/${REFERENCE}/video.json ]] && cp -f ~/astroport/${TYPE}/${REFERENCE}/video.json ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/
|
||
########################################################################
|
||
|
||
########################################################################
|
||
## EXPLANATIONS
|
||
########################################################################
|
||
# What is being in ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/
|
||
# is published on http://127.0.0.1:8181/ipns/$KEY/
|
||
########################################################################
|
||
########################################################################
|
||
# CONTRACTS, are small App (fulljs or jquery + nginx backend app server)
|
||
# They must decrypt IPFS after succeeding a chalenge (, +/- n zen, ...)
|
||
########################################################################
|
||
# Contract App Examples (ipns_TAG_refresh.sh makes MEDIAKEY evolution)
|
||
# Counting video views = +1 .views.counter => decrypt key
|
||
# Balancing Zen wallets = -n form source = +n for destination => decrypt key
|
||
########################################################################
|
||
# Astroport/Gchange USE as public/private media copy friend of friends swarm
|
||
# one star level (no encrypt)
|
||
# index.html is presenting Astroport/Kodi service then redirect to
|
||
# $G1PUB/index.html contains redirection to ipfs link
|
||
########################################################################
|
||
|
||
########################################################################
|
||
## IPNS access to index.html
|
||
## Level 1 (not crypted) -> Redirect to ipfs streaming link
|
||
## Modified by "./zen/ipns_TAG_refresh.sh" (add crypto/contracts there)
|
||
echo "<meta http-equiv=\"Refresh\" content=\"0;URL=http://127.0.0.1:8181/ipfs/$IPFSREPFILEID/$URLENCODE_FILE_NAME\">" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/index.html
|
||
|
||
IPNSLINK=$(ipfs key list -l | grep ${INDEXPREFIX}${REFERENCE} | cut -d ' ' -f 1)
|
||
echo "<meta charset=\"UTF-8\"><meta http-equiv=\"Refresh\" content=\"10;URL=https://tube.copylaradio.com/ipns/$IPNSLINK/${G1PUB}/\">
|
||
<h1><a href='https://astroport.com'>Astroport</a>/KODI</h1>
|
||
Ce média ${TITLE} vient d'être ajouté au Video Club P2P... Libre et légal<br>
|
||
<h2>Découvrez <a href='https://copylaradio.com'>astrXbian</a></h2>
|
||
Lancement de la lecture localhost dans 10 secondes...<br><br>
|
||
<br><a href=\"https://www.gchange.fr/#/app/user/${G1PUB}/\">
|
||
<img width=222 src=\"https://tube.copylaradio.com/ipns/$IPNSLINK/QR.png\"></a>
|
||
<br><br><b>QR Code du portefeuille du media (${id}) et lien vers son garant.</b>
|
||
<br>envoyez un virement pour le conserver en ligne... Et offrir de la monnaie libre à son créateur." > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/index.html
|
||
|
||
## COPY LOCALHOST IPFS URL TO CLIPBOARD
|
||
[[ $(which xclip) ]] && echo "http://127.0.0.1:8181/ipfs/$IPFSREPFILEID/$URLENCODE_FILE_NAME" | xclip -selection c
|
||
|
||
|
||
########################################################################
|
||
########################################################################
|
||
## PUBLISH new IPNS
|
||
########################################################################
|
||
NEWIPFS=$(ipfs add -rHq ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/ | tail -n 1 )
|
||
IPNS=$(ipfs name publish --quieter --key="${INDEXPREFIX}${REFERENCE}" $NEWIPFS)
|
||
########################################################################
|
||
########################################################################
|
||
|
||
########################################################################
|
||
# POST TRAITEMENTS
|
||
########################################################################
|
||
# film/serie PUBLISH "ajouter_video.txt" for KODI
|
||
########################################################################
|
||
if [[ "${CAT}" =~ ^(film|serie|youtube)$ ]]
|
||
then
|
||
## CREATE GCHANGE AD
|
||
if [[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad && "${CAT}" != "youtube" ]]
|
||
then
|
||
GOFFER=$(~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" setoffer -t "${TITLE} #astroport #${INDEXPREFIX}${REFERENCE}" -d "${TITLE} https://tube.copylaradio.com/ipns/$IPNS/ Faites un don à son portefeuille pour le conserver dans le Mediacenter des Amis - #CopyLaRadio - https://astroport.com" -p $HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/QR.png)
|
||
echo $GOFFER > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad
|
||
NEWIPFS=$(ipfs add -rHq ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/ | tail -n 1 )
|
||
IPNS=$(ipfs name publish --quieter --key="${INDEXPREFIX}${REFERENCE}" $NEWIPFS)
|
||
fi
|
||
echo "Annonce gchange : $(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad)"
|
||
|
||
########################################################################
|
||
# ${PREFIX}ASTRXBIAN FILE : Add Header
|
||
[[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN ]] \
|
||
&& echo "CAT;TMDB;YEAR;TITLE;SAISON;GENRES;GROUPES;RES;URLS=http://127.0.0.1:8181" > ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN
|
||
|
||
# ADD NEW LINE TO INDEX
|
||
if [[ -f ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/ajouter_video.txt ]]
|
||
then
|
||
line=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/ajouter_video.txt | sed "s/_IPFSREPFILEID_/$IPFSREPFILEID/g" | sed "s/_IPNSKEY_/$IPNS/g" )
|
||
else
|
||
FILE_RES=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "${path}${file}" | cut -d "x" -f 2)
|
||
RES=${FILE_RES%?}0p
|
||
line="$CAT;${REFERENCE};$YEAR;$TITLE;$SAISON;;${IPNS};$RES;/ipfs/$IPFSREPFILEID/$URLENCODE_FILE_NAME"
|
||
fi
|
||
echo "-------------------- UPDATE MY INDEX -----------------------------"
|
||
echo "$line"
|
||
echo "$line" >> ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN
|
||
echo "UPDATE IPNS ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/ajouter_video.txt"
|
||
echo "$line" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/ajouter_video.txt
|
||
## UPDATE SOURCE ajouter_video.txt FILE
|
||
cp -f ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/ajouter_video.txt ~/astroport/${TYPE}/${REFERENCE}/ajouter_video.txt
|
||
########################################################################
|
||
## TODO: ACTIVATE SUB DEFCON 4 MODE = encrypt/decrypt file in $G1DEST subdirectory
|
||
########################################################################
|
||
|
||
echo "----------------- REFRESH LOCAL KODI INDEX ----------------------"
|
||
cat ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN ~/.zen/ipfs_swarm/.12D*/astroport/kodi/vstream/${PREFIX}ASTRXBIAN | sort | uniq > ~/.zen/ipfs/.${IPFSNODEID}/${PREFIX}ASTRXBIAN
|
||
fi
|
||
|
||
########################################################################
|
||
# PUBLISH GENERAL video
|
||
########################################################################
|
||
if [[ "${CAT}" == "video" ]]
|
||
then
|
||
## REPLACE IPFS / IPNS REFERENCE IN video.json (Maybe cyphered later)
|
||
cat ~/astroport/${CAT}/${INDEXPREFIX}${REFERENCE}/video.json | sed "s/_IPFSREPFILEID_/$IPFSREPFILEID/g" | sed "s/_IPNSKEY_/$IPNS/g" >> ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN
|
||
|
||
fi
|
||
|
||
########################################################################
|
||
# PUBLISH YOUTUBE video to /astroport/wordpress/
|
||
########################################################################
|
||
if [[ "${CAT}" == "youtube" ]]
|
||
then
|
||
## CREATE astroport call to Astroport/Wordpress stations
|
||
if [[ ! -d ~/.zen/ipfs/.$IPFSNODEID/astroport/wordpress/${INDEXPREFIX}${REFERENCE} ]]; then
|
||
mkdir -p ~/.zen/ipfs/.$IPFSNODEID/astroport/wordpress/${INDEXPREFIX}${REFERENCE}
|
||
echo "1" > ~/.zen/ipfs/.$IPFSNODEID/astroport/wordpress/${INDEXPREFIX}${REFERENCE}/do
|
||
fi
|
||
fi
|
||
|
||
########################################################################
|
||
|
||
########################################################################
|
||
# REFRESH IPNS SELF PUBLISH
|
||
########################################################################
|
||
~/.zen/astrXbian/zen/ipns_self_publish.sh
|
||
########################################################################
|
||
echo "DUNIKEY PASS $PASS"
|
||
echo "NEW $TYPE ($file) ADDED. http://127.0.0.1:8181/ipfs/$IPFSREPFILEID/$URLENCODE_FILE_NAME"
|
||
echo "INDEX UPDATED : http://127.0.0.1:8181/ipns/${IPFSNODEID}/.${IPFSNODEID}/${PREFIX}ASTRXBIAN"
|
||
echo "VIDEO IPNS LINK : http://127.0.0.1:8181/ipns/$KEY/$G1PUB/"
|
||
exit 0
|