Astroport.ONE/ASTROBOT/G1Voeu.sh

261 lines
14 KiB
Bash
Raw Normal View History

2022-08-18 18:32:01 +02:00
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
################################################################################
# Create G1VOEU TW for PLAYER
# Mon Titre => G1MonTitre => PEPPER
## PARAM : "TITRE DU VOEU" "PLAYER" "INDEX"
2022-08-18 18:32:01 +02:00
################################################################################
TITRE="$1"
2022-08-18 18:32:01 +02:00
PLAYER="$2"
INDEX="$3"
2022-08-18 18:32:01 +02:00
[[ $PLAYER == "" ]] && PLAYER=$(cat ~/.zen/game/players/.current/.player 2>/dev/null)
[[ $PLAYER == "" ]] && echo "Second paramètre PLAYER manquant" && exit 1
2022-08-22 17:38:25 +02:00
PSEUDO=$(cat ~/.zen/game/players/$PLAYER/.pseudo 2>/dev/null)
[[ $G1PUB == "" ]] && G1PUB=$(cat ~/.zen/game/players/$PLAYER/.g1pub 2>/dev/null)
2022-08-18 18:32:01 +02:00
[[ $G1PUB == "" ]] && echo "Troisième paramètre G1PUB manquant" && exit 1
2022-10-24 14:12:34 +02:00
[[ ! $INDEX ]] && echo "MISSING ASTRONAUTE TW index.html - EXIT -" && exit 1
echo "Working on $INDEX"
2022-08-18 18:32:01 +02:00
ASTRONAUTENS=$(ipfs key list -l | grep -w "${PLAYER}" | cut -d ' ' -f 1)
2022-10-24 14:12:34 +02:00
[[ $ASTRONAUTENS == "" ]] && echo "CLEF IPNS ASTRONAUTE MANQUANTE - EXIT -" && exit 1
2022-08-18 18:32:01 +02:00
echo "Bienvenue $PSEUDO ($PLAYER) : $G1PUB"
echo
######################################################################
#####################################################
# CREATION DU TW G1VOEU
#####################################################
2022-10-11 13:51:46 +02:00
SALT=$(${MY_PATH}/../tools/diceware.sh 3 | xargs)
echo "$SALT"
2022-08-18 18:32:01 +02:00
echo "## TITRE POUR CE VOEU ? "
[[ ! $TITRE ]] && read TITRE
2022-08-22 17:38:25 +02:00
PEPPER=$(echo "$TITRE" | sed -r 's/\<./\U&/g' | sed 's/ //g') # CapitalGluedWords
2022-10-16 02:57:29 +02:00
echo "$PEPPER" && [[ ! $PEPPER ]] && echo "EMPTY PEPPER - ERROR" && exit 1
2022-08-18 18:32:01 +02:00
echo "## keygen CLEF DE VOEUX"
2022-10-11 13:51:46 +02:00
${MY_PATH}/../tools/keygen -t duniter -o ~/.zen/tmp/qrtw.dunikey "$SALT" "$PEPPER"
2022-08-18 18:32:01 +02:00
WISHKEY=$(cat ~/.zen/tmp/qrtw.dunikey | grep "pub:" | cut -d ' ' -f 2)
echo "WISHKEY (G1PUB) = $WISHKEY"
2022-08-18 18:32:01 +02:00
echo "# NOUVEAU VOEU"
2022-08-18 18:32:01 +02:00
mkdir -p ~/.zen/game/players/$PLAYER/voeux/$WISHKEY/
2022-10-12 00:50:32 +02:00
${MY_PATH}/../tools/keygen -t ipfs -o ~/.zen/game/players/$PLAYER/voeux/$WISHKEY/qrtw.ipfskey "$SALT" "$PEPPER"
2022-10-10 18:06:37 +02:00
ipfs key import $WISHKEY -f pem-pkcs8-cleartext ~/.zen/game/players/$PLAYER/voeux/$WISHKEY/qrtw.ipfskey
2022-10-12 01:05:12 +02:00
VOEUNS=$(ipfs key list -l | grep -w "$WISHKEY" | cut -d ' ' -f 1 )
echo "/ipns/$VOEUNS"
2022-10-10 18:18:57 +02:00
## TEST IPFS
ipfs --timeout=6s cat /ipns/$VOEUNS > ~/.zen/tmp/$VOEUNS.html
2022-10-24 14:12:34 +02:00
[[ -s ~/.zen/tmp/$VOEUNS.html ]] && echo "HEY !!! UN TW EXISTE POUR CE VOEU ! ~/.zen/tmp/$VOEUNS.html - EXIT -" && exit 1
2022-10-10 18:18:57 +02:00
2022-08-18 18:32:01 +02:00
# CRYPTO BUG. TODO use natools to protect and share key with Ŋ1 only ;)
myIP=$(hostname -I | awk '{print $1}' | head -n 1)
2022-12-18 20:45:43 +01:00
isLAN=$(route -n |awk '$1 == "0.0.0.0" {print $2}' | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
[[ ! $myIP || $isLAN ]] && myIP="ipfs.localhost"
echo " Passerelle : $myIP"
2022-08-18 18:32:01 +02:00
2022-08-23 13:38:37 +02:00
echo "# UPGRADING WORLD WHISHKEY DATABASE"
2022-08-18 18:32:01 +02:00
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
mkdir -p ~/.zen/game/world/$WISHKEY/
## A la fois Titre du tag et Pepper construction de clef
2022-08-18 18:32:01 +02:00
echo $PEPPER > ~/.zen/game/world/$WISHKEY/.pepper
2022-12-08 21:08:57 +01:00
echo "# INIT WISH TW"
2022-08-23 13:38:37 +02:00
##########################################################################################
##########################################################################################
2022-08-18 18:32:01 +02:00
cp ~/.zen/Astroport.ONE/templates/twdefault.html ~/.zen/game/world/$WISHKEY/index.html
# TODO : CREATE ONE TEMPLATE / REMOVE USELESS TID
2022-08-18 18:32:01 +02:00
# PERSONNALISATION "MadeInZion"
2022-08-18 18:32:01 +02:00
sed -i "s~_BIRTHDATE_~${MOATS}~g" ~/.zen/game/world/$WISHKEY/index.html
sed -i "s~_PSEUDO_~${PSEUDO}~g" ~/.zen/game/world/$WISHKEY/index.html
sed -i "s~_PLAYER_~${PLAYER}~g" ~/.zen/game/world/$WISHKEY/index.html
sed -i "s~_G1PUB_~${G1PUB}~g" ~/.zen/game/world/$WISHKEY/index.html
sed -i "s~_WISHKEY_~${WISHKEY}~g" ~/.zen/game/world/$WISHKEY/index.html
sed -i "s~_NUMBER_~${SALT}~g" ~/.zen/game/world/$WISHKEY/index.html
sed -i "s~_SECRET_~${PEPPER}~g" ~/.zen/game/world/$WISHKEY/index.html
2022-12-08 21:08:57 +01:00
sed -i "s~_ASTROPORT_~/ipns/${ASTRONAUTENS}~g" ~/.zen/game/world/$WISHKEY/index.html
2022-09-06 17:32:50 +02:00
sed -i "s~_QRSEC_~${myIP}~g" ~/.zen/game/world/$WISHKEY/index.html
2022-10-12 01:05:12 +02:00
# IPNS KEY is WISHKEY / VOEUNS
2022-08-18 18:32:01 +02:00
sed -i "s~_MEDIAKEY_~${WISHKEY}~g" ~/.zen/game/world/$WISHKEY/index.html
2022-10-12 01:05:12 +02:00
sed -i "s~k2k4r8kxfnknsdf7tpyc46ks2jb3s9uvd3lqtcv9xlq9rsoem7jajd75~${VOEUNS}~g" ~/.zen/game/world/$WISHKEY/index.html
2022-08-22 17:38:25 +02:00
# ASTROPORT LOCAL IP RELAY == Smartphone doesn't resolve LAN DNS. So using Astroport Station IP
2022-08-18 18:32:01 +02:00
sed -i "s~ipfs.infura.io~tube.copylaradio.com~g" ~/.zen/game/world/$WISHKEY/index.html
2022-08-20 17:12:15 +02:00
sed -i "s~127.0.0.1~$myIP~g" ~/.zen/game/world/$WISHKEY/index.html
2022-08-23 13:38:37 +02:00
# ADD API GW TIDDLERS for IPFS SAVE
##########################################################################################
# [{"title":"$:/ipfs/saver/api/http/local/5001","tags":"$:/ipfs/core $:/ipfs/saver/api","text":"http://127.0.0.1:5001"}]
# [{"title":"$:/ipfs/saver/gateway/local/myip","tags":"$:/ipfs/core $:/ipfs/saver/gateway","text":"http://127.0.0.1:8080"}]
##########################################################################################
tiddlywiki --load ~/.zen/game/world/$WISHKEY/index.html \
2022-08-23 13:38:37 +02:00
--import ~/.zen/Astroport.ONE/templates/data/local.api.json "application/json" \
--import ~/.zen/Astroport.ONE/templates/data/local.gw.json "application/json" \
2022-11-17 15:53:40 +01:00
--deletetiddlers '"Dessin de _PLAYER_"' \
2022-12-08 21:08:57 +01:00
--deletetiddlers '"BunkerBOX"' \
--deletetiddlers '"CopierYoutube"' \
--deletetiddlers '"Bienvenue"' \
2022-08-23 13:38:37 +02:00
--output ~/.zen/tmp --render "$:/core/save/all" "newindex.html" "text/plain"
[[ -s ~/.zen/tmp/newindex.html ]] && cp ~/.zen/tmp/newindex.html ~/.zen/game/world/$WISHKEY/index.html
[[ ! -s ~/.zen/tmp/newindex.html ]] && echo "ERROR ~/.zen/tmp/newindex.html MISSING" && exit 1
2022-08-23 13:38:37 +02:00
2022-08-18 18:32:01 +02:00
echo "# CREATION QR CODE"
LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2)
2022-10-12 01:05:12 +02:00
qrencode -s 12 -o "$HOME/.zen/game/world/$WISHKEY/QR.WISHLINK.png" "$LIBRA/ipns/$VOEUNS"
qrencode -s 12 -o "$HOME/.zen/game/world/$WISHKEY/QR.ASTROLINK.png" "$LIBRA/ipns/$ASTRONAUTENS"
2022-08-22 17:38:25 +02:00
qrencode -s 12 -o "$HOME/.zen/game/world/$WISHKEY/QR.G1ASTRO.png" "$G1PUB"
qrencode -s 12 -o "$HOME/.zen/game/world/$WISHKEY/QR.G1WISH.png" "$WISHKEY"
2022-10-12 01:05:12 +02:00
qrencode -s 12 -o "$HOME/.zen/game/world/$WISHKEY/QR.IPNS.png" "/ipns/$VOEUNS"
2022-08-18 18:32:01 +02:00
# Bricolage avec node tiddlywiki (TODO add tiddler with command line)
2022-08-22 17:38:25 +02:00
# A suivre .... https://talk.tiddlywiki.org/t/how-to-add-extract-modify-tiddlers-from-command-line-to-do-ipfs-media-transfer/4345/4
# cd ~/.zen/game/world/$WISHKEY
# tiddlywiki $WISHKEY --load ~/.zen/game/world/$WISHKEY/index.html --savewikifolder ./tw/
# cd -
#################################
# PREMIER TYPE ~/.zen/tmp/player.png
convert $HOME/.zen/game/world/$WISHKEY/QR.WISHLINK.png -resize 300 ~/.zen/tmp/QRWISHLINK.png
2022-10-11 13:51:46 +02:00
convert ${MY_PATH}/../images/logoastro.png -resize 220 ~/.zen/tmp/ASTROLOGO.png
2022-08-18 18:32:01 +02:00
2022-10-11 13:51:46 +02:00
composite -compose Over -gravity NorthWest -geometry +350+10 ~/.zen/tmp/ASTROLOGO.png ${MY_PATH}/../images/Brother_600x400.png ~/.zen/tmp/astroport.png
composite -compose Over -gravity NorthWest -geometry +0+0 ~/.zen/tmp/QRWISHLINK.png ~/.zen/tmp/astroport.png ~/.zen/tmp/one.png
2022-12-08 21:08:57 +01:00
convert -gravity northwest -pointsize 20 -fill black -draw "text 320,250 \"$PLAYER\"" ~/.zen/tmp/one.png ~/.zen/tmp/hop.png
convert -gravity northwest -pointsize 30 -fill black -draw "text 20,320 \"$PEPPER\"" ~/.zen/tmp/hop.png ~/.zen/tmp/pseudo.png
convert -gravity northwest -pointsize 30 -fill black -draw "text 320,300 \"$SALT\"" ~/.zen/tmp/pseudo.png ~/.zen/tmp/salt.png
convert -gravity northwest -pointsize 33 -fill black -draw "text 320,350 \"$PEPPER\"" ~/.zen/tmp/salt.png ~/.zen/tmp/player.png
2022-08-18 18:32:01 +02:00
2022-08-22 17:38:25 +02:00
#################################
# SECOND TYPE ~/.zen/tmp/voeu.png
convert $HOME/.zen/game/world/$WISHKEY/QR.G1WISH.png -resize 300 ~/.zen/tmp/G1WISH.png
2022-10-11 13:51:46 +02:00
convert ${MY_PATH}/../images/logojeu.png -resize 260 ~/.zen/tmp/MIZLOGO.png
2022-08-18 18:32:01 +02:00
2022-10-11 13:51:46 +02:00
composite -compose Over -gravity NorthWest -geometry +0+0 ~/.zen/tmp/G1WISH.png ${MY_PATH}/../images/Brother_600x400.png ~/.zen/tmp/astroport.png
composite -compose Over -gravity NorthWest -geometry +300+0 ~/.zen/tmp/QRWISHLINK.png ~/.zen/tmp/astroport.png ~/.zen/tmp/one.png
composite -compose Over -gravity NorthWest -geometry +320+280 ~/.zen/tmp/MIZLOGO.png ~/.zen/tmp/one.png ~/.zen/tmp/two.png
2022-08-18 18:32:01 +02:00
convert -gravity northwest -pointsize 28 -fill black -draw "text 32,350 \"Ğ1 VOEU\"" ~/.zen/tmp/two.png ~/.zen/tmp/pep.png
convert -gravity northwest -pointsize 50 -fill black -draw "text 30,300 \"$PEPPER\"" ~/.zen/tmp/pep.png ~/.zen/tmp/voeu.png
2022-08-22 17:38:25 +02:00
2022-08-31 18:02:06 +02:00
# IMAGE DANS IPFS
IVOEUPLAY=$(ipfs add -Hq ~/.zen/tmp/player.png | tail -n 1)
2022-08-22 17:38:25 +02:00
IVOEU=$(ipfs add -Hq ~/.zen/tmp/voeu.png | tail -n 1)
2022-08-24 11:40:49 +02:00
## Replace Template G1Voeu image
2022-08-22 17:38:25 +02:00
sed -i "s~bafybeidhghlcx3zdzdah2pzddhoicywmydintj4mosgtygr6f2dlfwmg7a~${IVOEU}~g" ~/.zen/game/world/$WISHKEY/index.html
2022-10-20 18:16:13 +02:00
# TEXT="<a target='_blank' href='"/ipns/${VOEUNS}"'><img src='"/ipfs/${IVOEUPLAY}"'></a><br><br><a target='_blank' href='"/ipns/${VOEUNS}"'>"${PEPPER}"</a>"
2022-10-24 16:56:42 +02:00
#:[tag[G1CopierYoutube]] [tag[pdf]]
2022-10-20 18:16:13 +02:00
# Contains QRCode linked to G1VoeuTW and BUTTON listing G1Voeux
2022-10-24 16:56:42 +02:00
TEXT="<a target='_blank' href='#:[tag[G1"$PEPPER"]]' ><img src='"/ipfs/${IVOEUPLAY}"'></a>
<br><a target='_blank' href='"/ipns/${VOEUNS}"'>TW G1Voeu "$PLAYER"</a><br><br>
2022-10-20 18:16:13 +02:00
<\$button class='tc-tiddlylink'>
2022-10-24 16:56:42 +02:00
<\$list filter='[tag[G1"${PEPPER}"]]'>
2022-10-20 18:16:13 +02:00
<\$action-navigate \$to=<<currentTiddler>> \$scroll=no/>
</\$list>
2022-10-24 16:56:42 +02:00
Afficher tous les G1"${PEPPER}"
2022-10-27 18:01:04 +02:00
</\$button>"
2022-08-25 20:30:02 +02:00
2022-08-22 17:38:25 +02:00
# NEW IVEU TIDDLER
2022-12-10 18:33:41 +01:00
echo "## Creation json tiddler : G1${PEPPER} /ipfs/${IVOEU}"
2022-08-22 17:38:25 +02:00
echo '[
{
2022-11-14 13:54:30 +01:00
"created": "'${MOATS}'",
2022-08-25 21:54:31 +02:00
"title": "'${PEPPER}'",
2022-08-26 14:25:47 +02:00
"type": "'text/vnd.tiddlywiki'",
2022-11-01 10:41:11 +01:00
"astronautens": "'/ipns/$ASTRONAUTENS'",
"wishns": "'/ipns/$VOEUNS'",
"qrcode": "'/ipfs/${IVOEUPLAY}'",
"wish": "'$WISHKEY'",
2022-08-25 20:30:02 +02:00
"text": "'$TEXT'",
2022-10-24 16:56:42 +02:00
"tags": "'G1Voeu G1${PEPPER} ${PLAYER}'"
2022-08-22 17:38:25 +02:00
}
]
2022-08-22 18:02:26 +02:00
' > ~/.zen/game/world/$WISHKEY/${PEPPER}.voeu.json
2022-08-22 17:38:25 +02:00
2022-08-23 13:38:37 +02:00
rm -f ~/.zen/tmp/newindex.html
echo "Nouveau Qr$PEPPER dans MOA $PSEUDO : http://127.0.0.1:8080/ipns/$ASTRONAUTENS"
tiddlywiki --verbose --load $INDEX \
--deletetiddlers '[tag[voeu]]' \
--import ~/.zen/game/world/$WISHKEY/${PEPPER}.voeu.json "application/json" \
--output ~/.zen/tmp --render "$:/core/save/all" "newindex.html" "text/plain"
2022-08-23 13:38:37 +02:00
2022-08-23 19:43:07 +02:00
echo "PLAYER TW Update..."
if [[ -s ~/.zen/tmp/newindex.html ]]; then
echo "$$$ Mise à jour $INDEX"
cp -f ~/.zen/tmp/newindex.html $INDEX
else
echo "ERROR INTO ~/.zen/game/world/$WISHKEY/${PEPPER}.voeu.json"
2022-08-22 17:38:25 +02:00
fi
2022-08-18 18:32:01 +02:00
# PRINTING
LP=$(ls /dev/usb/lp* | head -n1)
if [[ ! $LP ]]; then
echo "NO PRINTER FOUND - Plug a Brother QL700 or Add your printer"
else
echo "IMPRESSION VOEU"
brother_ql_create --model QL-700 --label-size 62 ~/.zen/tmp/player.png > ~/.zen/tmp/toprint.bin 2>/dev/null
sudo brother_ql_print ~/.zen/tmp/toprint.bin $LP
brother_ql_create --model QL-700 --label-size 62 ~/.zen/tmp/voeu.png > ~/.zen/tmp/toprint.bin 2>/dev/null
sudo brother_ql_print ~/.zen/tmp/toprint.bin $LP
fi
2022-08-18 18:32:01 +02:00
# COPY QR CODE TO PLAYER ZONE
cp ~/.zen/tmp/player.png ~/.zen/tmp/voeu.png ~/.zen/game/players/$PLAYER/voeux/$WISHKEY/
2022-08-22 17:38:25 +02:00
echo "$PEPPER" > ~/.zen/game/players/$PLAYER/voeux/$WISHKEY/.title
2022-10-12 01:05:12 +02:00
echo "http://$myIP:8080/ipns/$VOEUNS" > ~/.zen/game/players/$PLAYER/voeux/$WISHKEY/.link
2022-08-22 17:38:25 +02:00
cp ~/.zen/game/world/$WISHKEY/QR.WISHLINK.png ~/.zen/game/players/$PLAYER/voeux/$WISHKEY/
2022-08-18 18:32:01 +02:00
# PUBLISHING
echo "## ${PLAYER} RECORDING YOU WISH INTO IPFS"
2022-08-24 11:40:49 +02:00
echo "ipfs add -Hq ~/.zen/game/world/$WISHKEY/index.html
2022-08-18 18:32:01 +02:00
ipfs name publish --key=${WISHKEY} /ipfs/\$IPUSH"
2022-08-24 11:40:49 +02:00
IPUSH=$(ipfs add -Hq ~/.zen/game/world/$WISHKEY/index.html | tail -n 1)
2022-08-18 18:32:01 +02:00
ipfs name publish --key=${WISHKEY} /ipfs/$IPUSH 2>/dev/null
2022-08-24 11:40:49 +02:00
echo $IPUSH > ~/.zen/game/world/$WISHKEY/.chain
echo $MOATS > ~/.zen/game/world/$WISHKEY/.moats
echo
2022-11-14 13:54:30 +01:00
echo "Astronaute TW : http://$myIP:8080/ipns/$ASTRONAUTENS"
echo "Nouveau G1Voeu : $PEPPER (document de contrôle de copie Ŋ1)"
2022-11-14 13:54:30 +01:00
echo "TW $PEPPER : http://$myIP:8080/ipns/$VOEUNS"
echo "## TO RECEIVE G1RONDS Creating Cesium+ Profil #### timeout long ... patience ...."
2022-10-12 01:05:12 +02:00
$MY_PATH/../tools/jaklis/jaklis.py -k ~/.zen/tmp/qrtw.dunikey -n "https://g1.data.presles.fr" set --name "G1Voeu $PEPPER" --avatar "/home/$USER/.zen/Astroport.ONE/images/logojune.jpg" --site "https://astroport.com/ipns/$VOEUNS" #CESIUM+
2022-08-24 15:10:56 +02:00
[[ ! $? == 0 ]] && echo "CESIUM PROFILE CREATION FAILED !!!!"
2022-09-03 15:41:15 +02:00
echo "************************************************************"
echo "Hop, UNE JUNE pour le Voeu $PEPPER"
2022-10-12 01:05:12 +02:00
echo $MY_PATH/../tools/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey pay -a 1 -p $WISHKEY -c \'"$VOEUNS G1Voeu $PEPPER"\' -m
2022-09-03 15:41:15 +02:00
echo "************************************************************"
2022-08-24 15:10:56 +02:00
2022-10-11 13:51:46 +02:00
$MY_PATH/../tools/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey pay -a 1 -p $WISHKEY -c "$VOEUXNS G1Voeu $PEPPER" -m
2022-09-03 15:41:15 +02:00
echo "************************************************************"
2022-08-23 13:38:37 +02:00
2022-08-18 18:32:01 +02:00
exit 0