forked from axiom-team/astroport
106 lines
4.0 KiB
Bash
Executable File
106 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
########################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# Version: 0.2
|
|
# 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##*/}"
|
|
|
|
########################################################################
|
|
### MODIFY WITH GREAT CARE!!! MUST BE BUG FREE !!!!!
|
|
### EVERY STATION RUN THIS SCRIPT EVERY MINUTE
|
|
### DEPENDING ON EXE AND PS
|
|
isMinetestRunning=$(ps auxf --sort=+utime | grep -w minetest | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1)
|
|
isG1smsRunning=$(ps auxf --sort=+utime | grep -w gammu | 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)
|
|
### ACTIVATE DIFFERENT FLAVOUR
|
|
########################################################################
|
|
|
|
[[ ! $(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1) ]] \
|
|
&& echo "ipfs daemon not running. EXIT" \
|
|
&& exit 1
|
|
|
|
# CORRECT PATH
|
|
[[ ! $(echo $PATH | grep "/usr/local/bin") ]] && export PATH="$PATH:/usr/local/bin"
|
|
[[ ! $(echo $PATH | grep "~/.local/bin") ]] && export PATH="$PATH:~/.local/bin"
|
|
|
|
ipfsnodeid=$(ipfs id -f='<id>\n')
|
|
g1pub=$(cat ~/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
|
|
|
|
# UNIVERSAL TIME (TODO ntpdate, but sudo problem)
|
|
minute=$(date -u +%M)
|
|
heure=$(date -u +%H)
|
|
timebar="$heure:$minute"
|
|
jourdelasemaine=$(date +%w)
|
|
jourdumois=$(date +%d)
|
|
numerosemaine=$(date +%V)
|
|
echo $timebar
|
|
# TIME NTP SYNC: TODO: Problem being root (stickybit INSTALL?)
|
|
# sudo ntpdate ntp.pool.org
|
|
|
|
# #SWARM0 DEV MODE
|
|
# ACTIVATE 5 MN "git pull" update
|
|
[[ $(($minute % 5)) == 0 ]] && sleep $((1 + RANDOM % 12)) && cd $MY_PATH && git pull
|
|
|
|
|
|
|
|
##################################################################
|
|
# REFRESH IPFS SWARM DATA EVERY 12 minutes
|
|
[[ $(($minute % 12)) == 0 ]] && sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/ssb_IPFS_swarm.sh
|
|
##################################################################
|
|
|
|
##################################################################
|
|
# 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"
|
|
##################################################################
|
|
|
|
##################################################################
|
|
# YOUTUBE-DL
|
|
##################################################################
|
|
# RANDOMLY RUN SSB GET zenytv (avoid simultaneous run in swarm)
|
|
randh=$((1 + RANDOM % 24))
|
|
# [[ $(($heure % $randh)) == 0 ]] && sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/ssb_GET_zenytv.sh
|
|
##################################################################
|
|
randh=$((1 + RANDOM % 24))
|
|
# [[ $(($heure % $randh)) == 0 ]] && sleep $((1 + RANDOM % 10)) && $MY_PATH/zen/ssb_GET_zenyta.sh
|
|
##################################################################
|
|
|
|
|
|
##################################################################
|
|
# MIDNIGHT:01 : ZENBOT CLEANING & UPDATE
|
|
if [[ "$timebar" == "00:01" ]]; then
|
|
sleep $((1 + RANDOM % 10))
|
|
|
|
# UPGRADE youtube-dl
|
|
youtube-dl --rm-cache-dir
|
|
youtube-dl -U
|
|
|
|
sleep $((1 + RANDOM % 10))
|
|
# LOG ROTATE EVERY SUNDAY
|
|
[[ $jourdelasemaine == 0 ]] && mv -f /tmp/astroport.log ~/.zen/astroport.$numerosemaine.log # LOG BACKUP FOR 1 YEAR !!
|
|
|
|
sleep $((1 + RANDOM % 10))
|
|
# GIT PULL
|
|
git pull # UPDATE CODE git pull
|
|
|
|
# Clear 24h ssb_GET markers
|
|
rm ~/.zen/zenytv.last.ts
|
|
rm ~/.zen/zenyta.last.ts
|
|
|
|
# SYNC SSB Friends with IPFS SWARM
|
|
$MY_PATH/zen/ssb_IPFS_swarm.sh
|
|
|
|
fi
|
|
##################################################################
|
|
|
|
|
|
# MAXSTORAGE UPDATE EVERY MONTH
|
|
if [[ $jourdumois == 7 ]]; then
|
|
availableDiskSize=$(df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}')
|
|
diskSize="$((availableDiskSize / 2))"
|
|
ipfs config Datastore.StorageMax $diskSize
|
|
fi
|