forked from axiom-team/astroport
120 lines
5.3 KiB
Bash
Executable File
120 lines
5.3 KiB
Bash
Executable File
#!/bin/bash
|
|
##################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# Version: 0.2
|
|
# License: GPL (http://www.google.com/search?q=GPL)
|
|
##################################################################
|
|
# CHECK & WARN | CREATE Keys (gpg encrypt, G1wallet, IPNS publish)
|
|
##################################################################
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
|
|
NODE_G1PUBKEY=$(cat ~/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
|
|
[[ $NODE_G1PUBKEY == "" ]] && echo "ERROR NODE_G1PUBKEY empty !! Please check it..." && exit 1
|
|
|
|
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
|
|
IPFSNODEID=$(ipfs id -f='<id>\n')
|
|
NANODATE=$(date -u +%s%N) #1569692075385428020
|
|
|
|
##################################################################
|
|
# G1sms+ Node KEYS (G1wallet, gpg, IPNS)
|
|
##################################################################
|
|
IPFSPrivKey=$(cat ~/.ipfs/config | jq -r '.Identity.PrivKey') #"
|
|
export IPFSPrivKey="${IPFSPrivKey:0:24}" #
|
|
if [ ! $IPFSPrivKey ]; then echo "FATAL ERROR:: IPFS Node.Identity.PrivKey IPFSPrivKey EMPTY"; exit; fi
|
|
|
|
##################################################################
|
|
# G1sms+ Swarm KEYS
|
|
##################################################################
|
|
# G1sms Service - G1Wallet
|
|
#
|
|
|
|
# ONE TIME GIVE NODE_UIDNA
|
|
if [[ ! -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna ]]; then
|
|
# CREATE NODE G1 KEYS AND FILES
|
|
mkdir -p ~/.zen/ipfs/.$IPFSNODEID/TASK
|
|
####################################################################
|
|
# GIVE NAME TO NODE G1 WALLET: "6789diceware"
|
|
# And write ~/.zen/g1sms_wallets/.Qm***/G1SSB/(_files)
|
|
####################################################################
|
|
PRE=${ADMINPHONE:8:4}
|
|
ZUID=$($MY_PATH/diceware.sh 1 | xargs)
|
|
# Check if already existing among all swarm wallets G1SSB or G1SMS
|
|
while [[ $(grep -Rwl "$PRE$ZUID" ~/.zen/ipfs_swarm/.*/*/_uidna) ]]; do ZUID=$($MY_PATH/diceware.sh 1 | xargs); done
|
|
NODE_UIDNA="$PRE$ZUID"
|
|
NODE_PIN=$($MY_PATH/diceware.sh | xargs)
|
|
|
|
[[ -f ~/.zen/secret.astroport.key ]] \
|
|
&& [[ ! $(cat ~/.zen/secret.astroport.key | grep -F 'NODE_UIDNA' )]] \
|
|
&& chmod 600 ~/.zen/secret.astroport.key
|
|
&& echo "NODE_UIDNA=$NODE_UIDNA" >> ~/.zen/secret.astroport.key
|
|
|
|
source ~/.zen/secret.astroport.key
|
|
|
|
# WRITE NODE_UIDNA
|
|
echo "$NODE_UIDNA" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna ####### _uidna
|
|
echo $IPFSNODEID > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_ipfs.id ####### _ipfs.id
|
|
echo $NANODATE > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_nanodate ####### _nanodate
|
|
|
|
############ If sudo without password activated (Raspbian)
|
|
# SYSTEM MODIFY hosts & hostname ###########################
|
|
# WRITE NODE uidna NAME TO /etc/hosts & .Qm*/_uidna file
|
|
# sudo echo "127.0.0.101 $NODE_UIDNA" >> /etc/hosts
|
|
# sudo echo "$NODE_UIDNA" > /etc/hostname
|
|
############################################################
|
|
|
|
# TODO rewrite AUTO BACKUP / RESTORE
|
|
# tools/natools.py encrypt -p $NODE_G1PUBKEY -i "./authfile" -o "~/.zen/ipfs/.$IPFSNODEID/G1SSB/_authfile.swarm.crypt"
|
|
|
|
# SILKAJ INIT G1 NODE WALLET TODO ACTIVATE
|
|
#duniter_server=$(./tools/duniter_getnode.sh)
|
|
#TX_IN=$(silkaj -p "$duniter_server" -af --file ~/.ssb/secret.dunikey tx --output $SWARM_G1PUBKEY --amount 3.24 --comment "[A.Station] G1SSBIPF ($ADMINPSEUDO) $NODE_UIDNA $IPFSNODEID" -y)
|
|
|
|
log "__SUB:initkeys.sh: [ADMIN] NODE G1sms+ $NODE_UIDNA : ls ~/.zen/ipfs/.$IPFSNODEID"
|
|
gammu-smsd-inject -l TEXT "$ADMINPHONE" -text "[ADMIN] G1sms+ NODE $NODE_UIDNA ($IPFSNODEID)" 1>&2
|
|
gammu-smsd-inject -l TEXT "$ADMINPHONE" -text "$NODE_G1PUBKEY" 1>&2
|
|
|
|
fi
|
|
|
|
# COHERENCE TEST
|
|
[[ -f ~/.zen/secret.astroport.key ]] && source ~/.zen/secret.astroport.key || echo "Missing ~/.zen/secret.astroport.key" && exit 1
|
|
[[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna ]] && NODE_UIDNA=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna)|| echo "Missing _uidna" && exit 1
|
|
|
|
## INIT NODE G1 PUB & PRIV KEY
|
|
NODE_G1PUBKEY=$ZENG1
|
|
NODE_G1AUTHFILE="~/.ssb/secret.dunikey"
|
|
|
|
##########################################################
|
|
# MEMORIZE NODE NANODATE EXECUTION TIME (for ntpdate regular sync)
|
|
if [[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_nanodate ]]; then
|
|
last=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_nanodate)
|
|
timediff=$( echo "${NANODATE} - ${last}" | bc -l )
|
|
# NODE TIME SYNC 600 milliards de nanosecondes = 600 s = 10 mn
|
|
if [[ $timediff -gt 600000000000 ]]; then
|
|
# TODO RUN & LOG ntpdate
|
|
#ntpdate pool.ntp.org
|
|
#log "__SUB:ntpdate pool.ntp.org: $timediff $(ntpdate pool.ntp.org)"
|
|
export NANODATE=$(date -u +%s%N)
|
|
fi
|
|
echo $NANODATE > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_nanodate
|
|
fi
|
|
|
|
################################################################
|
|
#INFORM ABOUT NODE CAPACITIES
|
|
export NODEPUB=$(cat "~/.zen/ipfs/.$IPFSNODEID/G1SSB/_pub")
|
|
|
|
## IS IT A SMS NODE (gammu-smsd is installed)??
|
|
if [[ $G1SMS ]]; then
|
|
echo $MASTERPHONE > "~/.zen/ipfs/.$IPFSNODEID/G1SSB/_sms"
|
|
else
|
|
if [ -f "~/.zen/ipfs/.$IPFSNODEID/G1SSB/_sms" ]; then rm -f "~/.zen/ipfs/.$IPFSNODEID/G1SSB/_sms"; fi
|
|
fi
|
|
|
|
## IS THERE USB PRINTER CONNECTED?
|
|
if [[ -e "/dev/usb/lp0" ]]; then
|
|
log "G1CORE: IMPRESSION G1Tag ACTIF .............."
|
|
PRINT=true
|
|
# echo $ADRESSE > "~/.zen/ipfs/.$IPFSNODEID/G1SSB/_where"
|
|
fi
|
|
|