astroport/.install/scuttlebutt.sh

131 lines
3.9 KiB
Bash
Raw Permalink Normal View History

2020-03-19 21:25:39 +01:00
#!/bin/bash
scuttlebutt() {
2020-03-23 19:07:37 +01:00
echo -e "${c_yellow}Onboarding SCUTTLEBUTT...$c_"
where_is_ssb_installed=$(which ssb-server)
2020-05-09 02:09:19 +02:00
where_is_oasis_installed=$(which oasis)
2020-03-24 02:01:22 +01:00
mkdir -p ~/.zen
2020-03-23 19:07:37 +01:00
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2020-03-23 19:31:54 +01:00
if [[ ! $where_is_ssb_installed ]]; then
2020-04-30 01:21:38 +02:00
# KILL the BRUTAL WAY...
kill -9 $(ps auxf --sort=+utime | grep -w ssb-server| grep -v -E 'color=auto|grep' | tail -n 1 | awk '{print $2}')
2020-03-23 19:07:37 +01:00
# Install dependencies
sudo apt-get install -y socat python3-dev libtool python3-setuptools autoconf automake
# Install nvm
2020-04-30 03:01:48 +02:00
if [[ ! $(which nvm) ]]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
source ~/.bashrc
export NVM_DIR="$HOME/.nvm"
nvm install --lts
fi
2020-03-23 21:42:55 +01:00
2020-04-30 04:09:58 +02:00
cd ~/.ssb
### Install module
2020-05-09 21:34:28 +02:00
npm install -g sodium-native ssb-backlinks ssb-ws ssb-links ssb-query ssb-secret-blob ssb-private
2020-04-28 18:18:24 +02:00
npm install -g ssb-server
2020-05-09 02:09:19 +02:00
2020-04-28 18:18:24 +02:00
# TODO plugin activation !??
# sbot plugins.enable
### Install oasis & ssb-cli (could replace ssb-server?? TODO: try it)
2020-04-27 22:57:41 +02:00
npm -g install fraction/oasis#semver:
2020-04-30 04:09:58 +02:00
npm install -g fraction/ssb-daemon
2020-05-03 00:00:16 +02:00
# npm install -g ssb-cli
2020-03-24 03:10:28 +01:00
2020-03-26 05:20:49 +01:00
# INSTALL sbotc
if [[ ! $(which sbotc) ]]; then
sudo apt install libsodium-dev jq -y
git submodule add https://git.scuttlebot.io/%25133ulDgs%2FoC1DXjoK04vDFy6DgVBB%2FZok15YJmuhD5Q%3D.sha256 sbotc
2020-03-26 05:20:49 +01:00
cd sbotc
make
sudo make install
fi
2020-03-23 19:07:37 +01:00
fi
2020-03-23 21:38:52 +01:00
# TEST ssb-server Install
2020-03-23 19:07:37 +01:00
ssbSERVER=$(which ssb-server)
[[ $ssbSERVER == "" ]] && echo "Check your ssb-server install... Cannot find it !!" && exit 1
2020-03-23 21:38:52 +01:00
# 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
2020-03-23 21:38:52 +01:00
# 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/
2020-03-23 19:07:37 +01:00
2020-03-23 21:38:52 +01:00
# Symlink ~/.ssb -> ~/.ssb_astroport
[[ -L ~/.ssb ]] && rm ~/.ssb
[[ -d ~/.ssb_astroport ]] && ln -s ~/.ssb_astroport ~/.ssb
2020-05-09 02:09:19 +02:00
## #TODO get ~/.ssb/manifest.json from template
cp ./templates/ssb/manifest.json ~/.ssb/manifest.json
2020-03-23 19:07:37 +01:00
# Create config (TODO: adapt if public Pub or Local Node)
2020-03-24 01:20:10 +01:00
# TODO: Create unique hostname in swarm !! uidna
2020-03-23 19:07:37 +01:00
nodename=$(cat /etc/hostname)
2020-03-23 20:38:06 +01:00
extension=$(echo $nodename | cut -d '.' -f 2)
2020-03-24 06:14:21 +01:00
if [[ $extension == $nodename ]]; then
2020-05-09 02:09:19 +02:00
PUB="false"
nodename=$nodename.local
2020-03-24 14:52:34 +01:00
else
2020-05-09 02:09:19 +02:00
PUB="true"
fi
2020-03-24 01:20:10 +01:00
2020-05-09 02:09:19 +02:00
cat > ~/.ssb/config <<EOF
2020-03-23 19:07:37 +01:00
{
"connections": {
"incoming": {
"net": [
2020-05-09 02:09:19 +02:00
{ "scope": "public", "host": "0.0.0.0", "external": ["$nodename"], "transform": "shs", "port": 8008 }
2020-03-28 14:01:53 +01:00
],
2020-03-29 16:38:08 +02:00
"ws": [
{ "scope": ["public", "local", "device"], "host": "0.0.0.0", "port": 8989, "transform": "shs", "http": true }
]
2020-03-23 19:07:37 +01:00
},
"outgoing": {
2020-05-09 02:09:19 +02:00
"net": [{ "transform": "shs" }]
2020-03-23 19:07:37 +01:00
}
}
}
EOF
2020-05-09 02:09:19 +02:00
cat > ~/.zen/launch-oasis.sh <<EOF
2020-03-24 01:20:10 +01:00
#!/bin/bash
2020-05-09 02:09:19 +02:00
oasis --allow-host $nodename --host $nodename
2020-03-24 01:20:10 +01:00
EOF
2020-03-24 14:52:34 +01:00
echo "
_ __ __ _
_ _ .__|_o _ (_ (_ |_)
(_(_)| || |(_| __)__)|_)
_|
$nodename
2020-03-24 01:20:10 +01:00
"
2020-03-24 01:20:10 +01:00
echo '
__ _ _ _ _
(_ |_|_)\ /|_|_) o._ o_|_
2020-03-24 14:52:34 +01:00
__)|_| \ \/ |_| \ || || |_ ... SCUTTLEBUTT ... OK?
2020-03-24 01:20:10 +01:00
'
2020-05-09 02:09:19 +02:00
echo "Launching oasis"
oasis --allow-host $nodename --host $nodename &
echo " http://$nodename:3000 "
echo
echo "ADD ~/.zen/launch-oasis.sh TO YOUR '/etc/rc.local' !!! Or use patchwork. "
2020-04-30 01:21:38 +02:00
sleep $((1 + RANDOM % 5))
echo "LAUNCHING OASIS NODE MANAGER http://$nodename:3000"
2020-05-09 02:09:19 +02:00
echo "IF YOU ARE A PUB consider protect it behind password nginx redirect !!!"
2020-05-09 02:09:19 +02:00
echo "3 seconds before ssb_INIT.sh..."
sleep 3
2020-03-29 16:15:39 +02:00
$MY_PATH/zen/ssb_INIT.sh
2020-03-19 21:25:39 +01:00
}
2020-03-19 22:21:19 +01:00
$@