astroport/.install/scuttlebutt.sh

171 lines
4.6 KiB
Bash
Raw 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-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-03-23 19:07:37 +01:00
# 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
2020-03-23 20:52:51 +01:00
# Install ssb-server and config in ~/.ssb_astroport
2020-03-23 21:38:52 +01:00
[[ ! -d ~/.ssb_astroport ]] && mkdir -p ~/.ssb_astroport
cd ~/.ssb_astroport
2020-03-23 21:42:55 +01:00
2020-03-24 03:10:28 +01:00
### Install module in ~/.ssb_astroport/node_modules
npm install sodium-native ssb-backlinks ssb-ws ssb-links ssb-query ssb-secret-blob ssb-private
2020-03-23 19:07:37 +01:00
npm install -g ssb-server
2020-03-26 03:08:15 +01:00
### Install oasis webclient (could replace ssb-server, TODO: try it)
# npm -g install fraction/oasis#semver:
2020-03-24 03:10:28 +01:00
2020-03-25 18:21:56 +01:00
# Move node_modules with ssb-server (why do I have to do that? crazy heavy crappy wonderful node.js )
2020-03-24 03:10:28 +01:00
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
2020-03-26 05:20:49 +01:00
# INSTALL sbotc
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
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-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-23 19:07:37 +01:00
2020-03-24 06:14:21 +01:00
if [[ $extension == $nodename ]]; then
2020-03-24 14:52:34 +01:00
nodename=$nodename.local
2020-03-24 01:20:10 +01:00
# LOCAL
cat > ~/.ssb/config <<EOF
{
"connections": {
"incoming": {
"net": [
{ "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-24 01:20:10 +01:00
},
"outgoing": {
"net": [{ "transform": "shs" }]
}
}
}
EOF
2020-03-29 15:44:01 +02:00
cat > ~/.zen/run-ssb_server.sh <<EOF
2020-03-24 01:20:10 +01:00
#!/bin/bash
echo _$ > ~/.zen/ssb.pid.bash
while true; do
2020-03-24 03:10:28 +01:00
ssb-server start
2020-03-24 01:20:10 +01:00
echo _! > ~/.zen/ssb.pid
done
EOF
2020-03-24 14:52:34 +01:00
# REPLACE _ with $
2020-03-29 15:44:01 +02:00
sed -i s/_/\$/g ~/.zen/run-ssb_server.sh
chmod 755 ~/.zen/run-ssb_server.sh
2020-03-24 14:52:34 +01:00
ssb-server start &
else
2020-03-24 01:20:10 +01:00
2020-03-23 22:32:30 +01:00
2020-03-23 19:07:37 +01:00
# PUB
cat > ~/.ssb/config <<EOF
{
"connections": {
"incoming": {
"net": [
2020-03-29 16:38:08 +02:00
{ "scope": "public", "external": ["$nodename"], "transform": "shs", "port": 8008 },
2020-03-23 19:07:37 +01:00
{ "scope": "private", "host": "127.0.0.1", "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": {
"net": [
{
"transform": "shs"
}
]
}
}
}
EOF
2020-03-29 15:44:01 +02:00
cat > ~/.zen/run-ssb_server.sh <<EOF
2020-03-24 01:20:10 +01:00
#!/bin/bash
echo _$ > ~/.zen/ssb.pid.bash
while true; do
2020-03-24 03:10:28 +01:00
ssb-server start --host $nodename
2020-03-24 01:20:10 +01:00
echo _! > ~/.zen/ssb.pid
done
EOF
2020-03-24 02:01:22 +01:00
# REPLACE _ with $
2020-03-29 15:44:01 +02:00
sed -i s/_/\$/g ~/.zen/run-ssb_server.sh
chmod 755 ~/.zen/run-ssb_server.sh
2020-03-24 14:52:34 +01:00
ssb-server start --host $nodename &
fi
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
'
echo "DOES SCUTTELBUTT IS RUNNING FINE?"
2020-03-29 15:44:01 +02:00
echo "Then add $HOME/.zen/run-ssb_server.sh & TO YOUR '/etc/rc.local' !!! "
2020-03-29 16:38:08 +02:00
echo "WAIT 10 seconds before ssb_INIT.sh"
2020-03-29 16:15:39 +02:00
2020-03-29 16:38:08 +02:00
sleep 10
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
$@