mirror of
https://github.com/claudiobizzotto/ipfs-rpi.git
synced 2021-08-26 23:43:50 +03:00
* Install newest version by default * Allow version to be specified with and without 'v' * Code clean up * Make output less verbose * Add update functionality * Unify user prompts
94 lines
2.7 KiB
Bash
Executable File
94 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -o pipefail
|
|
|
|
source ./lib/functions.sh
|
|
|
|
mode="install"
|
|
if [ -x "$(command -v ipfs)" ]; then
|
|
ask ">>> IPFS already installed. Should it be updated?" || exit 0
|
|
mode="update"
|
|
fi
|
|
|
|
arm_type="? (unknown ARM system)"
|
|
rpi_revision=`sed -rn 's/Revision\s+\:\s+([0-9a-z_\-\s\,\(\)]+)/\1/p' /proc/cpuinfo`
|
|
|
|
if [[ $rpi_revision == *"900092"* ]]; then
|
|
arm_type="Raspberry Pi model zero"
|
|
elif [[ $rpi_revision == *"00"* ]]; then
|
|
arm_type="Raspberry Pi 1"
|
|
elif [[ $rpi_revision == *"a01041"* || $rpi_revision == *"a21041"* ]]; then
|
|
arm_type="Raspberry Pi 2"
|
|
elif [[ $rpi_revision == *"a02082"* || $rpi_revision = *"a22082"* ]]; then
|
|
arm_type="Raspberry Pi 3"
|
|
fi
|
|
|
|
echo ">>> Starting installation on ARM device compatible with $arm_type"
|
|
|
|
# Download and install IPFS
|
|
ipfs_arch=${2-"linux-arm"}
|
|
ipfs_version=$(curl -s https://dist.ipfs.io/go-ipfs/versions | tail -1)
|
|
ipfs_version=${1-$ipfs_version}
|
|
ipfs_version="v${ipfs_version#v}"
|
|
|
|
echo ">>> Installing IPFS version $ipfs_version"
|
|
|
|
tar_gz_destination=/tmp/go-ipfs_${ipfs_version}_${ipfs_arch}.tar.gz
|
|
wget "https://dist.ipfs.io/go-ipfs/${ipfs_version}/go-ipfs_${ipfs_version}_${ipfs_arch}.tar.gz" \
|
|
-q --show-progress \
|
|
-O $tar_gz_destination
|
|
|
|
if [ ! -f $tar_gz_destination ]; then
|
|
echo ">>> Failed to download IPFS"
|
|
exit 1
|
|
fi
|
|
|
|
ipfs_destination=/usr/local/bin/ipfs
|
|
tar xzf $tar_gz_destination -C /tmp
|
|
sudo install /tmp/go-ipfs/ipfs $ipfs_destination
|
|
|
|
echo ">>> Starting IPFS"
|
|
|
|
# Maybe initialize IPFS
|
|
[ ! -d ~/.ipfs ] && ipfs init
|
|
|
|
# Install and enable bring-up configurations for IPFS daemon
|
|
init_system=$(get_init_system)
|
|
ipfs_path=$HOME/.ipfs
|
|
ipfs_user=$(whoami)
|
|
ipfs_group=$(id -gn)
|
|
|
|
if [ $init_system == "systemd" ]; then
|
|
cat ./templates/ipfs-daemon.service.tpl | \
|
|
sed "s|{{ipfs_path}}|${ipfs_path}|g" | \
|
|
sed "s|{{ipfs_user}}|${ipfs_user}|g" | \
|
|
sed "s|{{ipfs_group}}|${ipfs_group}|g" | \
|
|
sudo tee /lib/systemd/system/ipfs-daemon.service > /dev/null
|
|
|
|
sudo systemctl daemon-reload
|
|
if [ "$mode" == "install" ]; then
|
|
sudo systemctl enable --now ipfs-daemon
|
|
elif [ "$mode" == "update" ]; then
|
|
sudo systemctl restart ipfs-daemon
|
|
fi
|
|
elif [ $init_system == "upstart" ]; then
|
|
cat ./templates/ipfs-daemon.conf.tpl | \
|
|
sed "s|{{ipfs_path}}|${ipfs_path}|g" | \
|
|
sed "s|{{ipfs_user}}|${ipfs_user}|g" | \
|
|
sudo tee /etc/init/ipfs-daemon.conf > /dev/null
|
|
|
|
sudo initctl reload-configuration
|
|
if [ "$mode" == "install" ]; then
|
|
sudo service ipfs-daemon start
|
|
elif [ "$mode" == "update" ]; then
|
|
sudo service ipfs-daemon stop
|
|
sudo service ipfs-daemon start
|
|
fi
|
|
else
|
|
echo ">>> Unable to detect init system - you don't seem to be using systemd or upstart. The IPFS daemon will have to be controlled manually."
|
|
fi
|
|
|
|
rm $tar_gz_destination
|
|
|
|
echo ">>> All done."
|