astroport/.install/scuttlebutt.sh

102 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
scuttlebutt() {
echo -e "${c_yellow}Onboarding SCUTTLEBUTT...$c_"
where_is_ssb_installed=$(which ssb-server)
# Install npm_modules in ~/.zen/fatlayer_install
mkdir -p ~/.zen/fatlayer_install
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ $where_is_ssb_installed == "" ]]; then
cd ~/.zen/fatlayer_install
# 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 sbot-server
npm install sodium-native ssb-backlinks ssb-ws ssb-links ssb-query
npm install -g ssb-server
fi
# test Install
ssbSERVER=$(which ssb-server)
[[ $ssbSERVER == "" ]] && echo "Check your ssb-server install... Cannot find it !!" && exit 1
# BACKUP OLD SSB
[[ -d ~/.ssb ]] && mv ~/.ssb ~/.ssb.$USER # BACKUP OLD SSB
# MAKE A LINK ~/.ssb.astroport to ~/.ssb
mkdir ~/.ssb.astroport
ln -s ~/.ssb.astroport ~/.ssb
# Create config (TODO: adapt if public Pub or Local Node)
nodename=$(cat /etc/hostname)
extension=$($(echo $nodename | cut -d '.' -f 2))
if [[ $extension == "" ]]; then
nodename=$(echo $nodename).home
# LOCAL
cat > ~/.ssb/config <<EOF
{
"incoming": {
"net": [{ "port": 8008, "scope": "public", "transform": "shs" }]
},
"outgoing": {
"net": [{ "transform": "shs" }]
}
}
EOF
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
fi
# Store current user as sudo will change it
currentUser=$USER
# Copy SYSTEMD service to correct location
sudo cp "$BASE_DIR/ssb.service" /tmp/ssb.service
# Copy repplace __USER__ place holder to current user
sudo sed -i "s|__USER__|${currentUser}|g" /tmp/ssb.service
sudo sed -i "s|__SSBSERVER__|${ssbSERVER}|g" /tmp/ssb.service
sudo mv /tmp/ssb.service /etc/systemd/system/ssb.service
# Reload, Enable and start SSB Service
sudo systemctl daemon-reload
sudo systemctl enable ssb.service
sudo systemctl start ssb.service
}
$@