Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Apr 21, 2015 8:12 pm 
Offline
Senior Member

Joined: Wed Jul 21, 2010 8:04 pm
Posts: 119
Hello,
I've been banging my head against the wall trying to figure out how to fix an issue. Any help would be appreciated!

What's happening:
I have a server build script that does stuff like install/configure Nginx, Node.js, etc. When installing Node.js, the build script actually calls another shell script.

Code:
#Server build script excerpt
#Node.js
if $nodejs_enabled ; then
   sh $server/installNodejs.sh $nodejs_version
fi


Interestingly, I get different results when the server build script calls the Node.js install script, and when I call the Node.js install script myself.

When the server build script calls it, the Node.js directory isn't copied correctly. Instead of copying the entire Node.js folder into /usr/bin/local/, it copies all of the directories within the Node.js folder there. So if you were to run "ls /usr/bin/local/" you would see "bin, etc" instead of "node-v0.12.2-linux-x64".

When I run the Node.js install script myself, it works fine though.

Code:
#installNodejs.sh

#!/bin/sh

#Make sure version isn't blank
if [ "$1" = "" ] ; then
   echo "Usage: installNodejs.sh version"
   echo "Example: installNodejs.sh 0.12.2"
   exit
fi


dir="node-v$1-linux-x64"
gz="$dir.tar.gz"
symlink='/usr/local/node'

#Download Node.js binary
wget http://nodejs.org/dist/v$1/$gz

#Extract it
tar -zxf $gz

#Move it to /usr/bin/local/
sudo mv $dir/ /usr/bin/local/

#Remove old symlink
sudo rm $symlink

#Create new symlink
sudo ln -s /usr/bin/local/$dir/bin/node $symlink


I've tried:
-Removing the trailing slash
-Using cp instead of mv
-Running mv with the -v (verbose) flag. That yielded: ‘node-v0.12.2-linux-x64/’ -> ‘/usr/bin/local/’

Any ideas what might be the issue?


Top
   
PostPosted: Wed Apr 22, 2015 1:16 am 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
Reading through the script, the behavior you describe could occur as follows. If /usr/bin/local/ doesn't already exist, then sudo mv $dir/ /usr/bin/local/ will rename the extracted node-vX.XX.XX-linux-x64 directory to be /usr/bin/local rather than moving it under /usr/bin/local. Putting mkdir -p /usr/bin/local plus an appropriate chown and/or chmod before the mv command would prevent this. (Sticking a test like [ -d /usr/bin/local ] in there, and only creating the directory if it fails, would be a good idea.)

Note that /usr/local/bin, not /usr/bin/local, is the typical place where custom-built or acquired binaries are usually installed. It wouldn't be a surprise if /usr/bin/local does not already exist on most newly-installed Linux systems.

My guess is that you are running the script manually after the automatic run has already created /usr/bin/local, which is why you are seeing different behavior.

The installNodejs.sh script could also benefit from error checking at each of the steps along the way.


Top
   
PostPosted: Wed Apr 22, 2015 1:24 pm 
Offline
Senior Member

Joined: Wed Jul 21, 2010 8:04 pm
Posts: 119
That was it! Thanks so much. I owe you a beer :)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group