2022-03-02 18:37:42 +01:00
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
################################################################################
#
2022-08-23 14:41:15 +02:00
MY_PATH = " `dirname \" $0 \"` " # relative
MY_PATH = " `( cd \" $MY_PATH \" && pwd )` " # absolutized and normalized
ME = " ${ 0 ##*/ } "
2022-08-20 17:12:15 +02:00
SALT = " $1 "
PEPPER = " $2 "
2022-08-22 17:38:25 +02:00
## Chargement TW !!!
if [ [ $SALT != "" && PEPPER != "" ] ] ; then
2022-08-23 14:36:40 +02:00
ASTRO = ""
2022-08-23 14:41:15 +02:00
echo " $SALT "
echo " $PEPPER "
2022-08-22 17:38:25 +02:00
ipfs key rm gchange
rm -f ~/.zen/tmp/gchange.key
${ MY_PATH } /keygen -t ipfs -o ~/.zen/tmp/gchange.key " $SALT " " $PEPPER "
GNS = $( ipfs key import gchange -f pem-pkcs8-cleartext ~/.zen/tmp/gchange.key )
2022-08-24 11:40:49 +02:00
mkdir -p ~/.zen/tmp/TW
rm -f ~/.zen/tmp/TW/index.html
ipfs --timeout 6s cat /ipns/$GNS > ~/.zen/tmp/TW/index.html
2022-08-22 17:38:25 +02:00
# Combien de clefs?
ipfs key list -l | grep -w $GNS
ipfs key list -l | grep -w $GNS | wc -l
2022-08-24 11:50:26 +02:00
if [ ! -s ~/.zen/tmp/TW/index.html ] ; then
rm -f ~/.zen/tmp/TW/index.html
2022-08-24 11:40:49 +02:00
echo "Aucun ancien TW détecté! Appuyez sur ENTRER pour créer un nouveau TW Astronaute"
2022-08-23 19:55:13 +02:00
read
else
ASTRO = "yes"
echo "Bienvenue Astronaute. Nous avons capté votre TW"
echo " http://127.0.0.1:8080/ipns/ $GNS "
echo "Initialisation de votre compte local"
fi
2022-08-22 17:38:25 +02:00
fi
2022-08-23 14:36:40 +02:00
2022-08-20 17:12:15 +02:00
echo " =============================================
2022-03-02 18:37:42 +01:00
MadeInZion DIPLOMATIC PASSPORT
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
A cryptographic key pair to control your P2P Digital Life.
Solar Punk garden forest terraforming game.
2022-05-02 23:10:48 +02:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Bienvenue 'Astronaute' " ; sleep 1
2022-03-05 02:16:41 +01:00
2022-05-02 23:10:48 +02:00
echo ""
2022-08-22 17:38:25 +02:00
echo "Création de votre PSEUDO, votre PLAYER, avec PASS (6 chiffres)"
2022-05-08 04:39:40 +02:00
2022-03-02 18:37:42 +01:00
################################################################################
MY_PATH = " `dirname \" $0 \"` " # relative
MY_PATH = " `( cd \" $MY_PATH \" && pwd )` " # absolutized and normalized
ME = " ${ 0 ##*/ } "
2022-07-07 13:16:39 +02:00
! ipfs swarm peers >/dev/null 2>& 1 && echo "Lancez 'ipfs daemon' SVP" && exit 1
2022-03-02 18:37:42 +01:00
2022-08-20 17:12:15 +02:00
[ [ $SALT = = "" ] ] && SALT = $( ${ MY_PATH } /diceware.sh 4 | xargs)
2022-08-22 17:38:25 +02:00
echo " -> SALT : $SALT "
2022-03-02 18:37:42 +01:00
2022-08-22 17:38:25 +02:00
[ [ $PEPPER = = "" ] ] && PEPPER = $( ${ MY_PATH } /diceware.sh 2 | xargs)
echo " -> PEPPER : $PEPPER "
2022-05-02 23:10:48 +02:00
2022-08-20 17:12:15 +02:00
echo "CHOISISSEZ UN PSEUDO" && read PSEUDO; PSEUDO = ${ PSEUDO ,, } && [ [ $( ls ~/.zen/game/players/$PSEUDO * 2>/dev/null) ] ] && echo "CE PSEUDO EST DEJA UN PLAYER. EXIT" && exit 1
2022-04-26 14:16:57 +02:00
# PSEUDO=${PSEUDO,,} #lowercase
2022-04-23 18:33:23 +02:00
PLAYER = ${ PSEUDO } ${ RANDOM : 0 : 2 } $( ${ MY_PATH } /diceware.sh 1 | xargs) ${ RANDOM : 0 : 2 }
2022-08-15 19:07:39 +02:00
[ [ -d ~/.zen/game/players/$PLAYER ] ] && echo " FATAL ERROR $PLAYER NAME COLLISION. TRY AGAIN. " && exit 1
2022-03-02 18:37:42 +01:00
[ [ ! $PSEUDO ] ] && PSEUDO = $PLAYER
2022-08-20 17:12:15 +02:00
echo; echo "Génération de vos identités Astronaute (PLAYER):" ; sleep 1; echo " $PLAYER " ; sleep 2
2022-03-02 18:37:42 +01:00
2022-08-15 19:07:39 +02:00
# 6 DIGIT PASS CODE TO PROTECT QRSEC
2022-03-02 18:37:42 +01:00
PASS = $( echo " ${ RANDOM } ${ RANDOM } ${ RANDOM } ${ RANDOM } " | tail -c-7)
2022-04-26 14:16:57 +02:00
2022-05-02 23:10:48 +02:00
############################################################
2022-08-15 19:07:39 +02:00
######### TODO Ajouter d'autres clefs IPNS, GPG ?
# MOANS=$(ipfs key gen moa_$PLAYER)
# MOAKEYFILE=$(${MY_PATH}/give_me_keystore_filename.py "moa_$PLAYER")
2022-05-02 23:10:48 +02:00
# echo "Coffre personnel multimedia journalisé dans votre 'Astroport' (amis de niveau 3)"
2022-08-20 17:12:15 +02:00
# echo "Votre clef moa_$PLAYER <=> $MOANS ($MOAKEYFILE)"; sleep 2
2022-08-15 19:07:39 +02:00
############################################################
2022-03-02 18:37:42 +01:00
2022-08-20 17:12:15 +02:00
echo " Compte Gchange et portefeuille G1.
2022-03-05 02:16:41 +01:00
Utilisez ces identifiants pour rejoindre le réseau JUNE
2022-05-02 23:10:48 +02:00
2022-03-05 02:16:41 +01:00
$SALT
$PEPPER
2022-05-02 23:10:48 +02:00
Rendez-vous sur https://gchange.fr" ; sleep 3
2022-08-15 19:07:39 +02:00
echo; echo "Création de votre clef multi-accès..." ; sleep 2
2022-05-02 23:10:48 +02:00
echo;
2022-04-26 14:16:57 +02:00
2022-08-15 19:07:39 +02:00
${ MY_PATH } /keygen -t duniter -o /tmp/secret.dunikey " $SALT " " $PEPPER "
2022-07-07 13:44:45 +02:00
G1PUB = $( cat /tmp/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
2022-04-26 14:16:57 +02:00
2022-08-15 19:07:39 +02:00
[ [ ! $G1PUB ] ] && echo "Désolé. clef Cesium absente." && exit 1
2022-05-02 23:10:48 +02:00
## CREATE Player personnal files storage and IPFS publish directory
mkdir -p ~/.zen/game/players/$PLAYER # Prepare PLAYER datastructure
2022-07-07 13:44:45 +02:00
mkdir -p ~/.zen/tmp/
2022-04-26 14:16:57 +02:00
mv /tmp/secret.dunikey ~/.zen/game/players/$PLAYER /
2022-05-02 23:10:48 +02:00
2022-08-15 19:07:39 +02:00
# Create Player "IPNS Key" (key import)
${ MY_PATH } /keygen -t ipfs -o ~/.zen/game/players/$PLAYER /secret.player " $SALT " " $PEPPER "
ipfs key import $PLAYER -f pem-pkcs8-cleartext ~/.zen/game/players/$PLAYER /secret.player
2022-08-18 03:47:49 +02:00
ASTRONAUTENS = $( ipfs key import $G1PUB -f pem-pkcs8-cleartext ~/.zen/game/players/$PLAYER /secret.player)
2022-08-15 19:07:39 +02:00
2022-05-02 23:10:48 +02:00
mkdir -p ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /G1SSB # Prepare astrXbian sub-datastructure
2022-06-20 18:38:22 +02:00
mkdir -p ~/.zen/game/players/$PLAYER /ipfs_swarm
2022-05-02 23:10:48 +02:00
2022-08-22 17:38:25 +02:00
qrencode -s 12 -o ~/.zen/game/players/$PLAYER /QR.png " $G1PUB "
2022-05-09 01:41:40 +02:00
cp ~/.zen/game/players/$PLAYER /QR.png ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /QR.png
2022-05-02 23:10:48 +02:00
echo " $G1PUB " > ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /G1SSB/_g1.pubkey # G1SSB NOTATION (astrXbian compatible)
2022-04-26 14:16:57 +02:00
secFromDunikey = $( cat ~/.zen/game/players/$PLAYER /secret.dunikey | grep "sec" | cut -d ' ' -f2)
2022-03-05 02:16:41 +01:00
echo " $secFromDunikey " > /tmp/${ PSEUDO } .sec
openssl enc -aes-256-cbc -salt -in /tmp/${ PSEUDO } .sec -out " /tmp/enc. ${ PSEUDO } .sec " -k $PASS 2>/dev/null
PASsec = $( cat /tmp/enc.${ PSEUDO } .sec | base58) && rm -f /tmp/${ PSEUDO } .sec
2022-08-22 17:38:25 +02:00
qrencode -s 12 -o $HOME /.zen/game/players/$PLAYER /QRsec.png $PASsec
2022-03-02 18:37:42 +01:00
2022-08-20 17:12:15 +02:00
echo " Votre Clef publique G1 est : $G1PUB " ; sleep 1
2022-05-02 23:10:48 +02:00
### INITALISATION WIKI dans leurs répertoires de publication IPFS
############ TODO améliorer templates, sed, ajouter index.html, etc...
MOATS = $( date -u +"%Y%m%d%H%M%S%4N" )
2022-08-22 17:38:25 +02:00
if [ ! -f ~/.zen/tmp/TW.html ] ; then
2022-08-15 19:07:39 +02:00
echo "Nouveau Canal TW Astronaute"
mkdir -p ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/
cp ~/.zen/Astroport.ONE/templates/twdefault.html ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
sed -i " s~_BIRTHDATE_~ ${ MOATS } ~g " ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
sed -i " s~_PLAYER_~ ${ PLAYER } ~g " ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-18 18:32:01 +02:00
sed -i " s~_PSEUDO_~ ${ PSEUDO } ~g " ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
sed -i " s~_WISHKEY_~ ${ G1PUB } ~g " ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-15 19:07:39 +02:00
sed -i " s~_G1PUB_~ ${ G1PUB } ~g " ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-18 03:47:49 +02:00
sed -i " s~_QRSEC_~ ${ PASsec } ~g " ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-15 19:07:39 +02:00
2022-08-23 18:02:45 +02:00
sed -i "s~G1Voeu~G1Visa~g" ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-15 19:07:39 +02:00
2022-08-18 03:47:49 +02:00
ASTRONAUTENS = $( ipfs key list -l | grep -w " ${ PLAYER } " | cut -d ' ' -f 1)
2022-08-15 19:07:39 +02:00
# La Clef IPNS porte comme nom G1PUB.
2022-08-18 03:47:49 +02:00
sed -i " s~_MEDIAKEY_~ ${ PLAYER } ~g " ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
sed -i " s~k2k4r8naeti1ny2hsk3a0ziwz22urwiu633hauluwopf4vwjk4x68qgk~ ${ ASTRONAUTENS } ~g " ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-15 19:07:39 +02:00
sed -i "s~ipfs.infura.io~tube.copylaradio.com~g" ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-23 14:24:18 +02:00
myIP = $( hostname -I | awk '{print $1}' | head -n 1)
2022-08-23 16:31:40 +02:00
sed -i " s~127.0.0.1~ $myIP ~g " ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-23 14:24:18 +02:00
tiddlywiki --verbose --load ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html \
--import ~/.zen/Astroport.ONE/templates/data/local.api.json "application/json" \
--import ~/.zen/Astroport.ONE/templates/data/local.gw.json "application/json" \
--output ~/.zen/tmp --render " $:/core/save/all " "newindex.html" "text/plain"
[ [ -f ~/.zen/tmp/newindex.html ] ] && cp ~/.zen/tmp/newindex.html ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-15 19:07:39 +02:00
2022-08-22 17:38:25 +02:00
## ID CARD
convert ~/.zen/game/players/$PLAYER /QR.png -resize 300 /tmp/QR.png
convert ${ MY_PATH } /../images/astroport.jpg -resize 300 /tmp/ASTROPORT.png
composite -compose Over -gravity SouthWest -geometry +280+20 /tmp/ASTROPORT.png ${ MY_PATH } /../images/Brother_600x400.png /tmp/astroport.png
composite -compose Over -gravity NorthWest -geometry +0+0 /tmp/QR.png /tmp/astroport.png /tmp/one.png
# composite -compose Over -gravity NorthWest -geometry +280+280 ~/.zen/game/players/.current/QRsec.png /tmp/one.png /tmp/image.png
convert -gravity northwest -pointsize 35 -fill black -draw " text 50,300 \" $PSEUDO \" " /tmp/one.png /tmp/image.png
convert -gravity northwest -pointsize 30 -fill black -draw " text 300,40 \" $PLAYER \" " /tmp/image.png /tmp/pseudo.png
convert -gravity northeast -pointsize 25 -fill black -draw " text 20,180 \" $PASS \" " /tmp/pseudo.png /tmp/pass.png
convert -gravity northwest -pointsize 25 -fill black -draw " text 300,100 \" $SALT \" " /tmp/pass.png /tmp/salt.png
convert -gravity northwest -pointsize 25 -fill black -draw " text 300,140 \" $PEPPER \" " /tmp/salt.png ~/.zen/game/players/$PLAYER /ID.png
# INSERTED IMAGE IPFS
IASTRO = $( ipfs add -Hq ~/.zen/game/players/$PLAYER /ID.png | tail -n 1)
sed -i " s~bafybeidhghlcx3zdzdah2pzddhoicywmydintj4mosgtygr6f2dlfwmg7a~ ${ IASTRO } ~g " ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-18 18:32:01 +02:00
2022-08-23 14:36:40 +02:00
else
2022-08-18 18:32:01 +02:00
2022-08-23 14:44:43 +02:00
cp ~/.zen/tmp/TW/index.html ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-18 18:32:01 +02:00
2022-08-22 17:38:25 +02:00
fi
2022-08-23 14:36:40 +02:00
## Copy Astro TW
2022-08-24 11:40:49 +02:00
[ [ $ASTRO = = "yes" ] ] && cp ~/.zen/tmp/TW/index.html ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html
2022-08-23 14:36:40 +02:00
2022-08-18 03:47:49 +02:00
echo " ## PUBLISHING ${ PLAYER } /ipns/ $ASTRONAUTENS / "
2022-08-24 11:40:49 +02:00
IPUSH = $( ipfs add -Hq ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/index.html | tail -n 1)
2022-08-23 14:36:40 +02:00
echo $IPUSH > ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/.chain # Contains last IPFS backup PLAYER KEY
2022-08-18 18:32:01 +02:00
echo " /ipfs/ $IPUSH "
2022-08-23 14:36:40 +02:00
echo $MOATS > ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /moa/.moats
2022-08-15 19:07:39 +02:00
ipfs name publish --key= ${ PLAYER } /ipfs/$IPUSH 2>/dev/null
# Lanch newly created TW
# cd ~/.zen/game/players/$PLAYER/ipfs/.$PeerID/
# tiddlywiki $PLAYER --verbose --load ~/.zen/game/players/$PLAYER/ipfs/.$PeerID/moa/index.html --listen port=8282
# sleep 3
# killall node
## MEMORISE PLAYER Ŋ1 ZONE
echo " $PLAYER " > ~/.zen/game/players/$PLAYER /.player
2022-05-02 23:10:48 +02:00
echo " $PSEUDO " > ~/.zen/game/players/$PLAYER /.pseudo
2022-05-07 18:53:11 +02:00
echo " $G1PUB " > ~/.zen/game/players/$PLAYER /.g1pub
# astrXbian compatible IPFS sub structure =>$XZUID
cp ~/.zen/game/players/$PLAYER /.player ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /_xbian.zuid
2022-06-22 18:32:49 +02:00
cp ~/.zen/game/players/$PLAYER /.player ~/.zen/game/players/$PLAYER /ipfs/.$PeerID /
2022-08-15 19:07:39 +02:00
# PUBLIC Ŋ7 ZONE
2022-05-02 23:10:48 +02:00
2022-08-15 19:07:39 +02:00
echo " $ASTRONAUTENS " > ~/.zen/game/players/$PLAYER /.playerns
2022-05-05 04:12:07 +02:00
2022-05-02 23:10:48 +02:00
echo " $SALT " > ~/.zen/game/players/$PLAYER /secret.june
echo " $PEPPER " >> ~/.zen/game/players/$PLAYER /secret.june
2022-08-15 19:07:39 +02:00
rm -f ~/.zen/game/players/.current
ln -s ~/.zen/game/players/$PLAYER ~/.zen/game/players/.current
2022-03-02 18:37:42 +01:00
2022-08-22 17:38:25 +02:00
qrencode -s 12 -o " $HOME /.zen/game/players/ $PLAYER /QR.ASTRONAUTENS.png " " http://127.0.0.1:8080/ipns/ $ASTRONAUTENS "
2022-03-02 18:37:42 +01:00
2022-08-18 03:47:49 +02:00
echo; echo "Création de votre clef et QR codes de votre réseau Astroport Ŋ1" ; sleep 1
2022-03-02 18:37:42 +01:00
2022-08-20 17:12:15 +02:00
echo; echo " *** Espace Astronaute Activé : ~/.zen/game/players/ $PLAYER / " ; sleep 1
2022-08-23 18:02:45 +02:00
echo; echo " *** Votre TW Ŋ7 : $PLAYER " ; echo " http:// $myIP :8080/ipns/ $ASTRONAUTENS " ; sleep 2
2022-03-02 18:37:42 +01:00
# PASS CRYPTING KEY
2022-08-20 17:12:15 +02:00
echo; echo "Sécurisation de vos clefs par chiffrage SSL... " ; sleep 1
2022-04-26 14:16:57 +02:00
openssl enc -aes-256-cbc -salt -in " $HOME /.zen/game/players/ $PLAYER /secret.june " -out " $HOME /.zen/game/players/ $PLAYER /enc.secret.june " -k $PASS 2>/dev/null
openssl enc -aes-256-cbc -salt -in " $HOME /.zen/game/players/ $PLAYER /secret.dunikey " -out " $HOME /.zen/game/players/ $PLAYER /enc.secret.dunikey " -k $PASS 2>/dev/null
openssl enc -aes-256-cbc -salt -in " $HOME /.zen/game/players/ $PLAYER / $KEYFILE -out " " $HOME /.zen/game/players/ $PLAYER /enc. $KEYFILE " -k $PASS 2>/dev/null
2022-03-05 02:16:41 +01:00
## TODO MORE SECURE ?! USE opengpg, natools, etc ...
2022-04-26 14:16:57 +02:00
# ${MY_PATH}/natools.py encrypt -p $G1PUB -i ~/.zen/game/players/$PLAYER/secret.dunikey -o "$HOME/.zen/game/players/$PLAYER/secret.dunikey.oasis"
2022-03-02 18:37:42 +01:00
#################################################
2022-05-07 18:53:11 +02:00
# !! TODO !! # DEMO MODE. REMOVE FOR PRODUCTION
2022-04-26 14:16:57 +02:00
echo " $PASS " > ~/.zen/game/players/$PLAYER /.pass
2022-05-07 18:53:11 +02:00
# ~/.zen/game/players/$PLAYER/secret.june SECURITY TODO
# Astronaut QRCode + PASS = LOGIN (=> DECRYPTING CRYPTO IPFS INDEX)
2022-08-15 19:07:39 +02:00
# TODO : Allow Astronaut PASS change ;)
2022-05-07 18:53:11 +02:00
#####################################################
2022-03-02 18:37:42 +01:00
2022-05-07 18:53:11 +02:00
## DISCONNECT AND CONNECT CURRENT PLAYER
2022-03-02 18:37:42 +01:00
rm -f ~/.zen/game/players/.current
2022-04-26 14:16:57 +02:00
ln -s ~/.zen/game/players/$PLAYER ~/.zen/game/players/.current
2022-03-02 18:37:42 +01:00
2022-08-18 03:47:49 +02:00
## CREATE GCHANGE+ PROFILE
${ MY_PATH } /Connect_PLAYER_To_Gchange.sh
2022-08-15 19:07:39 +02:00
## INIT FRIENDSHIP CAPTAIN/ASTRONAUTS (LATER THROUGH GCHANGE)
2022-06-23 16:30:56 +02:00
## ${MY_PATH}/FRIENDS.init.sh
## NO. GCHANGE+ IS THE MAIN INTERFACE, astrXbian manage
2022-08-20 17:12:15 +02:00
echo " Bienvenue 'Astronaute' $PSEUDO ( $PLAYER ) "
echo " Retenez votre PASS : $PASS " ; sleep 2
2022-04-23 18:33:23 +02:00
2022-05-02 23:10:48 +02:00
echo $PSEUDO > ~/.zen/tmp/PSEUDO ## Return data to start.sh
echo " cool $( ${ MY_PATH } /face.sh cool) "
2022-08-18 03:47:49 +02:00
echo "Relancez start."
2022-03-02 18:37:42 +01:00
exit 0