Astroport.ONE/tools/ipfs_setup.sh

92 lines
2.8 KiB
Bash
Raw Normal View History

2022-09-10 15:48:23 +02:00
#!/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 "DO NOT EXECUTE AS root. Choose a user for your Astroport Station (we like pi)"
exit 1
else echo -e "OK $USER, let's go!";
fi
# Ask user password on start
sudo true
## Error funciton
err() {
echo -e "ERREUR: $1"
exit 1
}
# CHECK node IP isLAN?
myIP=$(hostname -I | awk '{print $1}')
2022-12-18 20:45:43 +01:00
isLAN=$(route -n |awk '$1 == "0.0.0.0" {print $2}' | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
2022-11-16 06:11:07 +01:00
YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
2022-09-10 15:48:23 +02:00
MACHINE_TYPE=`uname -m`
2022-11-12 15:12:27 +01:00
# CHECK if daemon is already running
if [[ $YOU ]]; then
echo "ipfs daemon already running...! Run by $YOU $MACHINE_TYPE"
2022-11-25 20:58:43 +01:00
[[ $YOU == $USER ]] && echo "Stopping ipfs daemon" && killall ipfs \
2022-11-12 15:15:12 +01:00
|| (echo "ERROR $YOU is running ipfs, must be $USER" && exit 1)
2022-09-10 15:48:23 +02:00
else
2022-11-12 15:12:27 +01:00
# INIT ipfs
if [[ ! -d ~/.ipfs ]]; then
[[ $isLAN ]] && ipfs init -p lowpower \
|| ipfs init -p server
fi
fi
echo -e "Astroport activate IPFS Layer installation..."
2022-09-10 15:48:23 +02:00
## DEBIAN
echo "CREATE SYSTEMD ipfs SERVICE >>>>>>>>>>>>>>>>>>"
cat > /tmp/ipfs.service <<EOF
[Unit]
Description=IPFS daemon
After=network.target
2022-11-13 02:53:18 +01:00
Requires=network.target
2022-09-10 15:48:23 +02:00
[Service]
2022-11-13 02:53:18 +01:00
Type=simple
2022-09-10 15:48:23 +02:00
User=_USER_
2022-11-13 02:53:18 +01:00
RestartSec=1
Restart=always
Environment=IPFS_FD_MAX=8192
2022-10-16 17:09:03 +02:00
ExecStart=/usr/local/bin/ipfs daemon --enable-pubsub-experiment --enable-namesys-pubsub
2022-09-10 15:48:23 +02:00
CPUAccounting=true
CPUQuota=60%
[Install]
WantedBy=multi-user.target
EOF
2022-11-12 15:12:27 +01:00
sudo cp -f /tmp/ipfs.service /etc/systemd/system/
sudo sed -i "s/_USER_/$USER/g" /etc/systemd/system/ipfs.service
2022-09-10 15:48:23 +02:00
2022-11-12 15:12:27 +01:00
sudo systemctl daemon-reload
sudo systemctl enable ipfs
2022-09-10 15:48:23 +02:00
###########################################
# ACTIVATE IPFS OPTIONS: #swarm0 INIT
###########################################
2022-11-16 06:11:07 +01:00
~/.zen/Astroport.ONE/tools/ipfs_config.sh
2022-11-12 15:12:27 +01:00
sudo systemctl restart ipfs
2022-09-10 15:48:23 +02:00
2022-11-13 02:53:18 +01:00
## Add ulimit "open files" (avoid ipfs hang)
ulimit -n 2048
2022-09-10 15:48:23 +02:00
} # this ensures the entire script is downloaded #
# IPFS CONFIG documentation: https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#addressesswarm
2022-11-13 04:08:06 +01:00
# https://github.com/ipfs/kubo/blob/master/docs/config.md
# VISUALISER DHT
# ipfs stats dht wan
# CONSUMING RESSOURCES
# export DPID=26024; watch -n0 'printf "sockets: %s\nleveldb: %s\nflatfs: %s\n" $(ls /proc/${DPID}/fd/ -l | grep "socket:" | wc -l) $(ls /proc/${DPID}/fd/ -l | grep "\\/datastore\\/" | wc -l) $(ls /proc/${DPID}/fd/ -l | grep "\\/blocks\\/" | wc -l)'