backup .ssb

This commit is contained in:
qo-op 2020-03-30 03:33:30 +02:00
parent fb3d19fb8d
commit 0e76a649bc
1 changed files with 154 additions and 95 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
################################################################################ ########################################################################
# Authors: # Authors:
# [@cel](@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519) # [@cel](@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519)
# [@Fred](@9BbJwPDjcyIqrOUPNn0nJZBduWdIrpMk3Cjz5MP361s=.ed25519) # [@Fred](@9BbJwPDjcyIqrOUPNn0nJZBduWdIrpMk3Cjz5MP361s=.ed25519)
@ -7,92 +7,142 @@
# [@poka]() # [@poka]()
# Version: 1.0.1 # Version: 1.0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) # License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################################### ########################################################################
# ADD G1 Layer 10 LOVE to message writer you like ! ########################################################################
# INSTALL silkaj sbotc MY_PATH="`dirname \"$0\"`" # relative
# PREVENT DOUBLE PAYEMENT MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
############################################################################################ ME="${0##*/}"
echo '
# INSTALL requirements ########################################################################
[[ ! $(which base58) ]] && sudo apt install build-essential base58 -y # \\///
# qo-op
############# '$MY_PATH/$ME'
########################################################################
# SSB-G1-TX :: INSTALL G1 + SSB for sending G1 Tip on SSB likes
########################################################################
'
# INSTALL Silkaj, CLI for Duniter # INSTALL Silkaj, CLI for Duniter
if [[ ! $(which silkaj) ]]; then if [[ ! $(which silkaj) ]]; then
echo "INSTALL silkaj" echo '**************************************************************
__ ___
(_ | | |/ /\ |
__) _|_ |_ |\ /--\ \_|
#Libre Money Layer
'
mkdir -p ~/.zen
sudo apt update || true sudo apt update || true
sudo apt install python3-pip python3-setuptools python3-wheel -y && pip3 install silkaj --user 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 echo 'PATH=$PATH:.local/bin' >> ~/.bashrc && source ~/.bashrc
fi fi
# Install ScuttleButt
if [[ ! $(which sbot) ]]; then # 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 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
source ~/.bashrc source ~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install --lts nvm install --lts
sudo apt install libtool autoconf -y sudo apt install libtool autoconf -y
npm install sodium-native ssb-backlinks npm install sodium-native ssb-backlinks ssb-ws ssb-links ssb-query ssb-secret-blob ssb-private
npm install -g ssb-server npm install -g ssb-server
nodename=$(cat /etc/hostname).local # LOCAL
echo "SSB Node Hostname (default $nodename)?" ####### BACKUP .ssb to ~/.ssb_$USER && CREATE ~/.ssb_astroport
read EXTERNAL # If exists backup ~/.ssb to ~/.ssb_$USER SSB (one time only !)
[[ $EXTERNAL == "" ]] && EXTERNAL=$nodename [[ -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
mkdir -p ~/.ssb
cat > ~/.ssb/config <<EOF cat > ~/.ssb/config <<EOF
{ {
"connections": { "connections": {
"incoming": { "incoming": {
"net": [ "net": [
{ { "scope": "public", "host": "0.0.0.0", "external": ["$nodename"], "transform": "shs", "port": 8008 }
"scope": "public", "external": ["$EXTERNAL"], "transform": "shs", "port": 8008 ],
}, "ws": [
{ "scope": "private", "transform": "shs", "port": 8008, "host": "127.0.0.1" } { "scope": ["public", "local", "device"], "host": "0.0.0.0", "port": 8989, "transform": "shs", "http": true }
] ]
}, },
"outgoing": { "outgoing": {
"net": [ "net": [{ "transform": "shs" }]
{
"transform": "shs"
}
]
} }
} }
} }
EOF EOF
cat > ~/.zen/run-ssb_server.sh <<EOF
cat > ~/run-ssb-PUB_$EXTERNAL.sh <<EOF
#!/bin/bash #!/bin/bash
echo _$ > ~/.zen/ssb.pid.bash
while true; do while true; do
ssb-server start --host $EXTERNAL ssb-server start
echo _! > ~/.zen/ssb.pid
done done
EOF EOF
chmod 755 ~/run-ssb-PUB_$EXTERNAL.sh # REPLACE _ with $
~/run-ssb-PUB_$EXTERNAL.sh & 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 fi
# INSTALL sbotc # LOCAL NODE
if [[ ! $(which sbotc) ]]; then if [[ $extension == $nodename ]] ; 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
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 ############################################ ####################### G1 SSB ACCOUNT MANAGER ############################################
########################################################################################### ###########################################################################################
# If user already has an SSB account, we generate Duniter secret key from SSB secret key # If user already has an SSB account, we generate Duniter secret key from SSB secret key
if [[ -f ~/.ssb/secret ]]; then if [[ -f ~/.ssb/secret ]]; then
@ -115,54 +165,68 @@ else
mkdir -p ~/.ssb mkdir -p ~/.ssb
echo "WELCOME CREATING YOUR G1 SSB ACCOUNT !!!" echo "WELCOME CREATING YOUR G1 SSB ACCOUNT !!!"
echo "CHOOSE YOU LOGIN or LEAVE BLANK & HIT ENTER FOR AUTO GENERATION" echo "
read salt __ __ __ _
[[ $salt != "" ]] && echo "PASSWORD?" && read pepper && [[ $pepper == "" ]] && exit /__ /| (_ (_ |_)
\_| | __) __) |_)
# INSTALL Cargo CHOOSE YOU LOGIN or LEAVE BLANK & HIT ENTER FOR AUTO GENERATION"
if [[ ! $(which cargo) ]]; then 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 curl https://sh.rustup.rs -sSf | sh
PATH=$PATH:~/.cargo/env PATH=$PATH:~/.cargo/env
source $HOME/.cargo/env source $HOME/.cargo/env
fi fi
# Install DUP-Mnemonic # Install DUP-Mnemonic
if [[ ! $(which dup-mnemonic) ]]; then if [[ ! $(which dup-mnemonic) ]]; then
cd /tmp cd /tmp
git clone https://git.duniter.org/tools/dup-mnemonic-rs git clone https://git.duniter.org/tools/dup-mnemonic-rs
cd dup-mnemonic-rs cd dup-mnemonic-rs
cargo build --release cargo build --release
sudo cp target/release/dup-mnemonic /usr/local/bin sudo cp target/release/dup-mnemonic /usr/local/bin
fi fi
# GENERATE MNEMONIC KEY: 9 MOTS # GENERATE MNEMONIC KEY: 9 MOTS
if [[ $salt == "" ]]; then if [[ $salt == "" ]]; then
declare -a makeyarray declare -a makeyarray
makeyarray=($(dup-mnemonic -l $lang)) makeyarray=($(dup-mnemonic -l $lang))
# LOGIN (=SALT) 6 MOTS # LOGIN (=SALT) 6 WORDS
salt="${makeyarray[0]} ${makeyarray[1]} ${makeyarray[2]} ${makeyarray[3]} ${makeyarray[4]} ${makeyarray[5]}" salt="${makeyarray[0]} ${makeyarray[1]} ${makeyarray[2]} ${makeyarray[3]} ${makeyarray[4]} ${makeyarray[5]}"
# PASS (=PEPPER) 3 MOTS # PASS (=PEPPER) 3 WORDS
pepper="${makeyarray[6]} ${makeyarray[7]} ${makeyarray[8]}" pepper="${makeyarray[6]} ${makeyarray[7]} ${makeyarray[8]}"
fi
echo "........."
echo "REMEMBER YOUR CREDENTIALS: $salt / $pepper"
fi fi
echo "........."
echo "REMEMBER YOUR CREDENTIALS: $salt / $pepper"
# CREATE ~/.ssb/secret.dunikey # CREATE ~/.ssb/secret.dunikey
python3 ./key_create_dunikey.py "$salt" "$pepper" python3 $MY_PATH/key_create_dunikey.py "$salt" "$pepper"
mv ./.secret.dunikey ~/.ssb/secret.dunikey mv $MY_PATH/.secret.dunikey ~/.ssb/secret.dunikey
# CREATE SSB secret # CREATE SSB secret
g1pub=$(cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2) pub=$(cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2)
g1priv=$(cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2) priv=$(cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2)
ssbpub=$(echo $g1pub | base58 -d | base64) ssbpub=$(echo $pub | base58 -d | base64)
ssbpriv=$(echo $g1priv | base58 -d | base64) ssbpriv=$(echo $priv | base58 -d | base64)
cat > ~/.ssb/secret <<EOF cat > ~/.ssb/secret <<EOF
# This secret was generated from ~/.ssb/secret.dunikey # This secret is related to your G1Wallet - https://cesium.app
# G1 Wallet https://cesium.app with Mnemonic Credentials # silkaj balance $pub
# user: $salt # ID (salt): $salt / Pass: $pepper
# password: $pepper # THIS KEY IS YOURS! REMIND IT AND KEEP IT SAFE AS A REAL WALLET
# THIS KEY IS YOURS! KEEP IT SAFE AS A REAL WALLET # chmod 400 ~/.zen/secret
{ {
"curve": "ed25519", "curve": "ed25519",
@ -174,16 +238,11 @@ cat > ~/.ssb/secret <<EOF
# WARNING! It's vital that you DO NOT edit OR share your secret name # WARNING! It's vital that you DO NOT edit OR share your secret name
# instead, share your public name # instead, share your public name
# your SSB public name: @$ssbpub.ed25519 # your SSB public name: @$ssbpub.ed25519
# your G1 wallet public key: $g1pub
EOF EOF
fi fi
# TODO: Create RAM disk
# mkdir -p ~/.ssb/zen/tmp && sudo mount -t tmpfs -osize=64m tmpfs ~/.ssb/zen/tmp
# Add it to /etc/fstab
echo -e "Installation complete" echo -e "Installation complete"