astrXbian/cron_MINUTE.sh

186 lines
8.1 KiB
Bash
Raw Normal View History

2020-12-12 01:26:39 +01:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# 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/)
########################################################################
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)
[[ $IPFSNODEID ]] && export IPFSNODEID=$IPFSNODEID || export IPFSNODEID=$(ipfs id -f='<id>\n')
#####################################################
# CORRECT VSTREAM ASTROPORT SITE REMOVAL AFTER UPDATE
[[ ! -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-02-18 11:02:42 +01:00
### NO IP GATEWAY : EXIT
2021-02-18 11:06:30 +01:00
ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` 2> /dev/null && echo "OK" > /dev/null || (echo "NO GATEWAY CONNEXION" && exit 1)
2021-02-18 11:02:42 +01:00
2020-12-12 01:26:39 +01:00
########################################################################
# HELP DEVLT: Search "TODO" in code
# Write what you thing about the situation
# AND how you would like to 'fix it'...
# Then friends can read and enhance solution.
# 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)
export isinotifywaitRunning=$(ps auxf --sort=+utime | grep -w inotifywait | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1)
2020-12-12 01:26:39 +01:00
########################################################################
cd $MY_PATH
2021-02-13 14:45:00 +01:00
2020-12-12 01:26:39 +01:00
# WHAT UNIVERSAL TIME is it ?
minute=$(date -u +%M)
heure=$(date -u +%H)
timebar="$heure:$minute"
dayoftheweek=$(date +%w)
dayofthemonth=$(date +%d)
weeknumber=$(date +%V)
echo $timebar
[[ -f ~/.zen/DEFCON ]] && export DEFCON=$(cat ~/.zen/DEFCON) || export DEFCON=$(cat $MY_PATH/DEFCON) # ADAPT $DEFCON scenario
2021-01-31 23:18:56 +01:00
2020-12-12 01:26:39 +01:00
# ____ _______ __ __
# / __ \/ ____/ | / / ____ ___ ____ ____/ /__
# / / / / __/ | | / / / __ `__ \/ __ \/ __ / _ \
# / /_/ / /___ | |/ / / / / / / / /_/ / /_/ / __/
# /_____/_____/ |___/ /_/ /_/ /_/\____/\__,_/\___/
#
#
2020-12-15 13:27:32 +01:00
# ACTIVATE 15 MN "git pull" update
if [[ $(($minute % 15)) == 0 ]]; then
2021-02-13 14:25:50 +01:00
########## DESYNCH SWARM NODE REQUESTS #################
sleep $((1 + RANDOM % 120))
2021-02-13 14:25:50 +01:00
git pull
2020-12-12 01:26:39 +01:00
fi
# __ __ _____ ____
# __/ // /_/ ___/ ______ __________ ___ / __ \
# /_ _ __/\__ \ | /| / / __ `/ ___/ __ `__ \/ / / /
# /_ _ __/___/ / |/ |/ / /_/ / / / / / / / / /_/ /
# /_//_/ /____/|__/|__/\__,_/_/ /_/ /_/ /_/\____/
#
##################################################################
#
# REFRESH IPFS SWARM DATA EVERY 20 minutes décalé jusqu'à 3 mn
[[ $(($minute % 20)) == 0 ]] && sleep $((1 + RANDOM % 180)) && $MY_PATH/zen/gchange_INIT.sh && $MY_PATH/zen/gchange_IPFS_swarm.sh &
2020-12-12 01:26:39 +01:00
2020-12-15 23:23:36 +01:00
#
# _ _
# __ _| |__ (_) __ _ _ __
# \ \/ / '_ \| |/ _` | '_ \
# > <| |_) | | (_| | | | |
# /_/\_\_.__/|_|\__,_|_| |_| ASTROPORT youtube mp3
2020-12-15 23:23:36 +01:00
#
# Transfert ~/astroport/*/files to IPFS and make Vstream/ASTROPORT indexes on IPNS
2021-01-31 23:18:56 +01:00
if [[ "$USER" == "xbian" ]]; then
if [[ ! $isinotifywaitRunning ]]; then
mkdir -p /home/$YOU/astroport
2021-02-13 15:38:14 +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 &
2021-01-31 23:18:56 +01:00
fi
# restart inotifywait (may be useless)
if [[ "$timebar" == "03:03" ]]; then
killall inotifywait
fi
2020-12-12 01:26:39 +01:00
fi
## TODO investigate could breaks "ipfs p2p" forwards ?
##################################################################
# _________ _______ __ _ __
# / ____< / /_ __/ |/ / ____ ___ ____ ____ (_) /_____ _____
# / / __ / / / / | / / __ `__ \/ __ \/ __ \/ / __/ __ \/ ___/
# / /_/ // / / / / | / / / / / / /_/ / / / / / /_/ /_/ / /
# \____//_/ /_/ /_/|_| /_/ /_/ /_/\____/_/ /_/_/\__/\____/_/
#
##################################################################
2021-01-31 23:18:56 +01:00
# MONITOR INPUT TX (NOT ACTIVATED YET)
# Activate ZenTx => File become a wallet PASSENGER with CONTRACT(s)
2020-12-12 01:26:39 +01:00
# [[ $(($minute % 5)) == 0 ]] && sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/g1_MONITOR_zen.sh "5 minutes"
##################################################################
##################################################################
##################################################################
2021-01-31 23:18:56 +01:00
# MIDNIGHT:01 : CLEANING & UPDATE
2020-12-12 01:26:39 +01:00
##################################################################
##################################################################
if [[ "$timebar" == "00:01" ]]; then
echo '
# ____ ____ ____ ___
# / __ \/ __ \ _ / __ < /
# / / / / / / / (_) / / / / /
# / /_/ / /_/ / _ / /_/ / /
# \____/\____/ (_) \____/_/
#
# MAINTENANCE
'
2020-12-31 17:12:42 +01:00
sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/gchange_INIT.sh &
2020-12-12 01:26:39 +01:00
sleep $((1 + RANDOM % 5)) ### Be careful if random sleep is not activated...
############################## 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
youtube-dl --rm-cache-dir
youtube-dl -U
2021-01-31 23:27:36 +01:00
2021-01-31 23:18:56 +01:00
#### DESYNC
2020-12-12 01:26:39 +01:00
sleep $((1 + RANDOM % 5))
##################################################################
2021-01-31 23:18:56 +01:00
#
# _________ ______
# ____ ___ ____ /_ __/ | / ____/
# /_ / / _ \/ __ \ / / / /| |/ / __
# / /_/ __/ / / / / / / ___ / /_/ /
# /___/\___/_/ /_/ /_/ /_/ |_\____/
#
# REFRESHing ZenTAG nano DHTs = Zen File ECONOMY
2020-12-12 01:26:39 +01:00
# ./zen/ipns_TAG_refresh.sh
##################################################################
2021-01-31 23:18:56 +01:00
if [[ $dayoftheweek == 0 ]]; then
2020-12-12 01:26:39 +01:00
#
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}')
diskSize="$((availableDiskSize / 2))"
ipfs config Datastore.StorageMax $diskSize
2020-12-12 01:26:39 +01:00
echo "StorageMax = $diskSize"
2021-01-31 23:27:36 +01:00
# LOG ROTATE
[[ -f /tmp/astroport.log ]] && tar cvzf ~/.zen/astroport.$weeknumber.log.tgz /tmp/astroport.log && echo "" > /tmp/astroport.log
2020-12-12 01:26:39 +01:00
fi
##################################################################
fi