forked from axiom-team/astroport
281 lines
13 KiB
Bash
Executable File
281 lines
13 KiB
Bash
Executable File
#!/bin/bash
|
|
########################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# 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
|
|
[[ -f $MY_PATH/../secret.astroport.key ]] && source $MY_PATH/../secret.astroport.key
|
|
export YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1)
|
|
source /home/$YOU/.profile
|
|
[[ $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 isMinetestRunning=$(ps auxf --sort=+utime | grep -w minetest | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1)
|
|
export isG1smsRunning=$(ps auxf --sort=+utime | grep -w gammu | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1)
|
|
export isKodiRunning=$(ps auxf --sort=+utime | grep -w kodi | 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
|
|
|
|
#
|
|
# _________
|
|
# / ____< /________ ___ _____
|
|
# / / __ / / ___/ __ `__ \/ ___/
|
|
#/ /_/ // (__ ) / / / / (__ )
|
|
#\____//_/____/_/ /_/ /_/____/
|
|
#
|
|
# $MY_PATH/g1sms/sms_ASTROPORT.sh
|
|
|
|
# TIME NTP SYNC: TODO: Problem being root (stickybit INSTALL?)
|
|
# G1Tx. G1sms. G1Dab Zen economy needs precise time sync (RpiZero !!)
|
|
# Tx rates is limited by Station time synchronisation.
|
|
# sudo ntpdate ntp.pool.org
|
|
|
|
# ____ _______ __ __
|
|
# / __ \/ ____/ | / / ____ ___ ____ ____/ /__
|
|
# / / / / __/ | | / / / __ `__ \/ __ \/ __ / _ \
|
|
# / /_/ / /___ | |/ / / / / / / / /_/ / /_/ / __/
|
|
# /_____/_____/ |___/ /_/ /_/ /_/\____/\__,_/\___/
|
|
#
|
|
#
|
|
# ACTIVATE 5 MN "git pull" update
|
|
if [[ $(($minute % 5)) == 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 &
|
|
|
|
|
|
|
|
## 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"
|
|
##################################################################
|
|
|
|
##################################################################
|
|
# __ __ __
|
|
# __/ // /_____ ___ ____ __ __/ /__ __
|
|
# /_ _ __/_ / / _ \/ __ \/ / / / __/ | / /
|
|
# /_ _ __/ / /_/ __/ / / / /_/ / /_ | |/ /
|
|
# /_//_/ /___/\___/_/ /_/\__, /\__/ |___/
|
|
# /____/
|
|
# SSB message 2 "youtube-dl" EXPERIMENTAL
|
|
# TODO : Run on BIG STATIONS (Control available Disk Space !!)
|
|
##################################################################
|
|
# RANDOMLY RUN SSB GET zenytv (avoid simultaneous run in swarm)
|
|
randh=$((1 + RANDOM % 24))
|
|
if [[ $(($heure % $randh)) == 0 ]]; then
|
|
diskMBps=$(dd if=/dev/zero of=~/.zen/test.disk bs=10M count=1 oflag=dsync 2>&1 | tail -n 1 | sed s/\,\ /\ -/g | cut -d '-' -f 4 | cut -d ' ' -f 1 | cut -d '.' -f 1)
|
|
diskGiga=$(df -h ~/.ipfs/ | tail -n 1 | awk '{print $4}' | cut -d 'G' -f '1')
|
|
echo "GET_zenytv write speed : $diskMBps MB/s"
|
|
echo "Disk size : $diskGiga GB"
|
|
sleep $((1 + RANDOM % 10))
|
|
[[ $diskMBps -gt 15 ]] && [[ $diskGiga -gt 5 ]] && $MY_PATH/zen/ssb_GET_zenytv.sh &
|
|
|
|
fi
|
|
##################################################################
|
|
randh=$((1 + RANDOM % 24))
|
|
if [[ $(($heure % $randh)) == 0 ]]; then
|
|
diskMBps=$(dd if=/dev/zero of=~/.zen/test.disk bs=10M count=1 oflag=dsync 2>&1 | tail -n 1 | sed s/\,\ /\ -/g | cut -d '-' -f 4 | cut -d ' ' -f 1 | cut -d '.' -f 1)
|
|
diskGiga=$(df -h ~/.ipfs/ | tail -n 1 | awk '{print $4}' | cut -d 'G' -f '1' | cut -d '.' -f 1 )
|
|
echo "ssb_GET_zenyta write speed : $diskMBps MB/s"
|
|
echo "Disk size : $diskGiga GB"
|
|
# You can modify limit for a station to act ( > 15MB/s && > 5GB )
|
|
sleep $((1 + RANDOM % 10))
|
|
[[ $diskMBps -gt 15 ]] && [[ $diskGiga -gt 5 ]] && $MY_PATH/zen/ssb_GET_zenyta.sh &
|
|
fi
|
|
##################################################################
|
|
|
|
##################################################################
|
|
############ ASTROPORT LAUNCHING DATE 12:12 (HOUR is UTC)
|
|
TODAY=$(date -u '+%Y%m%d')
|
|
if [[ "$timebar" == "10:12" ]]; then
|
|
echo '
|
|
_____ ___ ___ __ __ _
|
|
|__ / |__ \ < / / /___ ___ ______ _____/ /_ (_)___ ____ _
|
|
/_ < __/ / / / / / __ `/ / / / __ \/ ___/ __ \/ / __ \/ __ `/
|
|
___/ / / __/ / /_ _ _ / / /_/ / /_/ / / / / /__/ / / / / / / / /_/ /
|
|
/____/ /____/ /_/(_|_|_) /_/\__,_/\__,_/_/ /_/\___/_/ /_/_/_/ /_/\__, /
|
|
/____/
|
|
ASTROPORT NOW... automate cellulaire - blob à rétrocontrole humain COLLECTIVE INIT
|
|
'
|
|
echo "$TODAY 12:12 - GCHANGE MARKET 50km SCAN"
|
|
sleep $((1 + RANDOM % 10))
|
|
# $MY_PATH/zen/gchange_MONITOR.sh &
|
|
fi
|
|
##################################################################
|
|
##################################################################
|
|
|
|
|
|
##################################################################
|
|
##################################################################
|
|
# MIDNIGHT:01 : ZENBOT CLEANING & UPDATE
|
|
##################################################################
|
|
##################################################################
|
|
if [[ "$timebar" == "00:01" ]]; then
|
|
echo '
|
|
# ____ ____ ____ ___
|
|
# / __ \/ __ \ _ / __ < /
|
|
# / / / / / / / (_) / / / / /
|
|
# / /_/ / /_/ / _ / /_/ / /
|
|
# \____/\____/ (_) \____/_/
|
|
#
|
|
# Clean & Upgrade + Log rotation + git pull + ipfs p2p port forward refresh, etc...
|
|
'
|
|
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 &
|
|
tar cvzf ~/.zen/astroport.$weeknumber.log.tgz /tmp/astroport.log # LOG BACKUP FOR 1 YEAR !!
|
|
fi
|
|
#### DESYNC
|
|
sleep $((1 + RANDOM % 5))
|
|
##################################################################
|
|
# GIT UPDATE
|
|
./git-update.sh
|
|
git pull # UPDATE CODE git pull
|
|
##################################################################
|
|
# Clear 24h ssb_GET markers
|
|
rm ~/.zen/zenytv.last.ts
|
|
rm ~/.zen/zenyta.last.ts
|
|
##################################################################
|
|
echo '
|
|
_________
|
|
/ ____< / _________ ___ _____
|
|
/ / __ / / / ___/ __ `__ \/ ___/
|
|
/ /_/ // / (__ ) / / / / (__ )
|
|
\____//_/ /____/_/ /_/ /_/____/
|
|
|
|
HTTP API forwarding to http://127.0.0.1:10099
|
|
'
|
|
echo '' > /tmp/A_P2Pforward
|
|
ipfs p2p close --all
|
|
####### OPEN PORT TO FORWARD ####### ADMIN ANY NODE (placer à 5 + 1mn)
|
|
### ADAPT TO ANY IPFSNODEID and TCP port
|
|
if [[ "$IPFSNODEID" == "QmVywXoBSz7JZ5vunYYVwi72SdTizvFt7k7qd3ooyYHvHA" ]]; then
|
|
ipfs p2p listen /x/g1pub-ssh /ip4/127.0.0.1/tcp/22 # CLOSE WITH ipfs p2p close /x/g1pub-ssh
|
|
ipfs p2p listen /x/g1pub-http /ip4/127.0.0.1/tcp/80
|
|
fi
|
|
# INDICATE OPENED PORTS to OTHER STATIONS
|
|
echo "ipfs p2p forward /x/g1pub-ssh /ip4/127.0.0.1/tcp/2021 /p2p/QmVywXoBSz7JZ5vunYYVwi72SdTizvFt7k7qd3ooyYHvHA" >> /tmp/A_P2Pforward
|
|
echo "ipfs p2p forward /x/g1pub-http /ip4/127.0.0.1/tcp/8021 /p2p/QmVywXoBSz7JZ5vunYYVwi72SdTizvFt7k7qd3ooyYHvHA" >> /tmp/A_P2Pforward
|
|
./zen/ipfs_OPEN_ports.sh
|
|
ipfs p2p ls
|
|
##################################################################
|
|
|
|
echo '
|
|
_________ ______
|
|
____ ___ ____ /_ __/ | / ____/
|
|
/_ / / _ \/ __ \ / / / /| |/ / __
|
|
/ /_/ __/ / / / / / / ___ / /_/ /
|
|
/___/\___/_/ /_/ /_/ /_/ |_\____/
|
|
|
|
REFRESHing ZenTAG nano DHTs
|
|
'
|
|
./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"
|
|
|
|
## RESET ipfs_SWARM_refresh.sh alert
|
|
rm -f /tmp/ssb-friends_ALERT.txt
|
|
|
|
fi
|
|
##################################################################
|
|
|
|
|
|
fi
|