forked from axiom-team/astroport
185 lines
7.8 KiB
Bash
Executable File
185 lines
7.8 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
|
|
|
|
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
|
|
if [[ $(whoami) == "root" ]]; then
|
|
export IPFSNODEID=$(su $YOU -c "ipfs id -f='<id>\n'")
|
|
chown -R $YOU /tmp/zen/
|
|
chown $YOU /tmp/g1sms.log
|
|
else
|
|
export IPFSNODEID=$(ipfs id -f='<id>\n')
|
|
fi
|
|
|
|
[[ ! $IPFSNODEID ]] && echo "PROBLEM GETTING IPFSNODEID" & exit 1
|
|
|
|
NANODATE=$(date -u +%s%N) #1569692075385428020
|
|
|
|
## IS IT A SMS NODE (gammu-smsd is installed)??
|
|
if [[ $(which gammu-smsd) ]]; then
|
|
[[ ! $MASTERPHONE ]] && echo "MISSING MASTERPHONE run from init.sh" && exit 1
|
|
echo $MASTERPHONE > /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_sms
|
|
else
|
|
if [ -f /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_sms ]; then rm -f /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_sms; fi
|
|
fi
|
|
|
|
NODE_G1PUBKEY=$(cat /home/$YOU/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
|
|
[[ $NODE_G1PUBKEY == "" ]] && echo "ERROR NODE_G1PUBKEY empty !! Please INIT SSB LAYER..." && exit 1
|
|
|
|
|
|
echo "
|
|
$NANODATE
|
|
_ _ __ __
|
|
(_)___ (_) /_ / /_____ __ _______
|
|
/ / __ \/ / __/ / //_/ _ \/ / / / ___/
|
|
/ / / / / / /_ / ,< / __/ /_/ (__ )
|
|
/_/_/ /_/_/\__/ /_/|_|\___/\__, /____/
|
|
/____/
|
|
|
|
I am $(whoami) on $IPFSNODEID
|
|
|
|
"
|
|
|
|
##################################################################
|
|
# G1sms+ Node KEYS (G1wallet, gpg, IPNS)
|
|
echo '
|
|
|
|
________ ___________ ____ _ __ __
|
|
/ _/ __ \/ ____/ ___// __ \_____(_) __/ //_/__ __ __
|
|
/ // /_/ / /_ \__ \/ /_/ / ___/ / | / / ,< / _ \/ / / /
|
|
_/ // ____/ __/ ___/ / ____/ / / /| |/ / /| / __/ /_/ /
|
|
/___/_/ /_/ /____/_/ /_/ /_/ |___/_/ |_\___/\__, /
|
|
/____/
|
|
Formed with 24 first char IPFS .Identity.PrivKey
|
|
Used as gpg symetric key (soon deprecated?)
|
|
'
|
|
##################################################################
|
|
IPFSPrivKey=$(cat /home/$YOU/.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 /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna ]]; then
|
|
# CREATE NODE G1 KEYS AND FILES
|
|
mkdir -p /home/$YOU/.zen/ipfs/.$IPFSNODEID/TASK
|
|
|
|
####################################################################
|
|
# GIVE NAME TO NODE G1 WALLET: "6789diceware"
|
|
# And write /home/$YOU/.zen/g1sms_wallets/.Qm***/G1SSB/(_files)
|
|
####################################################################
|
|
PRE=${ADMINPHONE:8:4}
|
|
ZUID=$(/home/$YOU/.zen/astroport/zen/tools/diceware.sh 1 | xargs)
|
|
# Check if already existing among all swarm wallets G1SSB or G1SMS
|
|
while [[ $(grep -Rwl "$PRE$ZUID" /home/$YOU/.zen/ipfs_swarm/.*/*/_uidna 2>/dev/null) ]]; do ZUID=$(/home/$YOU/.zen/astroport/zen/tools/diceware.sh 1 | xargs); done
|
|
NODE_UIDNA="$PRE$ZUID"
|
|
|
|
echo "
|
|
__ __________ _ _____
|
|
/ / / / _/ __ \/ | / / |
|
|
/ / / // // / / / |/ / /| |
|
|
/ /_/ // // /_/ / /| / ___ |
|
|
\____/___/_____/_/ |_/_/ |_| create
|
|
|
|
$NODE_UIDNA
|
|
"
|
|
if [[ -f /home/$YOU/.zen/secret.astroport.key ]]; then
|
|
#[[ ! $(cat /home/$YOU/.zen/secret.astroport.key | grep -F 'NODE_UIDNA' )]]
|
|
echo "IPFSNODEID=$IPFSNODEID" >> /home/$YOU/.zen/secret.astroport.key
|
|
echo "NODE_UIDNA=$NODE_UIDNA" >> /home/$YOU/.zen/secret.astroport.key
|
|
else
|
|
echo "ERROR NO /home/$YOU/.zen/secret.astroport.key !!" && exit 1
|
|
fi
|
|
|
|
chmod 400 /home/$YOU/.zen/secret.astroport.key
|
|
|
|
source /home/$YOU/.zen/secret.astroport.key
|
|
|
|
# WRITE NODE_UIDNA
|
|
echo "$NODE_UIDNA" > /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna ####### _uidna
|
|
echo $IPFSNODEID > /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_ipfs.id ####### _ipfs.id
|
|
echo $NANODATE > /home/$YOU/.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 "/home/$YOU/.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 /home/$YOU/.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 /home/$YOU/.zen/ipfs/.$IPFSNODEID"
|
|
if [[ $G1SMS == "YES" ]]; then
|
|
echo "SENDING SMS to $ADMINPHONE"
|
|
sudo gammu-smsd-inject -l TEXT "$ADMINPHONE" -text "[ADMIN] G1sms+ NODE $NODE_UIDNA ($IPFSNODEID)" 1>&2
|
|
sudo gammu-smsd-inject -l TEXT "$ADMINPHONE" -text "$ZENID / $ZENPWD" 1>&2
|
|
sudo gammu-smsd-inject -l TEXT "$ADMINPHONE" -text "$ZENG1" 1>&2
|
|
fi
|
|
fi
|
|
|
|
# COHERENCE TEST
|
|
[[ -f /home/$YOU/.zen/secret.astroport.key ]] && source /home/$YOU/.zen/secret.astroport.key || echo "Missing /home/$YOU/.zen/secret.astroport.key" || exit 1
|
|
[[ -f /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna ]] && NODE_UIDNA=$(cat /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna)|| echo "Missing _uidna" || exit 1
|
|
|
|
## INIT NODE G1 PUB & PRIV KEY
|
|
NODE_G1PUBKEY=$ZENG1
|
|
[[ ! $NODE_G1PUBKEY ]] && echo "Missing NODE_G1PUBKEY" && exit 1
|
|
NODE_PUBSECFILE="/home/$YOU/.ssb/secret.dunikey"
|
|
[[ ! $NODE_PUBSECFILE ]] && echo "Missing NODE_PUBSECFILE" && exit 1
|
|
|
|
##########################################################
|
|
# MEMORIZE NODE NANODATE EXECUTION TIME (for ntpdate regular sync)
|
|
if [[ -f /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nanodate ]]; then
|
|
last=$(cat /home/$YOU/.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 > /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nanodate
|
|
fi
|
|
|
|
################################################################
|
|
# PRINTER CAPACITIES ??
|
|
|
|
## IS THERE USB PRINTER CONNECTED?
|
|
if [[ -e "/dev/usb/lp0" ]]; then
|
|
log "G1CORE: IMPRESSION G1Tag ACTIF .............."
|
|
export PRINT=true
|
|
echo "$ADRESSE" > /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_where
|
|
else
|
|
rm -f /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_where
|
|
fi
|
|
|
|
echo "
|
|
______ _____ ____ __ ___ _ __
|
|
/ ___/ | / / | / __ \/ |/ / (_)___/ /
|
|
\__ \| | /| / / /| | / /_/ / /|_/ / / / __ /
|
|
___/ /| |/ |/ / ___ |/ _, _/ / / / / / /_/ /
|
|
/____/ |__/|__/_/ |_/_/ |_/_/ /_/ /_/\__,_/
|
|
loaded
|
|
/home/$YOU/.zen/secret.astroport.key
|
|
"
|
|
ls -a /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/
|