astroport/.install/scuttlebutt.sh

150 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
scuttlebutt() {
echo -e "${c_yellow}Onboarding SCUTTLEBUTT...$c_"
where_is_ssb_installed=$(which ssb-server)
mkdir -p ~/.zen
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ ! $where_is_ssb_installed ]]; then
# Install dependencies
sudo apt-get install -y socat python3-dev libtool python3-setuptools autoconf automake
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
source ~/.bashrc
nvm install --lts
# Install ssb-server and config in ~/.ssb_astroport
[[ ! -d ~/.ssb_astroport ]] && mkdir -p ~/.ssb_astroport
cd ~/.ssb_astroport
### Install module in ~/.ssb_astroport/node_modules
npm install sodium-native ssb-backlinks ssb-ws ssb-links ssb-query ssb-secret-blob ssb-private
npm install -g ssb-server
# Move node_modules with ssb-server (why do I have to do that? crazy heavy crappy wonderful node.js )
ssbSERVER=$(which ssb-server)
node_bin_path=$(dirname $ssbSERVER)
node_lib_path=$(dirname $ssbSERVER | sed s/bin/lib/)
mv ~/.ssb_astroport/node_modules/* $node_lib_path/node_modules/
# Create sblob symlink
ln -s $node_lib_path/node_modules/ssb-secret-blob/index.js $node_bin_path/sblob
fi
# TEST ssb-server Install
ssbSERVER=$(which ssb-server)
[[ $ssbSERVER == "" ]] && echo "Check your ssb-server install... Cannot find it !!" && exit 1
# 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 && cd ~/.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
# Create config (TODO: adapt if public Pub or Local Node)
# TODO: Create unique hostname in swarm !! uidna
nodename=$(cat /etc/hostname)
extension=$(echo $nodename | cut -d '.' -f 2)
if [[ $extension == $nodename ]]; then
nodename=$nodename.local
# LOCAL
cat > ~/.ssb/config <<EOF
{
"connections": {
"incoming": {
"net": [
{ "scope": "public", "host": "0.0.0.0", "external": ["$nodename"], "transform": "shs", "port": 8008 }
]
},
"outgoing": {
"net": [{ "transform": "shs" }]
}
}
}
EOF
cat > ~/.zen/run-ssb_$nodename.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_$nodename.sh
chmod 755 ~/.zen/run-ssb_$nodename.sh
ssb-server start &
else
# PUB
cat > ~/.ssb/config <<EOF
{
"connections": {
"incoming": {
"net": [
{
"scope": "public", "external": ["$nodename"], "transform": "shs", "port": 8008
},
{ "scope": "private", "host": "127.0.0.1", "transform": "shs", "port": 8008 }
]
},
"outgoing": {
"net": [
{
"transform": "shs"
}
]
}
}
}
EOF
cat > ~/.zen/run-ssb_$nodename.sh <<EOF
#!/bin/bash
echo _$ > ~/.zen/ssb.pid.bash
while true; do
ssb-server start --host $nodename
echo _! > ~/.zen/ssb.pid
done
EOF
# REPLACE _ with $
sed -i s/_/\$/g ~/.zen/run-ssb_$nodename.sh
chmod 755 ~/.zen/run-ssb_$nodename.sh
ssb-server start --host $nodename &
fi
echo "
_ __ __ _
_ _ .__|_o _ (_ (_ |_)
(_(_)| || |(_| __)__)|_)
_|
$nodename
"
echo '
__ _ _ _ _
(_ |_|_)\ /|_|_) o._ o_|_
__)|_| \ \/ |_| \ || || |_ ... SCUTTLEBUTT ... OK?
'
echo "DOES SCUTTELBUTT IS RUNNING FINE?"
echo "Then add $HOME/.zen/run-ssb_$nodename.sh & TO YOUR '/etc/rc.local' !!! "
}
$@