install.sh: Recommend using sudo on error.
Show error message that the user shall try running this script with sudo in case write permissions are missing. Implement proposal of comment https://github.com/ipfs/go-ipfs/pull/3194#issuecomment-245376993 License: MIT Signed-off-by: Stephan Kulla <git.mail@kulla.me>
Stephan Kulla committed
Sep 8, 2016 at 10:28 UTC
81e40de5eecfe9ea1dc569edcf3ee845a2d81d71
1 file changed
+18
-1
cmd/ipfs/dist/install.sh
+18
-1
@@ -3,6 +3,10 @@
3
bin=ipfs
4
binpaths="/usr/local/bin /usr/bin"
5
6
+# This variable contains a nonzero length string in case the script fails
7
+# because of missing write permissions.
8
+is_write_perm_missing=""
9
+
10
# this script is currently brain dead.
11
# it merely tries two locations.
12
# in the future maybe use value of $PATH.
@@ -11,8 +15,21 @@ for binpath in $binpaths; do
15
if mv -t "$binpath" "$bin" 2> /dev/null; then
16
echo "Moved $bin to $binpath"
17
exit 0
18
+ else
19
+ if [ -d "$binpath" -a ! -w "$binpath" ]; then
20
+ is_write_perm_missing=1
21
+ fi
22
fi
23
done
24
17
-echo "cannot install $bin in one of the directories $binpaths"
25
+echo "We cannot install $bin in one of the directories $binpaths"
26
+
27
+if [ -n "$is_write_perm_missing" ]; then
28
+ echo "It seems that we do not have the necessary write permissions."
29
+ echo "Perhaps try running this script as a privileged user:"
30
+ echo
31
+ echo " sudo $0"
32
+ echo
33
+fi
34
+
35
exit 1