-
Notifications
You must be signed in to change notification settings - Fork 32
/
install
executable file
·93 lines (74 loc) · 2.71 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/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."