2019-11-27 23:43:32 +01:00
#!/bin/bash
##################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: GPL (http://www.google.com/search?q=GPL)
##################################################################
# CHECK & WARN | CREATE Keys (gpg encrypt, G1wallet, IPNS publish)
##################################################################
2019-12-20 19:59:01 +01:00
MY_PATH = " `dirname \" $0 \"` " # relative
MY_PATH = " `( cd \" $MY_PATH \" && pwd )` " # absolutized and normalized
2019-12-21 22:58:36 +01:00
if [ [ -f $MY_PATH /.install/.GPATH ] ] ; then source $MY_PATH /.install/.GPATH; fi
if [ [ -f $MY_PATH /../.install/.GPATH ] ] ; then source $MY_PATH /../.install/.GPATH; fi
2019-12-20 19:59:01 +01:00
2019-11-27 23:43:32 +01:00
YOU = $( ps aux --sort= +utime | grep ipfs | tail -n 1 | cut -d " " -f 1)
# TODO Make it directory independant. (for now it is tested for pi running ipfs and code in $HOME/G1sms+
##################################################################
# G1sms+ Node KEYS (G1wallet, gpg, IPNS)
##################################################################
export GPGPASS = $( cat " /home/ $YOU /.ipfs/config " | jq '.Identity.PrivKey' | sed s/\" //g)
2019-12-15 21:35:51 +01:00
if [ ! $GPGPASS ] ; then echo "FATAL ERROR:: IPFS Node.Identity.PrivKey GPGPASS EMPTY" ; exit; fi
2019-11-27 23:43:32 +01:00
2019-12-26 17:44:26 +01:00
# GET SWARM KEY G1sms+ .ipfs/swarm.key
export SWARMKEY = $( cat " /home/ $YOU /.ipfs/swarm.key " | tail -n 1)
if [ ! $SWARMKEY ] ; then echo "FATAL ERROR:: .ipfs/swarm.key EMPTY" ; exit; fi
2019-11-27 23:43:32 +01:00
##################################################################
# G1sms+ Swarm KEYS
##################################################################
# G1sms Service - G1Wallet
2019-12-20 19:59:01 +01:00
if [ [ -f " ${ GPATH } /g1sms.pub.key " && -f " ${ GPATH } /g1sms.priv.key " ] ] ; then
chown root:root ${ GPATH } /g1sms.priv.key
chmod 600 ${ GPATH } /g1sms.priv.key
2019-12-24 05:47:47 +01:00
export NODE_G1PUBKEY = $( cat " ${ GPATH } /g1sms.pub.key " )
export NODE_G1PRIVKEYFILE = " ${ GPATH } /g1sms.priv.key "
2019-11-27 23:43:32 +01:00
else
2019-12-26 17:44:26 +01:00
echo "ATTENTION!! Vous devez installer une clef de G1 Wallet!!"
./shell/parle.sh "Il manque les Clefs du portefeuille G1 de votre noeud. Au revoir."
2019-11-27 23:43:32 +01:00
echo "Fichiers manquants:"
2019-12-20 19:59:01 +01:00
echo " ${ GPATH } /g1sms.pub.key "
echo " ${ GPATH } /g1sms.priv.key "
2019-11-27 23:43:32 +01:00
echo "Contactez nous sur https://g1sms.fr"
2019-12-21 22:58:36 +01:00
log " ${ GPATH } /g1sms.pub.key "
log " ${ GPATH } /g1sms.priv.key "
2019-11-27 23:43:32 +01:00
gammu-smsd-inject -l TEXT " $ADMINPHONE " -text "Clef de G1Wallet du SWARM g1sms.priv.key manquante! contactez-nous pour la recevoir https://g1sms.fr" 1>& 2
2019-12-21 22:58:36 +01:00
gammu-smsd-inject -l TEXT " $ADMINPHONE " -text " Debug: ${ GPATH } /g1sms.pub.key et ${ GPATH } /g1sms.priv.key " 1>& 2
2019-11-27 23:43:32 +01:00
exit
fi
##################################################################
# NODE KEYS (SCRIPT CALLED BY ROOT !!! gammu is root)
##################################################################
export IPFSNODEID = $( su $YOU -c "ipfs id -f='<id>\n'" )
export NANODATE = $( date -u +%s%N) #1569692075385428020
# CHECK LAST TIME NODE HAD ACTION
if [ [ -f ./wallets/.$IPFSNODEID /$IPFSNODEID .nanodate ] ] ; then
last = $( cat ./wallets/.$IPFSNODEID /$IPFSNODEID .nanodate)
timediff = $( echo " ${ NANODATE } - ${ last } " | bc -l )
# Get median nanodate before
2019-12-17 17:22:06 +01:00
# NODE TIME SYNC 120 milliards de nanosecondes = 120s
2019-11-27 23:43:32 +01:00
if [ [ $timediff -gt 120000000000 ] ] ; then
log " __SUB:ntpdate pool.ntp.org: $timediff $( ntpdate pool.ntp.org) "
export NANODATE = $( date -u +%s%N)
fi
fi
#################################################################
# CREATE NODE .$IPFSNODEID SPACE (G1Wallet + TASK + NODE DETAILS)
#################################################################
# Create G1sms Wallet with that NODE G1 wallet as member reference
if [ [ ! -f " ./wallets/. $IPFSNODEID / $IPFSNODEID .pub " ] ] ; then
mkdir -p ./wallets/.$IPFSNODEID /TASK
2019-12-15 21:35:51 +01:00
# TODO @poka ?? Place in install sequence: Create Node G1 Wallet (login=ipfsID pass=ipfsPrivKey)
2019-11-27 23:43:32 +01:00
NODEG1WALLET = $( ./silkaj/silkaj generate_auth_file --auth-scrypt -salt= " $IPFSNODEID " -password= " $GPGPASS " )
2019-12-12 20:07:53 +01:00
if [ [ ! $NODEG1WALLET ] ] ; then echo " PROBLEME CREATION DU WALLET G1 DE $IPFSNODEID " ; exit; fi
2019-12-15 21:35:51 +01:00
# Backup authfile GPG with IPFS NODE PRIVATE KEY
2019-11-27 23:43:32 +01:00
echo " ${ GPGPASS } " | gpg -q --output " ./wallets/. $IPFSNODEID / $IPFSNODEID .authfile.GPGPASS.gpg " --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "./authfile"
2019-12-15 21:35:51 +01:00
# Backup authfile CYPHER with NODE G1 WALLET PUB KEY
2019-11-27 23:43:32 +01:00
./shell/natools.py encrypt -p $NODEG1WALLET -i "./authfile" -o " ./wallets/. $IPFSNODEID / $IPFSNODEID .authfile.crypt "
2019-12-15 21:35:51 +01:00
# TODO ADD ACCESS TO OTHER SWARM NODES CYPHERING WITH ALL ACTUAL NODES G1WALLET PUB KEYS
2019-12-24 05:47:47 +01:00
# USEFUL TO OPERATE G1TAG WITHOUT SHARING NODE_G1PRIVKEYFILE...
2019-12-15 21:35:51 +01:00
# for nodepubfile in ./wallets_swarm/.Qm*/*.pub; do
# nodeG1pub=$(cat $nodepubfile)
# nodeID=$(echo $all | cut -d '/' -f 3)
# ./shell/natools.py encrypt -p $nodeG1pub -i "./authfile" -o "./wallets/.$IPFSNODEID/$nodeID.authfile.crypt"
# done
# Keep Node G1 wallet authfile in G1sms+ root
mv -f ./authfile ../
2019-11-27 23:43:32 +01:00
echo $NODEG1WALLET > " ./wallets/. $IPFSNODEID / $IPFSNODEID .pub "
echo $IPFSNODEID > " ./wallets/. $IPFSNODEID / $IPFSNODEID .ipfsid "
log " __SUB:initkeys.sh: [ADMIN] G1sms+ CREATE G1WALLET FOR: $IPFSNODEID : pub = $NODEG1WALLET "
# BACKUP $IPFSNODEID config
2019-12-24 05:47:47 +01:00
./shell/natools.py encrypt -p $NODE_G1PUBKEY -i " /home/ $YOU /.ipfs/config " -o " ./wallets/. $IPFSNODEID / $IPFSNODEID .ipfsconfig.crypt "
2019-11-27 23:43:32 +01:00
log " __SUB:initkeys.sh: [ADMIN] BACKUP $IPFSNODEID NODE CONFIG to ./wallets/. $IPFSNODEID / $IPFSNODEID .ipfsconfig.crypt "
#######################
# GIVE NAME TO WALLET
#######################
# 4 derniers chiffres du numéro de téléphone
TAIL = ${ MASTERPHONE : 8 : 4 }
# No UIDNA yet. Create new
UIDNA = $( ./shell/diceware.sh 1 | xargs)
# Check if already existing among all swarm wallets
while [ [ $( grep -Rwl " $UIDNA $TAIL " ./wallets_swarm/*/*.uidna) ] ] ; do UIDNA = $( ./shell/diceware.sh 1 | xargs) ; done
2019-12-15 21:35:51 +01:00
# WRITE NODE uidna NAME TO /etc/hosts & .Qm*/Qm*.uidna file
echo " 127.0.0.101 $UIDNA $TAIL " >> "/etc/hosts"
2019-11-27 23:43:32 +01:00
echo " $UIDNA $TAIL " > " ./wallets/. $IPFSNODEID / $IPFSNODEID .uidna "
2019-12-15 21:35:51 +01:00
# TODO: MAYBE REMOVE THAT CREATE NODE WALLET LIKE A PHONE (Stored in wallets/.$IPFSNODEID) BUT CREATE & ATTACH G1TAG INSTEAD
2019-11-27 23:43:32 +01:00
echo " ${ GPGPASS } " > " ./wallets/. $IPFSNODEID / $IPFSNODEID .pin "
echo " ${ GPGPASS } " | gpg -q --output " ./wallets/. $IPFSNODEID / $IPFSNODEID .pin.gpg " --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 " ./wallets/. $IPFSNODEID / $IPFSNODEID .pin "
echo "" > " ./wallets/. $IPFSNODEID / $IPFSNODEID .pin "
echo " $UIDNA $TAIL " > " ./wallets/. $IPFSNODEID / $IPFSNODEID .uidna "
echo "314" > " ./wallets/. $IPFSNODEID / $IPFSNODEID .g1cents "
echo $NODEG1WALLET > " ./wallets/. $IPFSNODEID / $IPFSNODEID .pub "
# SILKAJ INIT G1 NODE WALLET
2019-12-24 05:47:47 +01:00
TX_IN = $( ./silkaj/silkaj transaction --auth-file -file= " $NODE_G1PRIVKEYFILE " --amount= 3.24 --output= $NODEG1WALLET --comment= " [G1sms+] G1NODE ( $ADMINPSEUDO ) $UIDNA $TAIL $IPFSNODEID " -y)
TX_OUT = $( ./silkaj/silkaj transaction --auth-scrypt -salt= " $IPFSNODEID " -password= " $GPGPASS " --amount= 0.1 --output= $NODE_G1PUBKEY --comment= " [G1sms+] G1NODE $IPFSNODEID :ACK " -y)
2019-11-27 23:43:32 +01:00
log " __SUB:initkeys.sh: [ADMIN] G1sms+ $ADMINPSEUDO - $UIDNA $TAIL OUVERT POUR NODE: ls ./wallet/. $IPFSNODEID "
gammu-smsd-inject -l TEXT " $ADMINPHONE " -text " [ADMIN] G1sms+ $ADMINPSEUDO - $UIDNA $TAIL OUVERT POUR NODE: ls ./wallets/. $IPFSNODEID " 1>& 2
gammu-smsd-inject -l TEXT " $ADMINPHONE " -text " $NODEG1WALLET " 1>& 2
fi
2019-12-12 20:07:53 +01:00
echo $NANODATE > ./wallets/.$IPFSNODEID /$IPFSNODEID .nanodate
2019-11-27 23:43:32 +01:00
################################################################
#INFORM ABOUT NODE CAPACITIES
2019-12-10 02:31:15 +01:00
export NODEPUB = $( cat " ./wallets/. $IPFSNODEID / $IPFSNODEID .pub " )
2019-11-27 23:43:32 +01:00
## IS IT A SMS NODE (gammu-smsd is installed)??
if [ [ $G1SMS ] ] ; then
echo $MASTERPHONE > " ./wallets/. $IPFSNODEID / $IPFSNODEID .sms "
else
if [ -f " ./wallets/. $IPFSNODEID / $IPFSNODEID .sms " ] ; then rm -f " ./wallets/. $IPFSNODEID / $IPFSNODEID .sms " ; fi
fi
## IS THERE USB PRINTER CONNECTED?
if [ [ -e "/dev/usb/lp0" ] ] ; then
log "G1CORE: IMPRESSION G1Tag ACTIF .............."
echo $ADRESSE > " ./wallets/. $IPFSNODEID / $IPFSNODEID .where "
fi
## IS THERE SERIAL QR CODE READER CONNECTED?
if [ [ -e "/dev/ttyACM0" ] ] ; then
log "G1CORE: SCAN G1Tag ACTIF .............."
export G1TX = "YES"
echo "/dev/ttyACM0" > " ./wallets/. $IPFSNODEID / $IPFSNODEID .scan "
else
if [ -f " ./wallets/. $IPFSNODEID / $IPFSNODEID .scan " ] ; then rm -f " ./wallets/. $IPFSNODEID / $IPFSNODEID .scan " ; fi
fi