Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce copy METHOD for installation #580

Closed
wants to merge 4 commits into from
Closed

Introduce copy METHOD for installation #580

wants to merge 4 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Nov 16, 2014

This method copies the folder containing install.sh (normally also containing the repo) to - unless of course the install.sh being executed is in (where nvm was installed)

This is useful for vagrant to test local changes instead of pulling them from git and thus testing what's on the server and not local changes

As requested, here is a seperate PR for the copy method for installation.

This method copies the folder containing install.sh (normally also containing the repo) to  - unless of course the install.sh being executed is in  (where nvm was installed)

This is useful for vagrant to test local changes instead of pulling them from git and thus testing what's on the server and not local changes
@ljharb
Copy link
Member

ljharb commented Nov 17, 2014

Why can't this just use git and $NVM_SOURCE to pull from a git repo already locally located on the machine?

@ghost
Copy link
Author

ghost commented Nov 17, 2014

I didn't notice NVM_SOURCE, but in any case this PR was split (as requested) from the vagrant PR. I used it to install (copy) my working directory into the virtual machine. "git clone" wouldn't have my changes or even the stashed changes.

@ljharb
Copy link
Member

ljharb commented Nov 17, 2014

It would if they were committed to the local repo. I'm not sure I understand the use case here, and I'm hesitant to add new functionality that doesn't seem to offer anything over what's already here.

@ghost
Copy link
Author

ghost commented Nov 17, 2014

I'm not sure what the normal workflow is, but before I commit I try to make things work. Without the copy installation one would have to make changes, commit, test in the VM and if it doesn't work, revert and restart the cycle. With the copy method, you make a change and test in the VM.

SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain again why this above block of code is needed?

If needed, can it be put into a function? Is there nothing built into the shell for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just to "cover our bases" when getting the location of install.sh. Without dereferencing, if the script were linked somewhere, it would get the location of the linked script, not the "true" source.

I was thinking about putting it into a function, but I haven't tested that yet. Might be possible.

Didn't find a builtin, that does that. What you see here is from a stackoverflow response. Maybe I should attribute the author?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a bit on the problems that would be caused by getting the location of the linked script versus the non-linked path? It seems like the presence of the link shouldn't affect the copy - ie, it would still work with the linked path.

A comment with a link to the SO answer would indeed be helpful. Using a function makes it very clear that the sole purpose is to output a directory path and that you're not intending to rely on other side effects :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assume we have this scenario. Internal company nvm version with customizations.

root@localhost:~> cd /opt
root@localhost:/opt> git clone git@github.com:LoveIsGrief/nvm.git nvm # or git clone https://github.com/creationix/nvm.git
root@localhost:/opt> ln -s /opt/nvm/install.sh /usr/local/bin/nvm_install
user@localhost:~> nvm_install # Without symlink deref = cp /usr/local/bin $NVM_DIR
user@localhost:~> nvm_install # With symlink deref = cp /opt/nvm/ $NVM_DIR

It seems like the presence of the link shouldn't affect the copy - ie, it would still work with the linked path.

Hmm... do you mean something like this?

> # Folders:
> find -name install.sh -exec ls -l "{}" \;
lrwxrwxrwx 1 ubuntu ubuntu 21 nov.  23 12:02 ./old_nvm/install.sh -> ../new_nvm/install.sh
-rw-rw-r-- 1 ubuntu ubuntu 0 nov.  23 11:59 ./new_nvm/install.sh
> cd old_nvm && ./install.sh # Still installs new nvm

Is that your concern?

@ljharb
Copy link
Member

ljharb commented Nov 20, 2014

ok, i think i can get behind the development use case here. The symlink stuff concerns me. Splitting this PR even further (ie, "copy" first, "symlink handling" later) might be a good idea too?

@ghost
Copy link
Author

ghost commented Nov 23, 2014

I believe this PR would be incomplete with the symlink stuff. I'm not even sure how it would be split.
A PR with just the symlink loop in the install.sh wouldn't be used. If it were, it would be dependent of this PR.

/bin/sh doesn't like it...
@ljharb
Copy link
Member

ljharb commented Nov 23, 2014

Sorry if I'm not getting this - what does this PR achieve that cp -rf $OLD_NVM_DIR $NEW_NVM_DIR && . $NEW_NVM_DIR/install.sh does not?

@ghost
Copy link
Author

ghost commented Nov 23, 2014

Your same question could be asked, were there an install.sh that just did the post-install stuff (profiles) and somebody added the git or wget method. They too could be one-liners e.g git clone <repo> $NVM_DIR || cd $NVM_DIR && git fetch && . $NVM_DIR/install.sh.

So, I'm not really sure how to respond to that. This adds exactly that option under the hood - just like the option is given to use git or wget.

It was originally in the vagrant PR and I could have written all that in the provisioning script, but figured it could also be useful as an install option.

@ljharb
Copy link
Member

ljharb commented Nov 23, 2014

Sure, I'm just trying to make sure I understand it fully. The need to dereference symlinks worries me. The reason curl/wget and git are options is because URLs and a series of commands are difficult to remember and easy to get wrong - a single copy command and a single install script isn't particularly difficult, and I'm still not sure it warrants being added as an install option.

Thanks for being responsive on this; I'll continue thinking about it.

@ghost
Copy link
Author

ghost commented Nov 24, 2014

No problem :) Your code review is pretty thorough.
If you have any other questions, I hope I'll be able to provide satisfying answers.

Cheers

@ljharb ljharb added the feature requests I want a new feature in nvm! label Jul 3, 2015
@ghost ghost closed this Jul 1, 2017
@ghost ghost deleted the install_copy branch July 1, 2017 14:14
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature requests I want a new feature in nvm!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant