G1sms/shell/cron_CODE.backup.sh

72 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
# BACKUP G1sms+ current Devlt code and push it with SWARM_CODE_MASTER to IPFS
################################################################################
source ./init.sh
source ./functions.sh
now=$(date +%Y-%m-%d)
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
echo "COMMENTAIRES?"
read COMMENT
# CREATE CURRENT NODE "SWARM_CODE_MASTER" ipns key
if [[ ! -f "/home/$YOU/.ipfs/keystore/SWARM_CODE_MASTER" ]]; then
echo "Vous ne possédez pas la clef SWARM_CODE_MASTER de ce CODE..."
# echo "FORK ? su $YOU -c \"ipfs key gen -t rsa -s 2048 SWARM_CODE_MASTER\""
echo "Si vous souhaiter participer au CODE, contactez https://g1sms.fr "
echo "Utilisez le script ./G1sms+/install.sh pour installer ou mettre à jour votre noeud"
exit
else
# Only "SWARM_CODE_MASTER" key owner(s) can update & publish this _official _chain
#rm "./$dir/_publishkey.pgp" # TEMP for file name correction...
cat "/home/$YOU/.ipfs/keystore/SWARM_CODE_MASTER" | base64 | gpg -q --output "./$dir/_publishkey.gpg" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "/home/$YOU/.ipfs/keystore/SWARM_CODE_MASTER"
fi
## Backup $ROOT
dir=$(pwd | awk 'BEGIN { FS = "/" } ; {print $4}')
cd ..
###############################################
# Create BASIC IPNS _official IPFS HASH _chain
# with iterative update _chain, _nanodate, _zen, _g1cents values
# + _external UID references & _comments lines
###########################################################################################
echo "PLEASE WAIT...."
echo "GIT" > "./$dir/_type"
hop=$(cat "./$dir/_chain")
LASTDU=$(curl -s ${DUNITER}/blockchain/with/ud | jq '.result.blocks[]' | tail -n 1);
[[ $LASTDU != "" ]] && curl -s ${DUNITER}/blockchain/block/${LASTDU} | jq '.dividend' > "./$dir/_DU" || LASTDU=$(cat ./$dir/_DU)
echo "Valeur courante du DU=$(cat ./$dir/_DU) ZEN - CHAIN: $hop"
read
if [[ ! -f "./$dir/_id" ]]; then echo "SWARM_CODE_MASTER" > "./$dir/_id"; fi
if [[ ! -f "./$dir/_zen" ]]; then echo 0 > "./$dir/_zen"; fi
if [[ ! -f "./$dir/_g1cents" ]]; then echo 0 > "./$dir/_g1cents"; fi
if [[ ! -f "./$dir/_external" ]]; then echo "" > "./$dir/_external"; fi # Used to link to External UniqID
echo $(date +%s%N) > "./$dir/_nanodate"
echo "$now: $COMMENT" >> "./$dir/_comments"
# TAR G1sms+ FILES (WITH EXCLUSIONS!!)
tar -cvzf ~/G1sms+_backup_$now.tar.gz --exclude 'g1sms.preoni.*' --exclude 'authfile' --exclude 'init.sh' --exclude '.git' --exclude 'billets' --exclude 'constants.py' --exclude 'TAG' --exclude 'history*' --exclude 'trash' --exclude 'print' --exclude 'wallets' --exclude 'wallets_swarm' --exclude 'g1sms.priv.key' ./$dir
mkdir -p /tmp/CODE/ && tar xzf ~/G1sms+_backup_$now.tar.gz -C /tmp/CODE/ && rm -f ~/G1sms+_backup_$now.tar.gz
# PUBLISH IT
hash=$(su $YOU -c "ipfs add -rq /tmp/CODE/ -w | tail -n 1")
echo $hash > "./$dir/_chain"
publish=$(su $YOU -c "ipfs name publish -k SWARM_CODE_MASTER --quieter /ipfs/${hash}")
echo $publish > "./$dir/_official"
rm -Rf /tmp/CODE
echo "_CHAIN: NEW /ipfs/$hash // $hop PUBLISHED with \"SWARM_CODE_MASTER\" key
ipfs get --output=./ /ipns/$publish"