2020-12-12 01:26:39 +01:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
2020-12-24 15:49:41 +01:00
# Armust Blegde release
2020-12-12 01:26:39 +01:00
# Version: 0.3
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
2021-03-18 01:27:22 +01:00
# REGULATEUR DES PULSATIONS DE L'AUTOMATE # CADENCE # 1/60 Hz
########################################################################
2020-12-12 01:26:39 +01:00
MY_PATH = " `dirname \" $0 \"` " # relative
MY_PATH = " `( cd \" $MY_PATH \" && pwd )` " # absolutized and normalized
ME = " ${ 0 ##*/ } "
source $HOME /.profile
# CORRECT PATH
[ [ ! $( echo $PATH | grep "/usr/local/bin" ) ] ] && export PATH = " $PATH :/usr/local/bin "
2021-02-13 15:38:14 +01:00
[ [ ! $( echo $PATH | grep " $HOME /.local/bin " ) ] ] && export PATH = " $PATH : $HOME /.local/bin "
2020-12-12 01:26:39 +01:00
[ [ ! $( echo $PATH | grep "/usr/games" ) ] ] && export PATH = " $PATH :/usr/games "
#### INIT STATION PARAMETERS
export YOU = $( ps auxf --sort= +utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1)
2021-03-12 00:42:27 +01:00
[ [ ! $YOU ] ] && echo "ERREUR processus ipfs absent" && exit 1
2020-12-12 01:26:39 +01:00
[ [ $IPFSNODEID ] ] && export IPFSNODEID = $IPFSNODEID || export IPFSNODEID = $( ipfs id -f= '<id>\n' )
2021-03-06 13:30:40 +01:00
########################################################################
# CORRECT VSTREAM ASTROPORT SITE/ART REMOVED AFTER PLUGIN UPDATE
2021-02-20 02:01:58 +01:00
[ [ ! -f ~/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py ] ] && [ [ -f ~/.zen/astroport.py ] ] && cp -f ~/.zen/astroport.py ~/.kodi/addons/plugin.video.vstream/resources/sites/
2021-03-06 13:30:40 +01:00
[ [ ! -f ~/.kodi/addons/plugin.video.vstream/resources/art/astroport.png ] ] && cp ~/.zen/astrXbian/.install/.kodi/addons/plugin.video.vstream/resources/art/astroport.png ~/.kodi/addons/plugin.video.vstream/resources/art/
########################################################################
2021-02-20 02:01:58 +01:00
2021-02-18 11:02:42 +01:00
### NO IP GATEWAY : EXIT
2021-03-06 15:11:19 +01:00
ping -q -w 1 -c 1 ` ip r | grep default | cut -d ' ' -f 3` 2>& 1>/dev/null && echo "GATEWAY OK" || exit 1
2021-02-18 11:02:42 +01:00
2021-03-06 21:18:14 +01:00
########################################################################
### TEMP CODE (add missing packages to xbian) - TODO REMOVE after 30 mn for git pull & apply
# [[ $(which ffmpeg) == "" && "$USER" == "xbian" ]] && sudo apt-get update && sudo apt-get install git fail2ban inotify-tools curl net-tools libsodium* python3-dev python3-pip python3-setuptools python3-wheel mpack libssl-dev libffi-dev build-essential qrencode jq bc gawk ffmpeg sqlite dnsutils vlc mp3info x11-utils -y
2021-03-30 23:02:24 +02:00
[ [ -d ~/.zen/ipfs/.${ IPFSNODEID } /PIN/ ] ] && mv ~/.zen/ipfs/.${ IPFSNODEID } /PIN ~/.zen/ && rm ~/.zen/PIN/${ IPFSREPFILEID } /${ G1PUB } # HIDDING PIN FROM SWARM
[ [ -d ~/.zen/KEY/ ] ] && mv ~/.zen/KEY ~/.zen/ipfs/.${ IPFSNODEID } / # SHOWING IPNS KEY TO SWARM
2021-03-17 16:54:15 +01:00
2021-03-06 21:18:14 +01:00
########################################################################
2020-12-12 01:26:39 +01:00
########################################################################
# HELP DEVLT: Search "TODO" in code
# WARNING: This script must be processing less than 1 minute, so do not charge too much this script
# _ _____ ____ _ _______ ________ ____
# | | / / | / __ \/ | / / _/ | / / ____/ / / /
# | | /| / / /| | / /_/ / |/ // // |/ / / __ / / /
# | |/ |/ / ___ |/ _, _/ /| // // /| / /_/ / /_/_/
# |__/|__/_/ |_/_/ |_/_/ |_/___/_/ |_/\____/ (_|_)
########################################################################
2021-01-31 23:18:56 +01:00
# 'figlet' was used for labeling code trunks
2020-12-12 01:26:39 +01:00
########################################################################
### MODIFY WITH GREAT CARE!!! MUST BE BUG FREE !!!!!
### EVERY STATION RUN THIS SCRIPT EVERY MINUTE.
export isKodiRunning = $( ps auxf --sort= +utime | grep -w kodi | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1)
########################################################################
cd $MY_PATH
2021-03-30 01:17:26 +02:00
########################################################################
# WHAT TIME(s) is it ?
timestamp = " $( date -u +%s%N | cut -b1-13) "
2020-12-12 01:26:39 +01:00
minute = $( date -u +%M)
heure = $( date -u +%H)
timebar = " $heure : $minute "
dayoftheweek = $( date +%w)
dayofthemonth = $( date +%d)
weeknumber = $( date +%V)
2021-03-30 01:17:26 +02:00
# WAKEUP TIME
if [ [ ! -f /tmp/A_Station_ON ] ] ; then
echo " onheure= $heure ; onminute= $minute ; ontimebar= $timebar " > /tmp/A_Station_ON
else
source /tmp/A_Station_ON
old = $ontimebar
new = $timebar
# feeding variables by using read and splitting with IFS
IFS = : read old_hour old_min <<< " $old "
IFS = : read hour min <<< " $new "
# convert hours to minutes
# the 10# is there to avoid errors with leading zeros
# by telling bash that we use base 10
total_old_minutes = $(( 10# $old_hour * 60 + 10# $old_min ))
total_minutes = $(( 10# $hour * 60 + 10# $min ))
runtime = $(( total_minutes - total_old_minutes))
fi
# RUN TIME $runtime
echo " $runtime ( $timebar ) "
########################################################################
# STATION CAN MODIFY DEFCON (cool 5 to 1 war) - only 5 and 4 (fail2ban) are ready to use.
2021-02-21 20:33:38 +01:00
[ [ -f ~/.zen/DEFCON ] ] && export DEFCON = $( cat ~/.zen/DEFCON) || export DEFCON = $( cat ~/.zen/astrXbian/DEFCON) # ADAPT $DEFCON scenario
2021-01-31 23:18:56 +01:00
2020-12-12 01:26:39 +01:00
# ____ _______ __ __
# / __ \/ ____/ | / / ____ ___ ____ ____/ /__
# / / / / __/ | | / / / __ `__ \/ __ \/ __ / _ \
# / /_/ / /___ | |/ / / / / / / / /_/ / /_/ / __/
# /_____/_____/ |___/ /_/ /_/ /_/\____/\__,_/\___/
#
#
2021-02-21 20:33:38 +01:00
# ACTIVATE 15-17 MN "git pull" update
2020-12-15 13:27:32 +01:00
if [ [ $(( $minute % 15 )) = = 0 ] ] ; then
2021-02-13 14:25:50 +01:00
########## DESYNCH SWARM NODE REQUESTS #################
2021-02-20 02:01:58 +01:00
sleep $(( 1 + RANDOM % 120 ))
2021-03-18 00:46:55 +01:00
# git reset --hard
git pull
2021-03-07 23:10:09 +01:00
2021-03-28 21:04:55 +02:00
# if [[ $(diff ~/.zen/astrXbian/.install/.kodi/userdata/addon_data/plugin.video.vstream/settings.xml ~/.kodi/userdata/addon_data/plugin.video.vstream/settings.xml) ]]; then
2021-03-08 02:49:09 +01:00
# cp ~/.zen/astrXbian/.install/.kodi/userdata/addon_data/plugin.video.vstream/settings.xml ~/.kodi/userdata/addon_data/plugin.video.vstream/settings.xml
# echo "MAJ Vstream settings"
# fi
2021-03-06 23:52:13 +01:00
########## OPEN OR CLOSE SSH ACCESS #################
2021-03-07 15:41:27 +01:00
# [[ "$(ipfs p2p ls | grep $G1PUB-ssh)" == "" ]] && sleep $((1 + RANDOM % 10)) && ~/.zen/astrXbian/zen/ssh_forward2onelove.sh # OPEN-SSH
2021-03-06 23:52:13 +01:00
# [[ "$(ipfs p2p ls | grep $G1PUB-ssh)" != "" ]] && sleep $((1 + RANDOM % 10)) && ~/.zen/astrXbian/zen/ssh_forward2onelove.sh # CLOSE-SSH
2020-12-12 01:26:39 +01:00
fi
# __ __ _____ ____
# __/ // /_/ ___/ ______ __________ ___ / __ \
# /_ _ __/\__ \ | /| / / __ `/ ___/ __ `__ \/ / / /
# /_ _ __/___/ / |/ |/ / /_/ / / / / / / / / /_/ /
2021-03-30 01:17:26 +02:00
# /_//_/ /____/|__/|__/\__,_/_/ /_/ /_/ /_/\____/ gchange sync
2020-12-12 01:26:39 +01:00
#
##################################################################
2021-04-07 23:01:20 +02:00
# TODO: IDEA make gchange/ipfs/ipns refresh speed depending on ipfs swarm size and DEFCON level !
2021-04-01 00:06:06 +02:00
# SYNC GCHANGE EVERY 2 hours +/- 3 minutes
2021-04-07 23:01:20 +02:00
[ [ $(( $runtime % 120 )) = = 0 ] ] && $MY_PATH /zen/gchange_INIT.sh && $MY_PATH /zen/gchange_IPFS_swarm.sh &
2020-12-12 01:26:39 +01:00
2021-04-07 23:01:20 +02:00
# QUICK SYNC SWARM EVERY 20 minutes +/- 1 minute
[ [ $(( $runtime % 20 )) = = 0 ] ] && $MY_PATH /zen/ipfs_SWARM_refresh.sh "quick" &
2021-04-01 00:06:06 +02:00
2021-03-18 00:18:48 +01:00
# ~/astroport
2020-12-15 23:23:36 +01:00
# _ _
# __ _| |__ (_) __ _ _ __
# \ \/ / '_ \| |/ _` | '_ \
# > <| |_) | | (_| | | | |
2021-03-18 00:18:48 +01:00
# /_/\_\_.__/|_|\__,_|_| |_| inotifywait
2021-02-21 20:33:38 +01:00
#
# ON Rpi/xbian files added in ~/astroport are monitored to activate "new_file_in_astroport.sh"
2021-03-06 20:00:25 +01:00
# Transfert ~/astroport/*/files to IPFS and make Astroport/KODI indexes in IPNS
2021-03-06 21:27:30 +01:00
if [ [ " $YOU " = = "xbian" ] ] ; then
2021-03-06 20:00:25 +01:00
[ [ ! -e /home/$YOU /astroport ] ] && mkdir -p /home/$YOU /astroport
# VERIFY LAUNCH inotifywait ?!
inotifywaitRunning = $( ps auxf --sort= +utime | grep -w inotifywait | grep -w astroport | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1)
if [ [ " $inotifywaitRunning " != "xbian" ] ]
then
2021-03-09 18:59:22 +01:00
/usr/bin/inotifywait -r -e close_write -m /home/$YOU /astroport | while read dir flags file; do $MY_PATH /zen/new_file_in_astroport.sh " $dir " " $file " ; done >> /tmp/astroport.inotify.log 2>& 1 &
2021-01-31 23:18:56 +01:00
fi
2020-12-12 01:26:39 +01:00
fi
2021-03-06 20:00:25 +01:00
2021-03-18 00:18:48 +01:00
##########################################################
2020-12-12 01:26:39 +01:00
2021-03-30 01:29:44 +02:00
if [ [ " $timebar " = = "12:12" || " $timebar " = = "00:12" || $(( $runtime % 720 )) = = 0 ] ] ; then
2021-04-07 23:01:20 +02:00
#### timebar DESYNC
2021-03-01 02:25:02 +01:00
sleep $(( 1 + RANDOM % 5 ))
##################################################################
#
# _________ ______
# ____ ___ ____ /_ __/ | / ____/
# /_ / / _ \/ __ \ / / / /| |/ / __
# / /_/ __/ / / / / / / ___ / /_/ /
# /___/\___/_/ /_/ /_/ /_/ |_\____/
#
# REFRESHing KEY ZenTAG nano DHTs => Zen File ECONOMY door
$MY_PATH /zen/ipns_TAG_refresh.sh
2021-03-18 00:46:55 +01:00
## RESCAN dead swarm
rm -f ~/.zen/A_dead_swarm.txt
2021-03-01 02:25:02 +01:00
fi
2020-12-12 01:26:39 +01:00
##################################################################
##################################################################
2021-01-31 23:18:56 +01:00
# MIDNIGHT:01 : CLEANING & UPDATE
2020-12-12 01:26:39 +01:00
##################################################################
##################################################################
2021-04-07 23:01:20 +02:00
if [ [ " $timebar " = = "00:01" || " $runtime " = = "5" ] ] ; then
2020-12-12 01:26:39 +01:00
echo '
# ____ ____ ____ ___
# / __ \/ __ \ _ / __ < /
# / / / / / / / (_) / / / / /
# / /_/ / /_/ / _ / /_/ / /
# \____/\____/ (_) \____/_/
#
# MAINTENANCE
'
2021-03-02 11:24:32 +01:00
sleep $(( 1 + RANDOM % 15 )) ### Be careful if random sleep is not activated...
2020-12-12 01:26:39 +01:00
############################## That swarm could become an aggressive blob !!
### PEACE & LOVE software is processing... We are HyperWeb people here.
# DEFCON 5 quiet behaviour so Please keep cool, take care and be zen.
2021-01-31 23:18:56 +01:00
# GOOD BYE GOOGLE, AMAZON, FACEBOOK, APPLE, MICROSOFT. LIBRE WE ARE.
####################################################################
2020-12-12 01:26:39 +01:00
# REFRESH & UPGRADE youtube-dl
2021-03-02 11:24:32 +01:00
youtube-dl --rm-cache-dir
youtube-dl -U
2021-01-31 23:27:36 +01:00
2020-12-12 01:26:39 +01:00
##################################################################
2021-01-31 23:18:56 +01:00
2021-04-07 23:01:20 +02:00
if [ [ $dayoftheweek = = 1 ] ] ; then
# EVERY MONDAY
2021-01-31 23:18:56 +01:00
# _____ __ __ ___
# / ___// /_____ _________ _____ ____ / |/ /___ __ __
# \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / /|_/ / __ `/ |/_/
# ___/ / /_/ /_/ / / / /_/ / /_/ / __/ / / / / /_/ /> <
# /____/\__/\____/_/ \__,_/\__, /\___/ /_/ /_/\__,_/_/|_|
# /____/
# 1/2 HDD for IPFS size - dicotomic adaptation 7th EVERY MONTH
availableDiskSize = $( df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}' )
2021-04-03 23:18:58 +02:00
availableDiskSize = " $(( $availableDiskSize * 1024 )) "
2021-01-31 23:18:56 +01:00
diskSize = " $(( availableDiskSize / 2 )) "
ipfs config Datastore.StorageMax $diskSize
2021-03-02 11:24:32 +01:00
echo " StorageMax = $diskSize "
2021-03-18 00:46:55 +01:00
# New full test review in gchange_INIT.sh
2021-03-18 00:18:48 +01:00
rm -f ~/.ipfs/test.disk
2021-03-18 00:46:55 +01:00
2021-01-31 23:27:36 +01:00
# LOG ROTATE
2021-03-02 11:24:32 +01:00
[ [ -f /tmp/astroport.log ] ] && tar cvzf ~/.zen/astroport.$weeknumber .log.tgz /tmp/astroport.log && echo "" > /tmp/astroport.log
2021-01-31 23:27:36 +01:00
2021-03-02 11:24:32 +01:00
fi
2020-12-12 01:26:39 +01:00
##################################################################
2021-03-19 04:19:18 +01:00
## CREATE STARTGATE LEVEL KEYS
# _ open _
# ___| |_ __ _ _ __ __ _ __ _| |_ ___
#/ __| __/ _` | '__/ _` |/ _` | __/ _ \
#\__ \ || (_| | | | (_| | (_| | || __/
#|___/\__\__,_|_| \__, |\__,_|\__\___|
# |___/
# IPNS KEYS used to publish with star friends (creates your 5 swarm subnets)
if [ [ ! -f ~/.zen/key/1/stargate ] ] ; then
[ [ ! -d ~/.zen/key/ ] ] && mkdir -p ~/.zen/key/1 ~/.zen/key/2 ~/.zen/key/3 ~/.zen/key/4 ~/.zen/key/5
stargate_1 = $( ipfs key gen star_1) && key_1 = $( ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_1 ~/.zen/key/1/ && echo " $stargate_1 " > ~/.zen/key/1/stargate
stargate_2 = $( ipfs key gen star_2) && key_2 = $( ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_2 ~/.zen/key/2/ && echo " $stargate_2 " > ~/.zen/key/2/stargate
stargate_3 = $( ipfs key gen star_3) && key_3 = $( ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_3 ~/.zen/key/3/ && echo " $stargate_3 " > ~/.zen/key/3/stargate
stargate_4 = $( ipfs key gen star_4) && key_4 = $( ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_4 ~/.zen/key/4/ && echo " $stargate_4 " > ~/.zen/key/4/stargate
stargate_5 = $( ipfs key gen star_5) && key_5 = $( ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_5 ~/.zen/key/5/ && echo " $stargate_5 " > ~/.zen/key/5/stargate
# CYPHERED (SIGNED) THEY ARE SEND to regulate (could depends on DEFCON security level)
# gchange_IPFS_swarm.sh monitor ~/.zen/key/send file to execute "mailing"
fi
2020-12-12 01:26:39 +01:00
fi