#!/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) ################################################################## 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+ CHEMIN="/home/$YOU/G1sms+" ################################################################## # G1sms+ Node KEYS (G1wallet, gpg, IPNS) ################################################################## export GPGPASS=$(cat "/home/$YOU/.ipfs/config" | jq '.Identity.PrivKey' | sed s/\"//g) ################################################################## # G1sms+ Swarm KEYS ################################################################## # G1sms Service - G1Wallet if [[ -f "${CHEMIN}/g1sms.pub.key" && -f "${CHEMIN}/g1sms.priv.key" ]]; then chown root:root ${CHEMIN}/g1sms.priv.key chmod 600 ${CHEMIN}/g1sms.priv.key export MASTERPUB=$(cat "${CHEMIN}/g1sms.pub.key") export MASTERKEYFILE="${CHEMIN}/g1sms.priv.key" else echo "ATTENTION!! Vous devez posséder la clef du G1 Wallet utilisé par le SWARM G1sms!!" ./shell/parle.sh "Les clefs du portefeuille essaim G1 SMS sont absente. Au revoir." echo "Fichiers manquants:" echo "${CHEMIN}/g1sms.pub.key" echo "${CHEMIN}/g1sms.priv.key" echo "Contactez nous sur https://g1sms.fr" 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 exit fi ################################################################## # NODE KEYS (SCRIPT CALLED BY ROOT !!! gammu is root) ################################################################## export IPFSNODEID=$(su $YOU -c "ipfs id -f='\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 # NODE TIME SYNC 120 milliards de nanosecondes if [[ $timediff -gt 120000000000 ]]; then log "__SUB:ntpdate pool.ntp.org: $timediff $(ntpdate pool.ntp.org)" export NANODATE=$(date -u +%s%N) fi fi echo $NANODATE > ./wallets/.$IPFSNODEID/$IPFSNODEID.nanodate ################################################################# # 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 NODEG1WALLET=$(./silkaj/silkaj generate_auth_file --auth-scrypt -salt="$IPFSNODEID" -password="$GPGPASS") echo "${GPGPASS}" | gpg -q --output "./wallets/.$IPFSNODEID/$IPFSNODEID.authfile.GPGPASS.gpg" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "./authfile" ./shell/natools.py encrypt -p $NODEG1WALLET -i "./authfile" -o "./wallets/.$IPFSNODEID/$IPFSNODEID.authfile.crypt" rm -f ./authfile 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 ./shell/natools.py encrypt -p $MASTERPUB -i "/home/$YOU/.ipfs/config" -o "./wallets/.$IPFSNODEID/$IPFSNODEID.ipfsconfig.crypt" 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 echo "$UIDNA$TAIL" > "./wallets/.$IPFSNODEID/$IPFSNODEID.uidna" # CREATE NODE WALLET LIKE A PHONE (Stored in wallets/.$IPFSNODEID) 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 TX_IN=$(./silkaj/silkaj transaction --auth-file -file="$MASTERKEYFILE" --amount=3.15 --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=$MASTERPUB --comment="[G1sms+] G1NODE $IPFSNODEID:ACK" -y) 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 ################################################################ #INFORM ABOUT NODE CAPACITIES export NODEG1PUB=$(cat "./wallets/.$IPFSNODEID/$IPFSNODEID.pub") ## 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