astroport/.install/ipfs_alone.sh

138 lines
5.0 KiB
Bash
Raw Permalink Normal View History

2020-05-02 01:27:09 +02:00
#!/bin/bash
2020-05-04 17:05:23 +02:00
########################################################################
2020-05-20 02:16:53 +02:00
{ # this ensures the entire script is downloaded #
2020-05-02 01:27:09 +02:00
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
2020-05-04 17:05:23 +02:00
ME="${0##*/}"
2020-05-02 01:27:09 +02:00
2020-05-17 20:18:09 +02:00
# 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() {
2020-05-20 02:56:59 +02:00
echo -e "${c_red}$1$c_"
exit 1
}
# CHECK if daemon is already running
2020-05-17 20:48:50 +02:00
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
2020-05-17 11:56:39 +02:00
[[ -d ~/.ipfs ]] && echo "IPFS install exist! Please remove or backup before executing this script" && exit 1
2020-05-02 01:27:09 +02:00
2020-05-17 20:18:09 +02:00
echo -e "${c_yellow}Astroport IPFS Layer installation...$c_"
2020-05-02 01:27:09 +02:00
# CHECK node IP isLAN?
2020-05-17 11:56:39 +02:00
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])/")
2020-05-03 18:03:39 +02:00
MACHINE_TYPE=`uname -m`
2020-05-17 20:37:49 +02:00
2020-05-17 20:53:07 +02:00
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
2020-11-06 00:27:52 +01:00
curl -s https://dist.ipfs.io/ipfs-update/v1.6.0/ipfs-update_v1.6.0_linux-amd64.tar.gz -o $MY_PATH/ipfs-update.tar.gz
2020-05-17 20:53:07 +02:00
elif [ ${MACHINE_TYPE:0:3} == 'arm' ]; then
2020-11-06 00:27:52 +01:00
curl -s https://dist.ipfs.io/ipfs-update/v1.6.0/ipfs-update_v1.6.0_linux-arm.tar.gz -o $MY_PATH/ipfs-update.tar.gz
2020-05-17 20:53:07 +02:00
else
[ ! -f $MY_PATH/ipfs-update.tar.gz ] && err "Your $MACHINE_TYPE is not supported yet... Please add an issue."
fi
2020-05-03 18:05:52 +02:00
echo "INSTALL ipfs-update >>>>>>>>>>>>>>>>>>>>>>>>>>"
sudo tar -xvzf $MY_PATH/ipfs-update.tar.gz -C /usr/src/ || err "Untar ipfs-update"
2020-05-02 01:27:09 +02:00
rm $MY_PATH/ipfs-update.tar.gz
cd /usr/src/ipfs-update/
sudo ./install.sh || err "Install ipfs-update"
2020-05-02 01:27:09 +02:00
cd $MY_PATH
echo "INSTALL ipfs 0.7.0 >>>>>>>>>>>>>>>>>>>>>>>>>>"
2020-11-06 00:27:52 +01:00
sudo ipfs-update install 0.7.0 || err "Install IPFS"
2020-05-02 01:27:09 +02:00
2020-12-07 14:43:45 +01:00
## DEBIAN
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 --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
2020-12-07 16:29:04 +01:00
## Special Xbian init.d config
if [[ $USER == "xbian" && -f ~/.zen/astroport/.install/templates/ipfs/ipfs-initV.sh ]]; then
sudo cp ~/.zen/astroport/.install/templates/ipfs/ipfs-initV.sh /etc/init.d/ipfs
sudo chmod 755 /etc/init.d/ipfs
2020-12-12 02:21:08 +01:00
sudo touch /var/log/ipfs.log && sudo chown xbian /var/log/ipfs.log
2020-12-07 16:29:04 +01:00
sudo service ipfs enable
2020-12-12 02:21:08 +01:00
else
sudo systemctl daemon-reload || err "Restart IPFS"
sudo systemctl enable ipfs || err "Enable IPFS daemon"
2020-12-07 16:29:04 +01:00
fi
2020-05-02 01:27:09 +02:00
# INIT ipfs
2020-05-17 11:56:39 +02:00
[[ $isLAN ]] && ipfs init -p lowpower \
|| ipfs init -p server
2020-06-04 14:30:04 +02:00
# 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
2020-05-02 01:27:09 +02:00
2020-05-20 21:24:32 +02:00
sudo chown -R $USER:$USER ~/.ipfs || exit 1
2020-05-17 11:56:39 +02:00
###########################################
2020-05-17 20:18:09 +02:00
# ACTIVATE IPFS OPTIONS: #swarm0 INIT
###########################################
2020-05-20 02:16:53 +02:00
### IMPORTANT !!!!!!! IMPORTANT !!!!!!
2020-05-17 11:56:39 +02:00
###########################################
2020-05-20 21:22:22 +02:00
# DHT PUBSUB mode
2020-05-02 01:27:09 +02:00
ipfs config Pubsub.Router gossipsub
2020-05-17 20:18:09 +02:00
# MAXSTORAGE = 1/2 available
2020-05-02 01:27:09 +02:00
availableDiskSize=$(df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}')
diskSize="$((availableDiskSize / 2))"
ipfs config Datastore.StorageMax $diskSize
2020-05-17 20:18:09 +02:00
## Activate Rapid "ipfs p2p"
2020-05-02 01:27:09 +02:00
ipfs config --json Experimental.Libp2pStreamMounting true
2020-11-06 00:49:18 +01:00
ipfs config --json Experimental.P2pHttpProxy true
2020-05-02 01:27:09 +02:00
######### MAKE DEFAULT BOOTSTRAP TO oasis.astroport.com 2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS ###########
2020-05-02 01:27:09 +02:00
ipfs bootstrap rm --all
ipfs bootstrap add /dnsaddr/oasis.astroport.com/tcp/4001/ipfs/12D3KooWBYme2BsNUrtx4mEdNX6Yioa9AV7opWzQp6nrPs6ZKabN
ipfs bootstrap add /ip4/51.15.166.54/tcp/4001/p2p/12D3KooWBYme2BsNUrtx4mEdNX6Yioa9AV7opWzQp6nrPs6ZKabN
ipfs bootstrap add /ip4/51.15.166.54/udp/4001/quic/p2p/12D3KooWBYme2BsNUrtx4mEdNX6Yioa9AV7opWzQp6nrPs6ZKabN
ipfs bootstrap add /ip6/fe80::208:a2ff:fe0c:20d8/tcp/4001/p2p/12D3KooWBYme2BsNUrtx4mEdNX6Yioa9AV7opWzQp6nrPs6ZKabN
2020-05-17 11:56:39 +02:00
###########################################
2020-06-04 14:30:04 +02:00
# TODO: ADD some other bootstrap NODES
###########################################
2020-05-02 01:27:09 +02:00
2020-05-17 20:37:49 +02:00
sudo systemctl start ipfs || err "Start IPFS daemon"
2020-05-20 03:04:40 +02:00
sleep 3
2020-05-16 00:44:50 +02:00
2020-05-20 02:16:53 +02:00
echo "Peers: " && ipfs swarm peers && sleep 0.3
2020-05-20 03:09:08 +02:00
#[[ ! $(ipfs swarm peers) =~ "/ip4/" ]] && err "No peers found in swarm. Please open issue :https://git.p2p.legal/axiom-team/astroport/issues"
2020-05-15 22:02:32 +02:00
2020-05-20 02:16:53 +02:00
} # this ensures the entire script is downloaded #
2020-05-20 17:51:33 +02:00
# IPFS CONFIG documentation: https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#addressesswarm