From 736aacf4e11904b65b60e00b539c7b5515b7a3dd Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Sun, 16 Nov 2014 15:37:15 +0100 Subject: [PATCH 1/4] Introduce 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 --- install.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/install.sh b/install.sh index 8974593..5d17199 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,15 @@ #!/bin/bash +# Get this script after dereferincing all symlinks +# !! Doesn't check for circular symlinks !! +SOURCE="${BASH_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 )" + set -e nvm_has() { @@ -109,6 +119,19 @@ nvm_do_install() { exit 1 fi install_nvm_as_script + # Copies install.sh dir to installation dir + elif [ "~$METHOD" = "~copy" ]; then + local COPY=true + 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 From ed29fa9bd81f394f6683a4bf3ffeda1acfe075b1 Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Sun, 23 Nov 2014 11:33:16 +0100 Subject: [PATCH 2/4] Put symlink dereferencing loop into function for copy installation --- install.sh | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/install.sh b/install.sh index 5d17199..c034e78 100755 --- a/install.sh +++ b/install.sh @@ -1,17 +1,28 @@ #!/bin/bash -# Get this script after dereferincing all symlinks -# !! Doesn't check for circular symlinks !! -SOURCE="${BASH_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 )" - 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 +function 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 +function nvm_script_dir(){ + echo "$( dirname $(nvm_script_path))" +} + nvm_has() { type "$1" > /dev/null 2>&1 return $? @@ -122,6 +133,7 @@ nvm_do_install() { # Copies install.sh dir to installation dir elif [ "~$METHOD" = "~copy" ]; then local COPY=true + DIR=`nvm_script_dir` if [ $DIR = $NVM_DIR ]; then echo "=> install.sh is already in $NVM_DIR" COPY=false From 8839515af3c16da6656fe1937826ffa0ce401061 Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Sun, 23 Nov 2014 11:34:16 +0100 Subject: [PATCH 3/4] Keep creation of local var consistent definition on one line initialization on another --- install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index c034e78..f46a3d0 100755 --- a/install.sh +++ b/install.sh @@ -132,7 +132,8 @@ nvm_do_install() { install_nvm_as_script # Copies install.sh dir to installation dir elif [ "~$METHOD" = "~copy" ]; then - local COPY=true + local COPY + COPY=true DIR=`nvm_script_dir` if [ $DIR = $NVM_DIR ]; then echo "=> install.sh is already in $NVM_DIR" From 6375e37ceeff55e0436fddb99329e3bc5dada333 Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Sun, 23 Nov 2014 12:05:38 +0100 Subject: [PATCH 4/4] Remove 'function' to define functions /bin/sh doesn't like it... --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index f46a3d0..6bebf3d 100755 --- a/install.sh +++ b/install.sh @@ -6,7 +6,7 @@ set -e # Get's the path of the current script calling the function # !! Doesn't check for circular symlinks !! # e.g /tmp/path/to/script.sh -function nvm_script_path(){ +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 )" @@ -19,7 +19,7 @@ function nvm_script_path(){ } # Get the directory of the current script -function nvm_script_dir(){ +nvm_script_dir(){ echo "$( dirname $(nvm_script_path))" }