149 lines
3.6 KiB
Bash
Executable File
149 lines
3.6 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
|
|
npm install -g ssb-server
|
|
|
|
# Move node_modules with ssb-server (why do I have to do that?)
|
|
ssbSERVER=$(which ssb-server)
|
|
node_modules_path=$(echo $ssbSERVER | sed s/bin\\/ssb-server/lib/)
|
|
mv ~/.ssb_astroport/node_modules/* $node_modules_path/node_modules/
|
|
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 ]] && [[ ! -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)
|
|
|
|
echo "
|
|
_ __ __ _
|
|
_ _ .__|_o _ (_ (_ |_)
|
|
(_(_)| || |(_| __)__)|_)
|
|
_|
|
|
$nodename
|
|
"
|
|
|
|
if [[ $extension == $nodename ]]; then
|
|
|
|
|
|
nodename=$nodename.home
|
|
# 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 "DOES SCUTTELBUTT IS RUNNING?"
|
|
echo "ADD $HOME/.zen/run-ssb_$nodename.sh & TO YOUR '/etc/rc.local' !!! "
|
|
|
|
echo '
|
|
__ _ _ _ _
|
|
(_ |_|_)\ /|_|_) o._ o_|_
|
|
__)|_| \ \/ |_| \ || || |_ ... SCUTTLEBUTT ... OK?
|
|
|
|
'
|
|
|
|
}
|
|
|
|
$@
|