From 1f81933fb685e5a47a0e2c1c2a08f166af865151 Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Tue, 6 Sep 2016 15:41:27 +0200 Subject: [PATCH 1/8] install.sh: Add for loop to shorten script. License: MIT Signed-off-by: Stephan Kulla --- cmd/ipfs/dist/install.sh | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/cmd/ipfs/dist/install.sh b/cmd/ipfs/dist/install.sh index d5bb19c0418..400440e2282 100755 --- a/cmd/ipfs/dist/install.sh +++ b/cmd/ipfs/dist/install.sh @@ -6,16 +6,10 @@ bin=ipfs # it merely tries two locations. # in the future maybe use value of $PATH. -binpath=/usr/local/bin -if [ -d "$binpath" ]; then - mv "$bin" "$binpath/$bin" - echo "installed $binpath/$bin" - exit 0 -fi - -binpath=/usr/bin -if [ -d "$binpath" ]; then - mv "$bin" "$binpath/$bin" - echo "installed $binpath/$bin" - exit 0 -fi +for binpath in /usr/local/bin /usr/bin; do + if [ -d "$binpath" ]; then + mv "$bin" "$binpath/$bin" + echo "installed $binpath/$bin" + exit 0 + fi +done From fc20fe870d8402e2505a7adbabb248232e38279e Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Tue, 6 Sep 2016 15:46:35 +0200 Subject: [PATCH 2/8] install.sh: Add error message at the end. License: MIT Signed-off-by: Stephan Kulla --- cmd/ipfs/dist/install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/ipfs/dist/install.sh b/cmd/ipfs/dist/install.sh index 400440e2282..8004ae4bdd9 100755 --- a/cmd/ipfs/dist/install.sh +++ b/cmd/ipfs/dist/install.sh @@ -1,15 +1,19 @@ #!/bin/sh bin=ipfs +binpaths="/usr/local/bin /usr/bin" # this script is currently brain dead. # it merely tries two locations. # in the future maybe use value of $PATH. -for binpath in /usr/local/bin /usr/bin; do +for binpath in $binpaths; do if [ -d "$binpath" ]; then mv "$bin" "$binpath/$bin" echo "installed $binpath/$bin" exit 0 fi done + +echo "cannot install $bin in one of the directories $binpaths" +exit 1 From 28a69eea10c898b7792c6e33123320f1c76b4b8f Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Wed, 7 Sep 2016 13:29:48 +0200 Subject: [PATCH 3/8] install.sh: Treat $binpath as target directory. In case $binpath/$bin is an already existing directory, the command mv "$bin" "$binpath/$bin" would store the binary in the place $binpath/$bin/$bin. I guess this is not the expected behavior. Therefore I used the -t option of `mv' to specify the target directory explicitly. License: MIT Signed-off-by: Stephan Kulla --- cmd/ipfs/dist/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ipfs/dist/install.sh b/cmd/ipfs/dist/install.sh index 8004ae4bdd9..5b4b29d0def 100755 --- a/cmd/ipfs/dist/install.sh +++ b/cmd/ipfs/dist/install.sh @@ -9,7 +9,7 @@ binpaths="/usr/local/bin /usr/bin" for binpath in $binpaths; do if [ -d "$binpath" ]; then - mv "$bin" "$binpath/$bin" + mv -t "$binpath" "$bin" echo "installed $binpath/$bin" exit 0 fi From f8458411c1b9bbcf82de479b5acb53a380b22ac5 Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Wed, 7 Sep 2016 13:39:05 +0200 Subject: [PATCH 4/8] install.sh: Check whether installation succeeds. I moved the mv command into the if-condition so that the script only succeeds when mv command ran properly. Thus, there is no need to check whether the mv command will succeed beforehand. License: MIT Signed-off-by: Stephan Kulla --- cmd/ipfs/dist/install.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/ipfs/dist/install.sh b/cmd/ipfs/dist/install.sh index 5b4b29d0def..2742fba1703 100755 --- a/cmd/ipfs/dist/install.sh +++ b/cmd/ipfs/dist/install.sh @@ -8,8 +8,7 @@ binpaths="/usr/local/bin /usr/bin" # in the future maybe use value of $PATH. for binpath in $binpaths; do - if [ -d "$binpath" ]; then - mv -t "$binpath" "$bin" + if mv -t "$binpath" "$bin" 2> /dev/null; then echo "installed $binpath/$bin" exit 0 fi From f00b8d58ec1e218fd8c4c0a74bf981513cdac42f Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Thu, 8 Sep 2016 10:03:19 +0200 Subject: [PATCH 5/8] install.sh: Make success message clearer. Implement proposal of the comment https://github.com/ipfs/go-ipfs/pull/2504#discussion_r77872959 License: MIT Signed-off-by: Stephan Kulla --- cmd/ipfs/dist/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ipfs/dist/install.sh b/cmd/ipfs/dist/install.sh index 2742fba1703..7abb5174a9b 100755 --- a/cmd/ipfs/dist/install.sh +++ b/cmd/ipfs/dist/install.sh @@ -9,7 +9,7 @@ binpaths="/usr/local/bin /usr/bin" for binpath in $binpaths; do if mv -t "$binpath" "$bin" 2> /dev/null; then - echo "installed $binpath/$bin" + echo "Moved $bin to $binpath" exit 0 fi done From 81e40de5eecfe9ea1dc569edcf3ee845a2d81d71 Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Thu, 8 Sep 2016 10:28:21 +0200 Subject: [PATCH 6/8] 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 --- cmd/ipfs/dist/install.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/ipfs/dist/install.sh b/cmd/ipfs/dist/install.sh index 7abb5174a9b..b6be3edca44 100755 --- a/cmd/ipfs/dist/install.sh +++ b/cmd/ipfs/dist/install.sh @@ -3,6 +3,10 @@ bin=ipfs binpaths="/usr/local/bin /usr/bin" +# This variable contains a nonzero length string in case the script fails +# because of missing write permissions. +is_write_perm_missing="" + # this script is currently brain dead. # it merely tries two locations. # in the future maybe use value of $PATH. @@ -11,8 +15,21 @@ for binpath in $binpaths; do if mv -t "$binpath" "$bin" 2> /dev/null; then echo "Moved $bin to $binpath" exit 0 + else + if [ -d "$binpath" -a ! -w "$binpath" ]; then + is_write_perm_missing=1 + fi fi done -echo "cannot install $bin in one of the directories $binpaths" +echo "We cannot install $bin in one of the directories $binpaths" + +if [ -n "$is_write_perm_missing" ]; then + echo "It seems that we do not have the necessary write permissions." + echo "Perhaps try running this script as a privileged user:" + echo + echo " sudo $0" + echo +fi + exit 1 From 7f194c972162bdadf3f1400c94e6597c50e4219c Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Thu, 8 Sep 2016 10:31:48 +0200 Subject: [PATCH 7/8] install.sh: Enhance comments of the script. I removed the comment about using $PATH since it leads to long installation scripts (which violates the KISS principle). Cf. the discussion on https://github.com/ipfs/go-ipfs/pull/2504 License: MIT Signed-off-by: Stephan Kulla --- cmd/ipfs/dist/install.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cmd/ipfs/dist/install.sh b/cmd/ipfs/dist/install.sh index b6be3edca44..53e5350ec83 100755 --- a/cmd/ipfs/dist/install.sh +++ b/cmd/ipfs/dist/install.sh @@ -1,4 +1,7 @@ #!/bin/sh +# +# Installation script for ipfs. It tries to move $bin in one of the +# directories stored in $binpaths. bin=ipfs binpaths="/usr/local/bin /usr/bin" @@ -7,10 +10,6 @@ binpaths="/usr/local/bin /usr/bin" # because of missing write permissions. is_write_perm_missing="" -# this script is currently brain dead. -# it merely tries two locations. -# in the future maybe use value of $PATH. - for binpath in $binpaths; do if mv -t "$binpath" "$bin" 2> /dev/null; then echo "Moved $bin to $binpath" From 465e4b9f758f62f3f46be51a18477dd020031b2d Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Thu, 8 Sep 2016 16:55:07 +0200 Subject: [PATCH 8/8] install.sh: Remove -t parameter from mv command. Return to the old definition of the mv command since there is no `-t` parameter in `mv` of BSD. Cf. https://www.freebsd.org/cgi/man.cgi?query=mv&sektion=1 License: MIT Signed-off-by: Stephan Kulla --- cmd/ipfs/dist/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ipfs/dist/install.sh b/cmd/ipfs/dist/install.sh index 53e5350ec83..fb26a3aae73 100755 --- a/cmd/ipfs/dist/install.sh +++ b/cmd/ipfs/dist/install.sh @@ -11,7 +11,7 @@ binpaths="/usr/local/bin /usr/bin" is_write_perm_missing="" for binpath in $binpaths; do - if mv -t "$binpath" "$bin" 2> /dev/null; then + if mv "$bin" "$binpath/$bin" 2> /dev/null; then echo "Moved $bin to $binpath" exit 0 else