exit value doesn't reflect error if script failed to install specified version #117

Closed
brycebaril opened this Issue May 25, 2013 · 2 comments

Comments

Projects
None yet
3 participants

When running as a user that doesn't have permission to install to the system, n doesn't check interim error states and continues to work despite not getting anywhere, finally resulting in a shell exit status of success, even though it failed.

Obviously this could be avoided by changing perms on /usr/local or running as sudo, but it would be nice to be able to check output of n in a script, and possibly have n abort earlier (e.g. at the first failed mkdir in the output below)

vagrant@vagrant-ubuntu-raring-64:/vagrant$ n 0.10.5

     install : 0.10.5
       mkdir : /usr/local/n/versions/0.10.5
mkdir: cannot create directory ‘/usr/local/n/versions/0.10.5’: Permission denied
/usr/local/bin/n: 283: cd: can't cd to /usr/local/n/versions/0.10.5
       fetch : http://nodejs.org/dist/v0.10.5/node-v0.10.5-linux-x64.tar.gz
######################################################################## 100.0%
tar: bin/npm: Cannot create symlink to `../lib/node_modules/npm/bin/npm-cli.js': Read-only file system
/usr/local/bin/node
/usr/local/bin/n: 244: /usr/local/bin/n: cannot create /usr/local/n/versions/.prev: Permission denied
cp: cannot stat ‘/usr/local/n/versions/0.10.5/*’: No such file or directory
   installed : v0.8.23

vagrant@vagrant-ubuntu-raring-64:/vagrant$ echo $?
0
Contributor

jbnicolai commented Jul 6, 2014

This has been fixed by now, see L309

tree 7cd83b6a81eb30b73a16a5a25f8d13a01db87a5a
parent eb86f767c8fb403fd0819b3ab241f0e64f3df9a5
author Yazhong Liu <yorkiefixer@gmail.com> Fri Jan 3 10:46:36 2014 +0800
committer Yazhong Liu <yorkiefixer@gmail.com> Fri Jan 3 10:46:36 2014 +0800
encoding

handle `Permission denied` for `mkdir`


diff --git a/bin/n b/bin/n
index a7823d0..a48a3bf 100755
--- a/bin/n
+++ b/bin/n
@@ -304,6 +304,10 @@ install_node() {

   log mkdir $dir
   mkdir -p $dir
+  if [ $? -ne 0 ] ; then
+    abort "sudo required"
+  fi
+
Contributor

jbnicolai commented Jul 6, 2014

@tjwebb could you close this issue?

@tedgaydos tedgaydos closed this May 15, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment