165 lines
5.1 KiB
Bash
Executable File
165 lines
5.1 KiB
Bash
Executable File
#!/bin/bash
|
|
########################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# Version: 2020.03.21
|
|
# 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##*/}"
|
|
echo '
|
|
########################################################################
|
|
# \\///
|
|
# qo-op
|
|
############# '$MY_PATH/$ME'
|
|
########################################################################
|
|
# ex: ./'$ME'
|
|
# Initialize G1SSB account + IPFS Publish
|
|
########################################################################
|
|
o__ __o __o o__ __o o__ __o o__ __o
|
|
/v v\ __|> /v v\ /v v\ <| v\
|
|
/> <\ | /> <\ /> <\ / \ <\
|
|
o/ <o> _\o____ _\o____ \o/ o/
|
|
<| _\__o__ | \_\__o__ \_\__o__ |__ _<|
|
|
\\ | < > \ \ | \
|
|
\ / | \ / \ / <o> /
|
|
o o o o o o o | o
|
|
<\__ __/> __|>_ <\__ __/> <\__ __/> / \ __/>
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
# [ASTROPORT](https://astroport.com)
|
|
########################################################################
|
|
'
|
|
##############################################
|
|
# NODE ENVIRONEMENT DETECTION
|
|
##############################################
|
|
IPFSNODEID=$(ipfs id -f='<id>\n')
|
|
# CREATE ~/.zen/ipfs/.$IPFSNODEID/G1SSB
|
|
##############################################
|
|
[[ $IPFSNODEID == "" ]] && echo "ERROR missing IPFSNODEID" && exit 1
|
|
mkdir -p ~/.zen/ipfs/.$IPFSNODEID/G1SSB
|
|
|
|
EXTERNAL=$(cat /etc/hostname).local
|
|
|
|
[[ "$1" == "KILL" ]] && kill -9 $(cat ~/.zen/ssb.pid.bash) && killall node && echo "
|
|
_ _ _ _
|
|
| | (_) | |
|
|
| | ___| | |
|
|
| |/ / | | |
|
|
| <| | | |
|
|
|_|\_\_|_|_|
|
|
"
|
|
ssbpub=$(sbotc whoami 2>/dev/null | jq -r .id)
|
|
|
|
if [[ $ssbpub == "" ]]; then
|
|
|
|
[[ "$1" == "RESET" ]] && rm -Rf ~/.ssb.$USER
|
|
[[ -d ~/.ssb.$USER ]] && echo "Backup already exists $USER. $MY_PATH/$ME RESET to remove..." && exit 1
|
|
[[ -d ~/.ssb ]] && mv ~/.ssb ~/.ssb.$USER && rm -Rf ~/.ssb # BACKUP ~/.ssb
|
|
mkdir -p ~/.ssb
|
|
echo "
|
|
_ __ __ _
|
|
_ _ .__|_o _ (_ (_ |_)
|
|
(_(_)| || |(_| __)__)|_)
|
|
_|
|
|
$EXTERNAL
|
|
"
|
|
|
|
[[ -f ~/.ssb/config ]] && cp -f ~/.ssb/config ~/.ssb/config.bkp
|
|
cat > ~/.ssb/config <<EOF
|
|
{
|
|
"connections": {
|
|
"incoming": {
|
|
"net": [
|
|
{
|
|
"scope": "public", "external": ["$EXTERNAL"], "transform": "shs", "port": 8008
|
|
},
|
|
{ "scope": "private", "transform": "shs", "port": 8008, "host": "127.0.0.1" }
|
|
]
|
|
},
|
|
"outgoing": {
|
|
"net": [
|
|
{
|
|
"transform": "shs"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
echo '
|
|
__ _ _ _ _
|
|
(_ |_|_)\ /|_|_) o._ o_|_
|
|
__)|_| \ \/ |_| \ || || |_
|
|
|
|
'
|
|
cat > ~/.zen/run-ssb-PUB_$EXTERNAL.sh <<EOF
|
|
#!/bin/bash
|
|
echo _$ > ~/.zen/ssb.pid.bash
|
|
while true; do
|
|
ssb-server start --host $EXTERNAL 2>/dev/null
|
|
echo _! > ~/.zen/ssb.pid
|
|
done
|
|
EOF
|
|
|
|
sed -i s/_/\$/g ~/.zen/run-ssb-PUB_$EXTERNAL.sh
|
|
chmod 755 ~/.zen/run-ssb-PUB_$EXTERNAL.sh
|
|
|
|
~/.zen/run-ssb-PUB_$EXTERNAL.sh &
|
|
sleep 5
|
|
|
|
ssbpub=$(sbotc whoami 2>/dev/null | jq -r .id)
|
|
|
|
fi
|
|
|
|
# secret.dunikey ? NODE_G1PUBKEY
|
|
[[ ! -f ~/.ssb/secret.dunikey ]] && $MY_PATH/tools/secret2dunikey.sh
|
|
NODE_G1PUBKEY=$(cat ~/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
|
|
|
|
echo "
|
|
$ssbpub
|
|
_____ _____ _
|
|
(_ | /\ |_)||_| \
|
|
oooooooo__) |/--\| \||_|_/ !!!!!!!!!!!!!!
|
|
|
|
"
|
|
|
|
## PUBLISH ABOUT MESSAGE
|
|
##############################################
|
|
# CREATE G1 wallet QRCode
|
|
qrcodefile=~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.qrcode.png
|
|
qrencode -s 5 -o $qrcodefile "$NODE_G1PUBKEY"
|
|
|
|
# Publish G1 Wallet PUBKEY QRCode to SSB
|
|
name=${qrcodefile##*/}
|
|
id="$(sbotc blobs.add < $qrcodefile)"
|
|
type="$(file -b --mime-type $qrcodefile)"
|
|
size="$(wc -c < $qrcodefile)"
|
|
# Publish ABOUT
|
|
sbot publish --type about --about $ssbpub --description "Welcome to [Astroport](https://astroport.com) G1SSB/IPFS Station [$IPFSNODEID](http://localhost:8080/ipns/$IPFSNODEID)" --name "$USER@$(cat /etc/hostname)" --image "$id"
|
|
# Publish QRCode FILE post
|
|
sbotc publish '{"type":"post","text":"[G1SSB_Wallet.png]('"$id"')\nUse https://cesium.app to send payment.\nComment your transaction with '"'Zen'"' to order ZenTag...","mentions":[{"link":"'"$id"'","name":"'"$name"'","size":'"$size"',"type":"'"$type"'"}]}'
|
|
|
|
# COPY NODE G1SSB ID to IPFS
|
|
echo "$ssbpub" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_ssb.whoami
|
|
echo "$NODE_G1PUBKEY" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.pubkey
|
|
|
|
IWALLETS=$(ipfs add -rHq ~/.zen/ipfs | tail -n 1)
|
|
NODEIPNS=$(ipfs name publish --quieter /ipfs/$IWALLETS)
|
|
|
|
|
|
|
|
echo "
|
|
|
|
|
|
/\ |_ _ _|_
|
|
/--\|_)(_)|_||_ message published
|
|
|
|
$ssbpub
|
|
|
|
http://localhost:8080/ipns/$IPFSNODEID/.$IPFSNODEID/G1SSB/
|
|
|
|
INVITATION : $(sbotc invite.create 1)
|
|
|
|
"
|