Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
93 lines (74 sloc)
2.71 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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." |