forked from coolaj86/node-installer.sh
merge
This commit is contained in:
commit
b562d6dd3b
64
README.md
64
README.md
|
@ -35,29 +35,75 @@ wget -nv https://bit.ly/node-installer -O - ./node-installer.sh; bash ./node-ins
|
||||||
|
|
||||||
### Choosing a specific version
|
### Choosing a specific version
|
||||||
|
|
||||||
|
**Latest**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
echo "Current node.js version is $(curl -fsSL https://nodejs.org/dist/index.tab | head -2 | tail -1 | cut -f 1)"
|
export NODEJS_VER=""
|
||||||
|
```
|
||||||
|
|
||||||
|
**Exact**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export NODEJS_VER="v10.2.1"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Latest of vX.Y.Z**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export NODEJS_VER="v8.1"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Latest of vX.YY.Z**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# latest of v8.11.x
|
||||||
|
export NODEJS_VER="v8.11"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Latest of vX.Y**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export NODEJS_VER="v10"
|
||||||
|
```
|
||||||
|
|
||||||
|
Fun FYI, here's how the latest version is determined:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NODEJS_VER=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f 1 | head -1 )
|
||||||
|
echo "The current node.js version is $NODEJS_VER"
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# To install a specific version rather than defaulting to latest
|
BASE_VER="v10\\."
|
||||||
# latest version at time of writing are v8.11.1 and v10.1.0
|
NODEJS_VER=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f 1 | grep $BASE_VER | head -1 )
|
||||||
export NODEJS_VER="v10.1.0"
|
echo "Latest node.js $BASE_VER is $NODEJS_VER"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Choosing an install location
|
### Choosing an install location
|
||||||
|
|
||||||
Just set BOTH `NODE_PATH` and `NPM_CONFIG_PREFIX`.
|
Just set BOTH `NODE_PATH` and `NPM_CONFIG_PREFIX`.
|
||||||
The install path will be the preceding `lib/node_modules`
|
The install path will be the preceding `lib/node_modules`
|
||||||
(which you usually want to be the same as `NPM_CONFIG_PREFIIX` anyway).
|
(which you usually want to be the same as `NPM_CONFIG_PREFIX` anyway).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
export NPM_CONFIG_PREFIX=/tmp/user/local
|
export NPM_CONFIG_PREFIX=/tmp/usr/local
|
||||||
export NODE_PATH=/tmp/user/local/lib/node_modules
|
export NODE_PATH=/tmp/usr/local/lib/node_modules
|
||||||
|
```
|
||||||
|
|
||||||
|
A more realistic example for a self-contained node app:
|
||||||
|
```bash
|
||||||
|
export NPM_CONFIG_PREFIX=/opt/my-app
|
||||||
|
export NODE_PATH=/opt/my-app/lib/node_modules
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
curl -fsSL https://bit.ly/node-installer -o ./node-installer.sh; bash ./node-installer.sh --dev-deps
|
curl -fsSL https://bit.ly/node-installer -o ./node-installer.sh; bash ./node-installer.sh --dev-deps
|
||||||
|
```
|
||||||
|
|
||||||
# If you want to add the install location to your PATH
|
If you want to add the install location to your `PATH`:
|
||||||
|
|
||||||
|
```bash
|
||||||
PATH=$PATH:/tmp/user/local/bin
|
PATH=$PATH:/tmp/user/local/bin
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -101,7 +147,7 @@ wget -nv https://bit.ly/node-installer -O /tmp/node-installer.sh; bash /tmp/node
|
||||||
|
|
||||||
### Other things you should know
|
### Other things you should know
|
||||||
|
|
||||||
This is what gets installed:
|
This is what gets installed with the dev dependencies:
|
||||||
|
|
||||||
* rsync
|
* rsync
|
||||||
* curl
|
* curl
|
||||||
|
|
22
install.sh
22
install.sh
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
# Not every platform has or needs sudo, gotta save them O(1)s...
|
# Not every platform has or needs sudo, gotta save them O(1)s...
|
||||||
sudo_cmd=""
|
sudo_cmd=""
|
||||||
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
|
((EUID)) && [[ -z "${ANDROID_ROOT:-}" ]] && sudo_cmd="sudo"
|
||||||
|
|
||||||
deps_flag="$1"
|
deps_flag="$1"
|
||||||
set -e
|
set -e
|
||||||
|
@ -247,12 +247,23 @@ if [ -n "${NODEJS_VER:-}" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${NODEJS_VER:-}" ]; then
|
NODEJS_VER="${NODEJS_VER:-v}" # Search for 'v' at the least
|
||||||
|
# sort -rV # will sort by version number, but it appears these are already sorted
|
||||||
|
# tail -n +2 # starts at line two (1-indexed) and all after (omits the csv header with 'version' and such)
|
||||||
|
# cut -f 1 # gets only the first column
|
||||||
|
# head -n 1 # gets only the most recent version
|
||||||
|
my_char="."
|
||||||
|
my_count=$(awk -F"${my_char}" '{print NF-1}' <<< "${NODEJS_VER}")
|
||||||
|
# get the latest version if partial
|
||||||
|
if [ $my_count -ne 2 ]; then
|
||||||
|
if [ "$NODEJS_VER" != "v" ]; then
|
||||||
|
NODEJS_VER="$NODEJS_VER\\."
|
||||||
|
fi
|
||||||
if [ -n "$(type -p curl)" ]; then
|
if [ -n "$(type -p curl)" ]; then
|
||||||
NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | head -n 2 | tail -1 | cut -f 1) \
|
NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER" | head -n 1) \
|
||||||
|| echo 'error automatically determining current node.js version'
|
|| echo 'error automatically determining current node.js version'
|
||||||
elif [ -n "$(type -p wget)" ]; then
|
elif [ -n "$(type -p wget)" ]; then
|
||||||
NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -n 2 | tail -1 | cut -f 1) \
|
NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER" | head -n 1) \
|
||||||
|| echo 'error automatically determining current node.js version'
|
|| echo 'error automatically determining current node.js version'
|
||||||
else
|
else
|
||||||
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
||||||
|
@ -286,7 +297,7 @@ if [ -e "$node_install_path/bin/node" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "node.js is already installed as node $($node_install_path/bin/node -v | grep v)"
|
echo "node.js is already installed as node $($node_install_path/bin/node -v | grep v)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "to reinstall please first run: rm $node_install_path/bin/node"
|
echo "to reinstall as ${NODEJS_VER} please first run: rm $node_install_path/bin/node"
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -297,6 +308,7 @@ if [ -n "${NODEJS_VER}" ]; then
|
||||||
bash "$my_tmp/${INSTALL_FILE}" "${NODEJS_VER}"
|
bash "$my_tmp/${INSTALL_FILE}" "${NODEJS_VER}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
mkdir -p $node_install_path/lib/node_modules || $sudo_cmd mkdir -p $node_install_path/lib/node_modules
|
||||||
chown -R $(whoami) $node_install_path/lib/node_modules || $sudo_cmd chown -R $(whoami) $node_install_path/lib/node_modules
|
chown -R $(whoami) $node_install_path/lib/node_modules || $sudo_cmd chown -R $(whoami) $node_install_path/lib/node_modules
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
Loading…
Reference in New Issue