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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

set -e

# Adapted from stackoverflow: https://stackoverflow.com/a/246128
# Get's the path of the current script calling the function
# !! Doesn't check for circular symlinks !!
# e.g /tmp/path/to/script.sh
nvm_script_path(){
SOURCE=$0
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
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 )"
FILENAME=`basename $SOURCE`
echo $DIR/$FILENAME
}

# Get the directory of the current script
nvm_script_dir(){
echo "$( dirname $(nvm_script_path))"
}

nvm_has() {
type "$1" > /dev/null 2>&1
return $?
Expand Down Expand Up @@ -109,6 +130,21 @@ nvm_do_install() {
exit 1
fi
install_nvm_as_script
# Copies install.sh dir to installation dir
elif [ "~$METHOD" = "~copy" ]; then
local COPY
COPY=true
DIR=`nvm_script_dir`
if [ $DIR = $NVM_DIR ]; then
echo "=> install.sh is already in $NVM_DIR"
COPY=false
elif [ -d $NVM_DIR ]; then
echo "=> $NVM_DIR already exists and its contents will be replaced"
fi
mkdir -p $NVM_DIR
if $COPY; then
cp -R $DIR/* $NVM_DIR
fi
fi

echo
Expand Down