ssb-g1-tip/install.sh

253 lines
7.5 KiB
Bash
Executable File

#!/bin/bash
########################################################################
# Authors:
# [@cel](@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519)
# [@Fred](@9BbJwPDjcyIqrOUPNn0nJZBduWdIrpMk3Cjz5MP361s=.ed25519)
# [@Boris](@l5nYExWYIgDLV6BYHOJPoI97jIUyTdSm8CTLpQ0XeOg=.ed25519)
# [@poka]()
# Version: 1.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##*/}"
echo '
########################################################################
# \\///
# qo-op
############# '$MY_PATH/$ME'
########################################################################
# SSB-G1-TX :: INSTALL G1 + SSB for sending G1 Tip on SSB likes
########################################################################
'
# INSTALL Silkaj, CLI for Duniter
if [[ ! $(which silkaj) ]]; then
echo '**************************************************************
__ ___
(_ | | |/ /\ |
__) _|_ |_ |\ /--\ \_|
#Libre Money Layer
'
mkdir -p ~/.zen
sudo apt update || true
sudo apt install build-essential -y
sudo pip3 install base58
sudo apt install python3-pip python3-setuptools python3-wheel -y
pip3 install silkaj --user
echo 'PATH=$PATH:.local/bin' >> ~/.bashrc && source ~/.bashrc
fi
# Install ScuttleButt
echo '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
__ _ ___ ___ _ _ ___ ___
(_ / | | | | | |_ |_) | | | |
__) \_ |_| | | |_ |_ |_) |_| | |
#Libre Social Layer
Is it a 24/24 Pub?
Yes/No: y? (Default No)'
read ssb_yes
nodename=$(cat /etc/hostname)
extension=$(echo $nodename | cut -d '.' -f 2)
[[ $extension == $nodename ]] && nodename=$nodename.local
if [[ ! $(which sbot) && "$ssb_yes" == "y" ]]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
source ~/.bashrc
nvm install --lts
sudo apt install libtool autoconf -y
npm install sodium-native ssb-backlinks ssb-ws ssb-links ssb-query ssb-secret-blob ssb-private
npm install -g ssb-server
# LOCAL
####### BACKUP .ssb to ~/.ssb_$USER && CREATE ~/.ssb_astroport
# If exists backup ~/.ssb to ~/.ssb_$USER SSB (one time only !)
[[ -d ~/.ssb_$USER ]] && echo "BACKUP already existing... ~/.ssb_$USER !!! Manual check please..." && exit 1
[[ -d ~/.ssb ]] && [[ ! -d ~/.ssb_$USER ]] && mv ~/.ssb ~/.ssb_$USER
# CREATE ~/.ssb_astroport
[[ ! -d ~/.ssb_astroport ]] && mkdir -p ~/.ssb_astroport
# if exists, keep ~/.ssb_$USER/secret*
[[ ! -f ~/.ssb_astroport/secret ]] && [[ -f ~/.ssb_$USER/secret ]] && cp -f ~/.ssb_$USER/secret* ~/.ssb_astroport/
# Symlink ~/.ssb -> ~/.ssb_astroport
[[ -L ~/.ssb ]] && rm ~/.ssb
[[ -d ~/.ssb_astroport ]] && ln -s ~/.ssb_astroport ~/.ssb
cat > ~/.ssb/config <<EOF
{
"connections": {
"incoming": {
"net": [
{ "scope": "public", "host": "0.0.0.0", "external": ["$nodename"], "transform": "shs", "port": 8008 }
],
"ws": [
{ "scope": ["public", "local", "device"], "host": "0.0.0.0", "port": 8989, "transform": "shs", "http": true }
]
},
"outgoing": {
"net": [{ "transform": "shs" }]
}
}
}
EOF
cat > ~/.zen/run-ssb_server.sh <<EOF
#!/bin/bash
echo _$ > ~/.zen/ssb.pid.bash
while true; do
ssb-server start
echo _! > ~/.zen/ssb.pid
done
EOF
# REPLACE _ with $
sed -i s/_/\$/g ~/.zen/run-ssb_server.sh
chmod 755 ~/.zen/run-ssb_server.sh
# INSTALL sbotc for CLI API
if [[ ! $(which sbotc) ]]; then
sudo apt install libsodium-dev jq -y
git clone https://git.scuttlebot.io/%25133ulDgs%2FoC1DXjoK04vDFy6DgVBB%2FZok15YJmuhD5Q%3D.sha256 sbotc
cd sbotc
make
sudo make install
fi
fi
# LOCAL NODE
if [[ $extension == $nodename ]] ; then
echo '
_ ___ _ _ _
|_) /\ | / |_| \ / / \ |_) |/
| /--\ | \_ | | \/\/ \_/ | \ |\
Install Patchwork...
'
wget -s https://github.com/ssbc/patchwork/releases/download/v3.17.6/ssb-patchwork_3.17.6_amd64.deb > /tmp/
sudo dpkg -i /tmp/ssb-patchwork_3.17.6_amd64.deb
fi
###########################################################################################
####################### G1 SSB ACCOUNT MANAGER ############################################
###########################################################################################
# If user already has an SSB account, we generate Duniter secret key from SSB secret key
if [[ -f ~/.ssb/secret ]]; then
ssbpub=$(cat ~/.ssb/secret | grep public\" | cut -d ' ' -f 4 | cut -d '.' -f 1 | sed s/\"//g)
ssbpriv=$(cat ~/.ssb/secret | grep private\" | cut -d ' ' -f 4 | cut -d '.' -f 1 | sed s/\"//g)
g1pub=$(echo $ssbpub | base64 -d | base58)
g1priv=$(echo $ssbpriv | base64 -d | base58)
cat > ~/.ssb/secret.dunikey <<EOF
Type: PubSec
Version: 1
pub: $g1pub
sec: $g1priv
EOF
# If user doesn't have an SSB account, we create one
else
mkdir -p ~/.ssb
echo "WELCOME CREATING YOUR G1 SSB ACCOUNT !!!"
echo "
__ __ __ _
/__ /| (_ (_ |_)
\_| | __) __) |_)
CHOOSE YOU LOGIN or LEAVE BLANK & HIT ENTER FOR AUTO GENERATION"
read salt
[[ $salt != "" ]] && echo "PASSWORD?" && read pepper && [[ $pepper == "" ]] && exit 1
if [[ "$salt" == "" && "$pepper" == "" ]]; then
echo '
._ _ ._ _ ._ _ _ ._ o _
| | | | | (/_ | | | (_) | | | (_
passphrase generator...'
# INSTALL Cargo
if [[ ! $(which cargo) ]]; then
curl https://sh.rustup.rs -sSf | sh
PATH=$PATH:~/.cargo/env
source $HOME/.cargo/env
fi
# Install DUP-Mnemonic
if [[ ! $(which dup-mnemonic) ]]; then
cd /tmp
git clone https://git.duniter.org/tools/dup-mnemonic-rs
cd dup-mnemonic-rs
cargo build --release
sudo cp target/release/dup-mnemonic /usr/local/bin
fi
# GENERATE MNEMONIC KEY: 9 MOTS
if [[ $salt == "" ]]; then
declare -a makeyarray
makeyarray=($(dup-mnemonic -l $lang))
# LOGIN (=SALT) 6 WORDS
salt="${makeyarray[0]} ${makeyarray[1]} ${makeyarray[2]} ${makeyarray[3]} ${makeyarray[4]} ${makeyarray[5]}"
# PASS (=PEPPER) 3 WORDS
pepper="${makeyarray[6]} ${makeyarray[7]} ${makeyarray[8]}"
fi
echo "........."
echo "REMEMBER YOUR CREDENTIALS: $salt / $pepper"
fi
# CREATE ~/.ssb/secret.dunikey
python3 $MY_PATH/key_create_dunikey.py "$salt" "$pepper"
mv $MY_PATH/.secret.dunikey ~/.ssb/secret.dunikey
# CREATE SSB secret
pub=$(cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2)
priv=$(cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2)
ssbpub=$(echo $pub | base58 -d | base64)
ssbpriv=$(echo $priv | base58 -d | base64)
cat > ~/.ssb/secret <<EOF
# This secret is related to your G1Wallet - https://cesium.app
# silkaj balance $pub
# ID (salt): $salt / Pass: $pepper
# THIS KEY IS YOURS! REMIND IT AND KEEP IT SAFE AS A REAL WALLET
# chmod 400 ~/.zen/secret
{
"curve": "ed25519",
"public": "$ssbpub.ed25519",
"private": "$ssbpriv.ed25519",
"id": "@$ssbpub.ed25519"
}
# WARNING! It's vital that you DO NOT edit OR share your secret name
# instead, share your public name
# your SSB public name: @$ssbpub.ed25519
EOF
fi
echo -e "Installation complete"
exit 0