-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·115 lines (96 loc) · 3.54 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash -e
tag=$(basename $(/usr/bin/curl -Ls -o /dev/null -w %{url_effective} https://github.com/MRtrix3/mrtrix3/releases/latest))
if [ -z "${tag}" ]; then
echo "ERROR: could not find tag name for latest release ..."
exit
fi
if [ "$1" != "-f" ]; then
echo "This installer will download MRtrix ${tag} and install it to /usr/local/mrtrix3."
echo "In addition it will:"
echo "* create symbolic links in /usr/local/bin to the binaries in /usr/local/mrtrix3/bin"
echo "* create symbolic links in /Applications to the app bundles in /usr/local/mrtrix3/bin"
fi
if [ $EUID != 0 ]; then
echo "ERROR: This script requires root privileges, please run as: sudo "$0" "$@""
exit
fi
if [ -d "/usr/local/mrtrix3" ] || [ -L "/usr/local/mrtrix3" ] ; then
echo "WARNING: /usr/local/mrtrix3 already exists and will be replaced during installation."
fi
if [ "$1" != "-f" ]; then
while true; do
read -p "Are you sure you want to continue? [y/n] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
esac
done
fi
if [ ! -d "/usr/local/bin" ]; then
if [ -e "/usr/local/bin" ]; then
echo "WARNING: /usr/local/bin is not a directory, cannot create symlinks"
else
echo "WARNING: /usr/local/bin does not exist, creating it for you."
mkdir -p -m 755 /usr/local/bin
fi
fi
url=https://github.com/MRtrix3/mrtrix3/releases/download/${tag}/mrtrix3-macos-${tag}.tar.gz
if [ -z "${url}" ]; then
echo "ERROR: Could not find tarball of latest release ..."
exit
fi
echo "Downloading "${url}" ..."
/usr/bin/curl -sL "${url}" -O
tarball=$(basename "${url}")
if [ ! -f "${tarball}" ]; then
echo "ERROR: Download not sucessful ..."
exit
fi
if [ -f /usr/local/mrtrix3/symlinks ]; then
echo "Removing symbolic links of previous installation ..."
for l in $(cat /usr/local/mrtrix3/symlinks); do
if [ -L "${l}" ]; then
unlink "${l}"
fi
done
fi
if [ -d "/usr/local/mrtrix3" ] || [ -L "/usr/local/mrtrix3" ] ; then
echo "Removing previous installation in /usr/local/mrtrix3 ..."
rm -rf "/usr/local/mrtrix3"
fi
for l in /usr/local/bin/*; do
if [ -L "${l}" ]; then
t="$(readlink "${l}")"
if [[ "${t}" == *"mrtrix3"* ]]; then
echo "WARNING: Removing symbolic link "${l}" to "${t}" (conflicting homebrew installation?) ..."
unlink "${l}"
fi
fi
done
echo "Unpacking "${tarball}" to /usr/local/mrtrix3 ..."
tar oxf "${tarball}" -C /usr/local
rm "${tarball}"
echo "Fixing python shebang ..."
cd /usr/local/mrtrix3/bin
for f in $(grep -lr '^#!/usr/bin/env python' .); do
sed -i '' 's|^#!/usr/bin/env python$|#!/usr/bin/python3|' ${f}
done
echo "Applying patch to show correct version numbers in scripts ..."
cd /usr/local/mrtrix3
curl -s https://github.com/MRtrix3/mrtrix3/commit/4a293d30e1c0686037ae637f67932d497eb71ee6.patch | patch -s -p1
echo "Creating symlinks in /usr/local/bin ..."
cd /usr/local/bin
touch /usr/local/mrtrix3/symlinks
for target in $(find ../mrtrix3/bin -maxdepth 1 -type f ! -name "*.*"); do
ln -sf "${target}"
echo /usr/local/bin/"$(basename "${target}")" >> /usr/local/mrtrix3/symlinks
done
echo "Creating symlinks in /Applications ..."
cd /Applications
for target in /usr/local/mrtrix3/bin/*.app; do
ln -sf "${target}"
echo /Applications/"$(basename "${target}")" >> /usr/local/mrtrix3/symlinks
done
if [[ $SHELL = "/bin/zsh" ]]; then profile=~/.zprofile; else profile=~/.bash_profile; fi
echo "$PATH" | grep -q '/usr/local/bin:' || printf "WARNING: /usr/local/bin is not in PATH. You can add it to the PATH with:\necho 'export PATH=/usr/local/bin:\$PATH' >> ${profile}\n"
echo "Installation complete!"