mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-10 22:31:51 +00:00
Merge 6375e37cee
into 3ac49e5ef1
This commit is contained in:
commit
2a327274db
36
install.sh
36
install.sh
@ -2,6 +2,27 @@
|
||||
|
||||
{ # this ensures the entire script is downloaded #
|
||||
|
||||
# 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
|
||||
}
|
||||
@ -305,6 +326,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
|
||||
|
Loading…
Reference in New Issue
Block a user