astrXbian/.install/ipfs_alone.sh

108 lines
3.5 KiB
Bash
Raw Normal View History

2020-12-12 01:26:39 +01: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 ]
2021-02-03 02:05:20 +01:00
then echo -e "DO NOT EXECUTE AS root. Choose a user for your Astroport Station (we like pi)"
2020-12-12 01:26:39 +01:00
exit 1
2021-02-03 02:05:20 +01:00
else echo -e "OK $USER, let's go!";
2020-12-12 01:26:39 +01:00
fi
# Ask user password on start
sudo true
## Error funciton
err() {
2021-08-11 05:28:21 +02:00
echo -e "ERREUR: $1"
exit 1
2020-12-12 01:26:39 +01:00
}
# 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
2021-08-11 05:28:21 +02:00
ipfs id && echo "ipfs swarm peers: " && ipfs swarm peers
echo "ipfs bootstrap list: " && ipfs bootstrap list
echo "ipfs daemon already running...!"
exit 0
2020-12-12 01:26:39 +01:00
fi
2022-05-28 17:46:25 +02:00
echo -e "Astroport activate IPFS Layer installation..."
2020-12-12 01:26:39 +01:00
# 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`
2021-01-29 01:03:15 +01:00
# INIT ipfs
[[ $isLAN ]] && ipfs init -p lowpower \
|| ipfs init -p server
2021-08-11 05:28:21 +02:00
## Special Xbian init.d config
2021-01-29 01:03:15 +01:00
if [[ "$USER" == "xbian" ]]; then
2021-08-11 05:28:21 +02:00
sudo cp ~/.zen/astrXbian/.install/templates/ipfs/ipfs-initV.sh /etc/init.d/ipfs
sudo chmod 755 /etc/init.d/ipfs
sudo touch /var/log/ipfs.log && sudo chown xbian /var/log/ipfs.log
2021-01-29 01:03:15 +01:00
else
2021-08-11 05:28:21 +02:00
## DEBIAN
echo "CREATE SYSTEMD ipfs SERVICE >>>>>>>>>>>>>>>>>>"
2021-01-29 01:03:15 +01:00
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
2021-06-05 22:04:59 +02:00
CPUAccounting=true
CPUQuota=60%
2021-01-29 01:03:15 +01:00
[Install]
WantedBy=multi-user.target
EOF
2021-08-11 05:28:21 +02:00
sudo cp -f /tmp/ipfs.service /etc/systemd/system/
sudo sed -i "s/_USER_/$USER/g" /etc/systemd/system/ipfs.service
2021-01-29 01:03:15 +01:00
2021-08-11 05:28:21 +02:00
[[ -d ~/.ipfs ]] && sudo chown -R $USER:$USER ~/.ipfs
sudo systemctl daemon-reload
sudo systemctl enable ipfs
2020-12-12 01:26:39 +01:00
fi
###########################################
# 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
ipfs config --json Experimental.P2pHttpProxy true
ipfs config --json Swarm.ConnMgr.LowWater 0
ipfs config --json Swarm.ConnMgr.HighWater 0
2022-04-18 16:09:28 +02:00
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]'
######### CLEAN DEFAULT BOOTSTRAP TO STAY INVISIBLE ###########
2020-12-12 01:26:39 +01:00
ipfs bootstrap rm --all
###########################################
# BOOTSTRAP NODES ARE ADDED LATER
2020-12-12 01:26:39 +01:00
###########################################
2022-05-08 21:25:15 +02:00
# AVOID CONFLICT WITH KODI ./.install/.kodi/userdata/guisettings.xml
ipfs config Addresses.Gateway "/ip4/0.0.0.0/tcp/8080"
2020-12-12 01:26:39 +01:00
2021-01-29 01:03:15 +01:00
[[ "$USER" != "xbian" ]] && sudo systemctl restart ipfs
2020-12-12 01:26:39 +01:00
} # this ensures the entire script is downloaded #
# IPFS CONFIG documentation: https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#addressesswarm