forked from axiom-team/astrXbian
193 lines
8.3 KiB
Bash
Executable File
193 lines
8.3 KiB
Bash
Executable File
#!/bin/bash
|
||
########################################################################
|
||
# Author: Fred (support@qo-op.com)
|
||
# Armust Blegde release
|
||
# 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"
|
||
[[ ! $(echo $PATH | grep "HOME/.local/bin") ]] && export PATH="$PATH:$HOME/.local/bin"
|
||
[[ ! $(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')
|
||
|
||
########################################################################
|
||
# 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
|
||
# _ _____ ____ _ _______ ________ ____
|
||
# | | / / | / __ \/ | / / _/ | / / ____/ / / /
|
||
# | | /| / / /| | / /_/ / |/ // // |/ / / __ / / /
|
||
# | |/ |/ / ___ |/ _, _/ /| // // /| / /_/ / /_/_/
|
||
# |__/|__/_/ |_/_/ |_/_/ |_/___/_/ |_/\____/ (_|_)
|
||
|
||
########################################################################
|
||
# NB: 'figlet' is used for labeling code trunks
|
||
########################################################################
|
||
### 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)
|
||
isinotifywaitRunning=$(ps auxf --sort=+utime | grep -w inotifywait | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1)
|
||
|
||
# ? isNextcloudRunning=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1)
|
||
### DETECT FLAVOURS (TODO: Publish and share into ipfs/.12D3KooW***/ )
|
||
########################################################################
|
||
cd $MY_PATH
|
||
|
||
# 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
|
||
|
||
# ____ _______ __ __
|
||
# / __ \/ ____/ | / / ____ ___ ____ ____/ /__
|
||
# / / / / __/ | | / / / __ `__ \/ __ \/ __ / _ \
|
||
# / /_/ / /___ | |/ / / / / / / / /_/ / /_/ / __/
|
||
# /_____/_____/ |___/ /_/ /_/ /_/\____/\__,_/\___/
|
||
#
|
||
#
|
||
# ACTIVATE 15 MN "git pull" update
|
||
if [[ $(($minute % 15)) == 0 ]]; then
|
||
#######################################
|
||
sleep $((1 + RANDOM % 12))
|
||
git pull
|
||
fi
|
||
|
||
# __ __ _____ ____
|
||
# __/ // /_/ ___/ ______ __________ ___ / __ \
|
||
# /_ _ __/\__ \ | /| / / __ `/ ___/ __ `__ \/ / / /
|
||
# /_ _ __/___/ / |/ |/ / /_/ / / / / / / / / /_/ /
|
||
# /_//_/ /____/|__/|__/\__,_/_/ /_/ /_/ /_/\____/
|
||
#
|
||
##################################################################
|
||
# REFRESH IPFS SWARM DATA EVERY 12 & 15 minutes
|
||
[[ $(($minute % 12)) == 0 ]] && sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/gchange_IPFS_swarm.sh &
|
||
[[ $(($minute % 15)) == 0 ]] && sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/ipfs_SWARM_refresh.sh &
|
||
|
||
#
|
||
# _ _
|
||
# __ _| |__ (_) __ _ _ __
|
||
# \ \/ / '_ \| |/ _` | '_ \
|
||
# > <| |_) | | (_| | | | |
|
||
# /_/\_\_.__/|_|\__,_|_| |_| ASTROPORT youtube mp3
|
||
#
|
||
# Transfert ~/astroport/*/files to IPFS and make Vstream/ASTROPORT indexes on IPNS
|
||
|
||
if [[ ! $isinotifywaitRunning ]]; then
|
||
mkdir -p /home/$YOU/astroport
|
||
[[ $YOU == "xbian" ]] && /usr/bin/inotifywait -r -e close_write -m /home/$YOU/astroport | while read dir flags file; do $MY_PATH/zen/xbian_vstream.sh "$dir" "$file"; done &
|
||
[[ $YOU != "xbian" ]] && /usr/bin/inotifywait -r -e close_write -m /home/$YOU/astroport | while read dir flags file; do $MY_PATH/zen/mint_youtube.sh "$dir" "$file"; done &
|
||
fi
|
||
|
||
# restart inotifywait (may be useless)
|
||
if [[ "$timebar" == "03:03" ]]; then
|
||
killall inotifywait
|
||
fi
|
||
|
||
## TODO investigate could breaks "ipfs p2p" forwards ?
|
||
##################################################################
|
||
|
||
# _________ _______ __ _ __
|
||
# / ____< / /_ __/ |/ / ____ ___ ____ ____ (_) /_____ _____
|
||
# / / __ / / / / | / / __ `__ \/ __ \/ __ \/ / __/ __ \/ ___/
|
||
# / /_/ // / / / / | / / / / / / /_/ / / / / / /_/ /_/ / /
|
||
# \____//_/ /_/ /_/|_| /_/ /_/ /_/\____/_/ /_/_/\__/\____/_/
|
||
#
|
||
##################################################################
|
||
# MONITOR INPUT TX (TODO: DEBUG)
|
||
# Activate later for DAB ZenTx Machines
|
||
# [[ $(($minute % 5)) == 0 ]] && sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/g1_MONITOR_zen.sh "5 minutes"
|
||
##################################################################
|
||
|
||
##################################################################
|
||
##################################################################
|
||
# MIDNIGHT:01 : ZENBOT CLEANING & UPDATE
|
||
##################################################################
|
||
##################################################################
|
||
if [[ "$timebar" == "00:01" ]]; then
|
||
echo '
|
||
# ____ ____ ____ ___
|
||
# / __ \/ __ \ _ / __ < /
|
||
# / / / / / / / (_) / / / / /
|
||
# / /_/ / /_/ / _ / /_/ / /
|
||
# \____/\____/ (_) \____/_/
|
||
#
|
||
# MAINTENANCE
|
||
'
|
||
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.
|
||
# GOOD BYE GOOGLE, AMAZON, FACEBOOK, APPLE, MICROSOFT. We don't need you.
|
||
##################################################################
|
||
# REFRESH & UPGRADE youtube-dl
|
||
youtube-dl --rm-cache-dir
|
||
youtube-dl -U
|
||
#### DESYNC
|
||
sleep $((1 + RANDOM % 5))
|
||
##################################################################
|
||
# ssb_INIT + LOG ROTATE EVERY SUNDAY # TODO /var/log/ + logrotate (& tempfiles in /tmp in RAMFS)
|
||
if [[ $dayoftheweek == 0 ]]; then
|
||
$MY_PATH/zen/gchange_INIT.sh &
|
||
# ACTIVATE IF CRON LOGGING
|
||
#tar cvzf ~/.zen/astrXbian.$weeknumber.log.tgz /tmp/astroport.log # LOG BACKUP FOR 1 YEAR !!
|
||
fi
|
||
#### DESYNC
|
||
sleep $((1 + RANDOM % 5))
|
||
##################################################################
|
||
|
||
git pull # UPDATE CODE git pull
|
||
|
||
##################################################################
|
||
|
||
echo '
|
||
_________ ______
|
||
____ ___ ____ /_ __/ | / ____/
|
||
/_ / / _ \/ __ \ / / / /| |/ / __
|
||
/ /_/ __/ / / / / / / ___ / /_/ /
|
||
/___/\___/_/ /_/ /_/ /_/ |_\____/
|
||
|
||
REFRESHing ZenTAG nano DHTs = Zen File ECONOMY
|
||
'
|
||
# ./zen/ipns_TAG_refresh.sh
|
||
|
||
##################################################################
|
||
if [[ $dayofthemonth == 7 ]]; then
|
||
availableDiskSize=$(df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}')
|
||
diskSize="$((availableDiskSize / 2))"
|
||
ipfs config Datastore.StorageMax $diskSize
|
||
echo '
|
||
_____ __ __ ___
|
||
/ ___// /_____ _________ _____ ____ / |/ /___ __ __
|
||
\__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / /|_/ / __ `/ |/_/
|
||
___/ / /_/ /_/ / / / /_/ / /_/ / __/ / / / / /_/ /> <
|
||
/____/\__/\____/_/ \__,_/\__, /\___/ /_/ /_/\__,_/_/|_|
|
||
/____/
|
||
# 1/2 HDD for IPFS size - dicotomic adaptation 7th EVERY MONTH
|
||
#
|
||
# TODO: Read parameters from ipfs, publish status to swarm, could be use for youtube-dl or other kind of heavy ipfs input Station election.
|
||
#
|
||
'
|
||
echo "StorageMax = $diskSize"
|
||
|
||
fi
|
||
##################################################################
|
||
|
||
|
||
fi
|