forked from axiom-team/astrXbian
215 lines
11 KiB
Bash
Executable File
215 lines
11 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/)
|
|
########################################################################
|
|
# REGULATEUR DES PULSATIONS DE L'AUTOMATE # CADENCE # 1/60 Hz
|
|
########################################################################
|
|
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)
|
|
[[ ! $YOU ]] && echo "ERREUR processus ipfs absent" && exit 1
|
|
[[ $IPFSNODEID ]] && export IPFSNODEID=$IPFSNODEID || export IPFSNODEID=$(ipfs id -f='<id>\n')
|
|
|
|
########################################################################
|
|
# CORRECT VSTREAM ASTROPORT SITE/ART REMOVED AFTER PLUGIN 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/
|
|
[[ ! -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/
|
|
########################################################################
|
|
|
|
### NO IP GATEWAY : EXIT
|
|
ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` 2>&1>/dev/null && echo "GATEWAY OK" || exit 1
|
|
|
|
########################################################################
|
|
### 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
|
|
# [[ -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
|
|
|
|
########################################################################
|
|
|
|
########################################################################
|
|
# HELP DEVLT: Search "TODO" in code
|
|
# WARNING: This script must be processing less than 1 minute, so do not charge too much this script
|
|
# _ _____ ____ _ _______ ________ ____
|
|
# | | / / | / __ \/ | / / _/ | / / ____/ / / /
|
|
# | | /| / / /| | / /_/ / |/ // // |/ / / __ / / /
|
|
# | |/ |/ / ___ |/ _, _/ /| // // /| / /_/ / /_/_/
|
|
# |__/|__/_/ |_/_/ |_/_/ |_/___/_/ |_/\____/ (_|_)
|
|
|
|
########################################################################
|
|
# 'figlet' was 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)
|
|
########################################################################
|
|
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
|
|
[[ -f ~/.zen/DEFCON ]] && export DEFCON=$(cat ~/.zen/DEFCON) || export DEFCON=$(cat ~/.zen/astrXbian/DEFCON) # ADAPT $DEFCON scenario
|
|
|
|
# ____ _______ __ __
|
|
# / __ \/ ____/ | / / ____ ___ ____ ____/ /__
|
|
# / / / / __/ | | / / / __ `__ \/ __ \/ __ / _ \
|
|
# / /_/ / /___ | |/ / / / / / / / /_/ / /_/ / __/
|
|
# /_____/_____/ |___/ /_/ /_/ /_/\____/\__,_/\___/
|
|
#
|
|
#
|
|
# ACTIVATE 15-17 MN "git pull" update
|
|
if [[ $(($minute % 15)) == 0 ]]; then
|
|
########## DESYNCH SWARM NODE REQUESTS #################
|
|
sleep $((1 + RANDOM % 120))
|
|
# git reset --hard
|
|
git pull
|
|
|
|
# if [[ $(diff ~/.zen/astrXbian/.install/.kodi/userdata/addon_data/plugin.video.vstream/settings.xml ~/.kodi/userdata/addon_data/plugin.video.vstream/settings.xml) ]]; then
|
|
# 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
|
|
########## OPEN OR CLOSE SSH ACCESS #################
|
|
# [[ "$(ipfs p2p ls | grep $G1PUB-ssh)" == "" ]] && sleep $((1 + RANDOM % 10)) && ~/.zen/astrXbian/zen/ssh_forward2onelove.sh # OPEN-SSH
|
|
# [[ "$(ipfs p2p ls | grep $G1PUB-ssh)" != "" ]] && sleep $((1 + RANDOM % 10)) && ~/.zen/astrXbian/zen/ssh_forward2onelove.sh # CLOSE-SSH
|
|
fi
|
|
|
|
# __ __ _____ ____
|
|
# __/ // /_/ ___/ ______ __________ ___ / __ \
|
|
# /_ _ __/\__ \ | /| / / __ `/ ___/ __ `__ \/ / / /
|
|
# /_ _ __/___/ / |/ |/ / /_/ / / / / / / / / /_/ /
|
|
# /_//_/ /____/|__/|__/\__,_/_/ /_/ /_/ /_/\____/
|
|
#
|
|
##################################################################
|
|
#
|
|
# MAINTAIN FRESH LOCAL SWARM DATA EVERY 2 1/4 hours +/- 3 minutes
|
|
[[ $(($heure % 2)) == 0 && $minute == 15 ]] && sleep $((1 + RANDOM % 180)) && $MY_PATH/zen/gchange_INIT.sh && $MY_PATH/zen/gchange_IPFS_swarm.sh &
|
|
|
|
# ~/astroport
|
|
# _ _
|
|
# __ _| |__ (_) __ _ _ __
|
|
# \ \/ / '_ \| |/ _` | '_ \
|
|
# > <| |_) | | (_| | | | |
|
|
# /_/\_\_.__/|_|\__,_|_| |_| inotifywait
|
|
#
|
|
# ON Rpi/xbian files added in ~/astroport are monitored to activate "new_file_in_astroport.sh"
|
|
# Transfert ~/astroport/*/files to IPFS and make Astroport/KODI indexes in IPNS
|
|
if [[ "$YOU" == "xbian" ]]; then
|
|
[[ ! -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
|
|
/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 &
|
|
fi
|
|
fi
|
|
|
|
##########################################################
|
|
|
|
if [[ "$timebar" == "12:12" || "$timebar" == "00:12" ]]; then
|
|
#### DESYNC
|
|
sleep $((1 + RANDOM % 5))
|
|
##################################################################
|
|
#
|
|
# _________ ______
|
|
# ____ ___ ____ /_ __/ | / ____/
|
|
# /_ / / _ \/ __ \ / / / /| |/ / __
|
|
# / /_/ __/ / / / / / / ___ / /_/ /
|
|
# /___/\___/_/ /_/ /_/ /_/ |_\____/
|
|
#
|
|
# REFRESHing KEY ZenTAG nano DHTs => Zen File ECONOMY door
|
|
$MY_PATH/zen/ipns_TAG_refresh.sh
|
|
|
|
## RESCAN dead swarm
|
|
rm -f ~/.zen/A_dead_swarm.txt
|
|
fi
|
|
|
|
##################################################################
|
|
##################################################################
|
|
# MIDNIGHT:01 : CLEANING & UPDATE
|
|
##################################################################
|
|
##################################################################
|
|
if [[ "$timebar" == "00:01" ]]; then
|
|
echo '
|
|
# ____ ____ ____ ___
|
|
# / __ \/ __ \ _ / __ < /
|
|
# / / / / / / / (_) / / / / /
|
|
# / /_/ / /_/ / _ / /_/ / /
|
|
# \____/\____/ (_) \____/_/
|
|
#
|
|
# MAINTENANCE
|
|
'
|
|
sleep $((1 + RANDOM % 15)) ### 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. LIBRE WE ARE.
|
|
####################################################################
|
|
# REFRESH & UPGRADE youtube-dl
|
|
youtube-dl --rm-cache-dir
|
|
youtube-dl -U
|
|
|
|
|
|
##################################################################
|
|
|
|
if [[ $dayoftheweek == 0 ]]; then
|
|
# EVERY SUNDAY
|
|
# _____ __ __ ___
|
|
# / ___// /_____ _________ _____ ____ / |/ /___ __ __
|
|
# \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / /|_/ / __ `/ |/_/
|
|
# ___/ / /_/ /_/ / / / /_/ / /_/ / __/ / / / / /_/ /> <
|
|
# /____/\__/\____/_/ \__,_/\__, /\___/ /_/ /_/\__,_/_/|_|
|
|
# /____/
|
|
# 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
|
|
echo "StorageMax = $diskSize"
|
|
|
|
# New full test review in gchange_INIT.sh
|
|
rm -f ~/.ipfs/test.disk
|
|
|
|
# LOG ROTATE
|
|
[[ -f /tmp/astroport.log ]] && tar cvzf ~/.zen/astroport.$weeknumber.log.tgz /tmp/astroport.log && echo "" > /tmp/astroport.log
|
|
|
|
fi
|
|
##################################################################
|
|
|
|
## 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
|
|
|
|
fi
|