2020-03-27 01:50:40 +01:00
|
|
|
#!/bin/bash
|
2020-04-30 02:51:50 +02:00
|
|
|
ipfs() {
|
2020-03-19 21:25:39 +01:00
|
|
|
# Install IPFS
|
2020-03-27 01:50:40 +01:00
|
|
|
|
|
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
|
|
|
|
|
|
## Config
|
2020-04-30 02:04:13 +02:00
|
|
|
templates="$MY_PATH/.install/templates/ipfs"
|
2020-03-27 01:50:40 +01:00
|
|
|
|
|
|
|
if [ "$EUID" -eq 0 ]
|
2020-04-28 18:18:24 +02:00
|
|
|
then echo -e "${c_red}DO NOT EXECUTE AS root. Choose a user for your Astroport Station (we like pi)$c_"
|
2020-03-27 01:50:40 +01:00
|
|
|
exit 1
|
|
|
|
else echo -e "${c_yellow}OK $USER, let's go!$c_";
|
|
|
|
fi
|
|
|
|
|
2020-04-30 01:39:27 +02:00
|
|
|
[[ -d ~/.ipfs ]] && echo "IPFS install exist, please remove backup before execute this script" && exit 1
|
2020-03-27 01:50:40 +01:00
|
|
|
|
2020-04-30 02:51:50 +02:00
|
|
|
echo -e "${c_yellow}Onboarding IPFS...$c_"
|
|
|
|
[[ -f /usr/local/bin/ipfs ]] && sudo service ipfs stop
|
2020-03-19 21:25:39 +01:00
|
|
|
|
|
|
|
|
2020-04-30 02:51:50 +02:00
|
|
|
if [[ $ARM == "yes" ]]; then
|
|
|
|
wget 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 || err+="Download ipfs-update"
|
|
|
|
else
|
|
|
|
wget 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 || err+="Download ipfs-update"
|
|
|
|
fi
|
2020-04-30 01:39:27 +02:00
|
|
|
|
2020-04-30 02:51:50 +02:00
|
|
|
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
|
2020-03-27 02:01:26 +01:00
|
|
|
|
2020-04-30 02:51:50 +02:00
|
|
|
echo "INSTALL latest ipfs"
|
|
|
|
sudo ipfs-update install latest || err+="Install IPFS"
|
2020-03-19 21:25:39 +01:00
|
|
|
|
2020-04-30 02:51:50 +02:00
|
|
|
echo "CREATE SYSTEMD ipfs SERVICE"
|
|
|
|
sudo cp -f $templates/ipfs.service /etc/systemd/system/
|
|
|
|
sudo sed -i "s/_USER/$USER/g" /etc/systemd/system/ipfs.service
|
|
|
|
|
|
|
|
sudo systemctl daemon-reload || err+="Restart IPFS"
|
|
|
|
sudo systemctl enable ipfs || err+="Enable IPFS daemon"
|
2020-03-27 01:50:40 +01:00
|
|
|
|
2020-04-30 02:51:50 +02:00
|
|
|
# INIT ipfs
|
|
|
|
ipfs init -p lowpower
|
|
|
|
# ipfs init -p server ## Uncomment for server infrastructure
|
2020-03-27 01:50:40 +01:00
|
|
|
|
2020-04-30 02:51:50 +02:00
|
|
|
# ACTIVATE CONFIG OPTIONS
|
|
|
|
# PUBSUB
|
|
|
|
ipfs config Pubsub.Router gossipsub
|
|
|
|
# MAXSTORAGE
|
|
|
|
availableDiskSize=$(df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}')
|
|
|
|
diskSize="$((availableDiskSize / 2))"
|
|
|
|
ipfs config Datastore.StorageMax $diskSize
|
|
|
|
## PORT FORWARD (SSH)
|
|
|
|
ipfs config --json Experimental.Libp2pStreamMounting true
|
2020-03-27 01:50:40 +01:00
|
|
|
|
2020-04-30 02:51:50 +02:00
|
|
|
######### UPDATE BOOTSTRAP LIST ###########
|
|
|
|
ipfs bootstrap rm --all
|
2020-03-27 01:50:40 +01:00
|
|
|
|
2020-04-30 02:51:50 +02:00
|
|
|
sudo systemctl restart ipfs || err+="Restart IPFS daemon"
|
2020-03-27 02:01:26 +01:00
|
|
|
|
2020-03-27 01:50:40 +01:00
|
|
|
|
|
|
|
exit 0
|
2020-04-30 02:51:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$@
|