forked from axiom-team/astroport
124 lines
4.5 KiB
Bash
Executable File
124 lines
4.5 KiB
Bash
Executable File
#!/bin/bash
|
|
########################################################################
|
|
{ # this ensures the entire script is downloaded #
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
ME="${0##*/}"
|
|
|
|
# CHECK not root user !!
|
|
if [ "$EUID" -eq 0 ]
|
|
then echo -e "${c_red}DO NOT EXECUTE AS root. Choose a user for your Astroport Station (we like pi)$c_"
|
|
exit 1
|
|
else echo -e "${c_yellow}OK $USER, let's go!$c_";
|
|
fi
|
|
|
|
# Ask user password on start
|
|
sudo true
|
|
|
|
## Error funciton
|
|
err() {
|
|
echo -e "${c_red}$1$c_"
|
|
exit 1
|
|
}
|
|
|
|
# CHECK if daemon is already running
|
|
if [[ $(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) ]]; then
|
|
echo "ipfs daemon already running...! Must STOP ipfs AND remove ~/.ipfs to install again !!"
|
|
ipfs id && echo "ipfs swarm peers: " && ipfs swarm peers
|
|
echo "ipfs bootstrap list: " && ipfs bootstrap list
|
|
echo "Please RUN : sudo systemctl stop ipfs"
|
|
exit 1
|
|
fi
|
|
|
|
[[ -d ~/.ipfs ]] && echo "IPFS install exist! Please remove or backup before executing this script" && exit 1
|
|
|
|
echo -e "${c_yellow}Astroport IPFS Layer installation...$c_"
|
|
|
|
# CHECK node IP isLAN?
|
|
myIP=$(hostname -I | awk '{print $1}')
|
|
isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
|
|
|
|
MACHINE_TYPE=`uname -m`
|
|
|
|
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
|
curl -s https://dist.ipfs.io/ipfs-update/v1.5.2/ipfs-update_v1.5.2_linux-amd64.tar.gz -o $MY_PATH/ipfs-update.tar.gz
|
|
elif [ ${MACHINE_TYPE:0:3} == 'arm' ]; then
|
|
curl -s https://dist.ipfs.io/ipfs-update/v1.5.2/ipfs-update_v1.5.2_linux-arm.tar.gz -o $MY_PATH/ipfs-update.tar.gz
|
|
else
|
|
[ ! -f $MY_PATH/ipfs-update.tar.gz ] && err "Your $MACHINE_TYPE is not supported yet... Please add an issue."
|
|
fi
|
|
|
|
echo "INSTALL ipfs-update >>>>>>>>>>>>>>>>>>>>>>>>>>"
|
|
sudo tar -xvzf $MY_PATH/ipfs-update.tar.gz -C /usr/src/ || err "Untar ipfs-update"
|
|
rm $MY_PATH/ipfs-update.tar.gz
|
|
cd /usr/src/ipfs-update/
|
|
sudo ./install.sh || err "Install ipfs-update"
|
|
cd $MY_PATH
|
|
|
|
echo "INSTALL latest ipfs >>>>>>>>>>>>>>>>>>>>>>>>>>"
|
|
sudo ipfs-update install 0.5.1 || err "Install IPFS"
|
|
|
|
echo "CREATE SYSTEMD ipfs SERVICE >>>>>>>>>>>>>>>>>>"
|
|
cat > /tmp/ipfs.service <<EOF
|
|
[Unit]
|
|
Description=IPFS daemon
|
|
After=network.target
|
|
|
|
[Service]
|
|
User=_USER_
|
|
ExecStart=/usr/local/bin/ipfs daemon --enable-pubsub-experiment --enable-namesys-pubsub --routing=dhtclient --enable-gc
|
|
Restart=on-failure
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
sudo cp -f /tmp/ipfs.service /etc/systemd/system/
|
|
sudo sed -i "s/_USER_/$USER/g" /etc/systemd/system/ipfs.service
|
|
|
|
[[ -d ~/.ipfs ]] && sudo chown -R $USER:$USER ~/.ipfs
|
|
|
|
sudo systemctl daemon-reload || err "Restart IPFS"
|
|
sudo systemctl enable ipfs || err "Enable IPFS daemon"
|
|
|
|
# INIT ipfs
|
|
[[ $isLAN ]] && ipfs init -p lowpower \
|
|
|| ipfs init -p server
|
|
# TODO try ipfs init --profile=badgerds (for better performance)
|
|
# https://discuss.ipfs.io/t/adding-content-to-ipfs-is-quite-slow-any-ideas-on-why-and-how-to-speed-things-up/8135/3
|
|
|
|
sudo chown -R $USER:$USER ~/.ipfs || exit 1
|
|
|
|
###########################################
|
|
# ACTIVATE IPFS OPTIONS: #swarm0 INIT
|
|
###########################################
|
|
### IMPORTANT !!!!!!! IMPORTANT !!!!!!
|
|
###########################################
|
|
# DHT PUBSUB mode
|
|
ipfs config Pubsub.Router gossipsub
|
|
# MAXSTORAGE = 1/2 available
|
|
availableDiskSize=$(df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}')
|
|
diskSize="$((availableDiskSize / 2))"
|
|
ipfs config Datastore.StorageMax $diskSize
|
|
## Activate Rapid "ipfs p2p"
|
|
ipfs config --json Experimental.Libp2pStreamMounting true
|
|
|
|
######### UPDATE BOOTSTRAP LIST ###########
|
|
ipfs bootstrap rm --all
|
|
ipfs bootstrap add /dnsaddr/oasis.astroport.com/tcp/4001/ipfs/Qmf98yiZja5yrVctp5x4FicUe3Dubzbm5TiUHqJQwwT5Rj
|
|
ipfs bootstrap add /ip4/51.15.166.54/tcp/4001/p2p/Qmf98yiZja5yrVctp5x4FicUe3Dubzbm5TiUHqJQwwT5Rj
|
|
ipfs bootstrap add /ip6/fe80::208:a2ff:fe0c:20d8/tcp/4001/p2p/Qmf98yiZja5yrVctp5x4FicUe3Dubzbm5TiUHqJQwwT5Rj
|
|
###########################################
|
|
# TODO: ADD some other bootstrap NODES
|
|
###########################################
|
|
|
|
sudo systemctl start ipfs || err "Start IPFS daemon"
|
|
|
|
sleep 3
|
|
|
|
echo "Peers: " && ipfs swarm peers && sleep 0.3
|
|
#[[ ! $(ipfs swarm peers) =~ "/ip4/" ]] && err "No peers found in swarm. Please open issue :https://git.p2p.legal/axiom-team/astroport/issues"
|
|
|
|
} # this ensures the entire script is downloaded #
|
|
# IPFS CONFIG documentation: https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#addressesswarm
|