diff --git a/zen/tools/autoPINfriends.sh b/zen/tools/autoPINfriends.sh index 3590e7b..41baacd 100755 --- a/zen/tools/autoPINfriends.sh +++ b/zen/tools/autoPINfriends.sh @@ -20,8 +20,10 @@ G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) # MEDIAKEY: ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/${PINnode}/.ipns.mediakey.encrypt ## AUTO PIN FRIENDS ACTIVATION +## TODO Source should rename ".ipfsid.encrypt" to stop asking for autoPIN for astrofile in $(ls -dt ~/.zen/ipfs_swarm/.12D*/KEY/*/*/${G1PUB}/.ipfsid.encrypt | shuf); do + astrofilelinksec=$(echo "$astrofile" | sed "s/.ipfsid.encrypt/.ipfs.filelink.encrypt/g") # decrypt $astrofile mediakey=$(echo "$astrofile" | cut -d '/' -f 8 ) keytype=$(echo "$mediakey" | cut -d '_' -f 1 ) @@ -31,17 +33,19 @@ do ipfsnodesource=$(~/.zen/astrXbian/zen/tools/g1_to_ipfs.py $g1source) echo "$mediakey PINNING ASKED BY $g1source" - ## VERIFY CONTRACT... TODO + ## DECRYPT FINAL IPFS LINKS... $MY_PATH/natools.py decrypt -f pubsec -k "$HOME/.zen/secret.dunikey" -i "$astrofile" -o "/tmp/ipfslink.txt" - astrofile=$(cat /tmp/ipfslink.txt) - # PINNING NEW FILE - echo "SHOULD I PIN ~/.zen/PIN/${astrofile} ??" - if [[ ! -d ~/.zen/PIN/${astrofile} ]]; + astrofile=$(cat /tmp/ipfslink.txt) && [[ -d ~/.zen/PIN/${astrofile} ]] && rm -Rf ~/.zen/PIN/${astrofile}/ ## REMOVE OLD PIN REFERENCE to keep directory (easier reading) + $MY_PATH/natools.py decrypt -f pubsec -k "$HOME/.zen/secret.dunikey" -i "$astrofilelinksec" -o "/tmp/ipfsfilelink.txt" + ipfsrepidfile=$(cat /tmp/ipfsfilelink.txt | rev | cut -d '/' -f 2 | rev) + # PINNING NEW DIRECTORY & FILE + echo "SHOULD I PIN ~/.zen/PIN/${ipfsrepidfile} ??" + if [[ ! -d ~/.zen/PIN/${ipfsrepidfile} ]]; then - echo "PIN : $astrofile" - ipfs pin add /ipfs/$astrofile && mkdir -p ~/.zen/PIN/${astrofile}/ + echo "PIN ADD : $ipfsrepidfile" + ipfs pin add /ipfs/$ipfsrepidfile && mkdir -p ~/.zen/PIN/${ipfsrepidfile}/ echo "RECORDING MY PIN ~/.zen/PIN/" - [[ -d ~/.zen/PIN/${astrofile} ]] && echo "0" > ~/.zen/PIN/${astrofile}/$G1PUB + [[ -d ~/.zen/PIN/${ipfsrepidfile} ]] && echo "$ipfsnodesource" > ~/.zen/PIN/${ipfsrepidfile}/$G1PUB ## COPY IPNS MEDIAKEY TO ipfs keystore (UPDATE IF STATION OFF) echo "ADD ${mediakey} to my local keystore (SO I CAN UPDATE IPNS LINK LATER with ipns_TAG_refresh.sh)" @@ -50,8 +54,8 @@ do if [[ -f /tmp/ipns.mediakey ]]; then KEYFILE=$($MY_PATH/give_me_keystore_filename.py "${mediakey}") [[ ! -f ~/.ipfs/keystore/$KEYFILE ]] && mv /tmp/ipns.mediakey ~/.ipfs/keystore/$KEYFILE || ( echo "$KEYFILE already existing in local keystore. EXIT" && continue ) - echo "${mediakey}" > ~/.zen/PIN/${astrofile}/MEDIAKEY - echo "$(ipfs key list -l | grep ${mediakey} | cut -d ' ' -f 1)" > ~/.zen/PIN/${astrofile}/IPNSLINK + echo "${mediakey}" > ~/.zen/PIN/${ipfsrepidfile}/MEDIAKEY + echo "$(ipfs key list -l | grep ${mediakey} | cut -d ' ' -f 1)" > ~/.zen/PIN/${ipfsrepidfile}/IPNSLINK ## USED BY BOOTSTRAP IN ipns_TAG_refresh.sh TO REFRESH MEDIAKEY publishing fi fi @@ -67,7 +71,7 @@ do [[ "$keytype" == "TMDB" ]] && cat ~/.zen/ipfs_swarm/.12D*/astroport/kodi/vstream/FASTRXBIAN | grep ";$mediaid;" | tail -n 1 >> ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/FASTRXBIAN # EXIT AFTER ONE PIN ONLY (next PIN in cron_MINUTE time) - [[ -f ~/.zen/PIN/${astrofile}/$G1PUB ]] && break + [[ -f ~/.zen/PIN/${ipfsrepidfile}/$G1PUB ]] && break done exit 0