Compare commits

..

1 Commits

Author SHA1 Message Date
Sergio Crisostomo 5379b3b577 add nginx, forever and clone app from github 2015-12-07 22:26:22 +01:00
11 changed files with 406 additions and 811 deletions

164
README.md
View File

@ -1,144 +1,52 @@
# Easy Install node.js
node-install-script
===================
| Sponsored by [ppl](https://ppl.family) |
A script to install basic development tools for node (git, node, gcc, etc)
Simple node.js installer for macOS and Linux
## QuickStart
Works for any recent version of Ubuntu or OS X.
```bash
curl -fsL bit.ly/node-installer | bash
# Specify the version of node to install
echo "v4.2.3" > /tmp/NODE_VER
# Specify the Github url of your app
echo "https://github.com/<user>/<project>" > /tmp/APP_URL
# And install away!
curl -fsSL bit.ly/easy-install-node | bash
```
*Note*: [bit.ly/node-installer](https://bit.ly/node-installer) is a redirect to <https://git.coolaj86.com/coolaj86/node-installer.sh/raw/master/install.sh>
## Screencast
[How to Setup a VPS for node.js Development](https://www.youtube.com/watch?v=ypjzi1axH2A) - [(3:06 installing node.js](https://www.youtube.com/watch?v=ypjzi1axH2A#t=186))
## Installer Options
* [x] version
* [x] install location
* [x] tools for building native modules
### Choose Version
The latest version of node is installed by default.
You can choose a specific version by defining `NODE_VERSION` in the format `vX`, `vX.Y`, or `v.X.Y.Z`:
**For older versions of Ubuntu**:
```bash
NODE_VERSION=v10
wget -nv bit.ly/easy-install-node -O - | bash
```
Usage:
This is what gets installed:
```bash
export NODE_VERSION=v10.10
curl -fsSL https://bit.ly/node-installer | bash
```
* fail2ban (not necessary for development, but should be on every server)
* rsync
* curl
* wget
* git
* xcode / brew / build-essential / pkg-config / gcc
* node
* jshint
* nginx
* forever
### Location
Screencast
==========
By default node will be installed to `/usr/local`, without root if possible.
[How to Setup a VPS for Node.js Development](https://www.youtube.com/watch?v=ypjzi1axH2A) - [(3:06 installing node](https://www.youtube.com/watch?v=ypjzi1axH2A#t=186))
You can choose a specific location by setting **both** `NPM_CONFIG_PREFIX` **and** `NODE_PATH`:
Front-End Extras
================
```bash
export NPM_CONFIG_PREFIX=$HOME/.local
export NODE_PATH=$NPM_CONFIG_PREFIX/lib/node_modules
curl -fsSL https://bit.ly/node-installer | bash
```
These are **not installed**, but you may wish to use them if you're doing front-end work as well
If you want to add the install location to your `PATH`, add `/bin` to the custom location used above and append it like so:
```bash
PATH=$PATH:$HOME/.local/bin
```
### Development Tools
If you plan on building or creating native node modules, you'll want to install `gcc`, `pgk-config`, and a few other required tools and niceties.
In fact, it's fairly common for modules to have both native module and pure js dependencies, so you'll probably want (or need) to install these even if you don't plan to use them directly.
* [x] curl & wget
* [x] git
* [x] rsync
* [x] xcode, brew (on macOS), build-essential (Linux)
* [x] gcc, pkg-config
* [x] pkg-config
* [x] node.js, jshint
Pass `--dev-deps` to the installer script and it will use either `brew` (on macOS) or `apt` (on Linux) to install the development tools.
```bash
curl -fsSL https://bit.ly/node-installer | bash -s -- --dev-deps
```
Or, if you don't have `curl` installed yet you can use `wget`:
```bash
wget -nv https://bit.ly/node-installer -O - | bash -s -- --dev-deps
```
### Securing your server
If you're running a node.js server on anything with a public ip address
(an "edge" server), I'd highly recommend that you also install `fail2ban` to secure ssh -
especially if you haven't switched your server to use key-only authentication (which you should also do).
See [The 15-Minute Guide to Secure VPS Access (for the Semi-Paranoid)](https://www.youtube.com/watch?v=YZzhIIJmlE0)
## Notes
* [OS X](#apple-os-x)
* [Ubuntu Linux](#ubuntu-linux)
* [Important Notes](#other-things-you-should-know)
### Apple OS X
First you need to **Install XCode Command Line Tools**
```bash
xcode-select --install
```
Then you need to **Accept the XCode License** by running any command installed by Xcode with sudo. We'll use git.
```bash
sudo git --version
```
You can scroll to the bottom by hitting shift+G (capital G).
Type `agree` and hit enter to accept the license.
Now you can install node.js
```bash
curl -fsSL https://bit.ly/node-installer -o /tmp/node-installer.sh; bash /tmp/node-installer.sh --dev-deps
```
*TODO*: Make it easier to accepting the license (automatic?)
### Ubuntu Linux
```bash
wget -nv https://bit.ly/node-installer -O /tmp/node-installer.sh; bash /tmp/node-installer.sh --dev-deps
```
### Automatic Version Detection
Fun FYI, here's how the latest version is determined:
```bash
NODE_VERSION=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f 1 | head -1 )
echo "The current node.js version is $NODE_VERSION"
```
```bash
BASE_VER="v10\\."
NODE_VERSION=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f 1 | grep $BASE_VER | head -1 )
echo "Latest node.js $BASE_VER is $NODE_VERSION"
```
* bower
* uglifyjs
* yo
* jade
* less

View File

@ -0,0 +1,80 @@
#!/bin/bash
#
# description: DevShelf service
# processname: node
# pidfile: /var/run/devshelf.pid
# logfile: /var/log/devshelf.log
#
# Based on https://gist.github.com/jinze/3748766
#
# To use it as service on Ubuntu:
# sudo cp devshelf.sh /etc/init.d/devshelf
# sudo chmod a+x /etc/init.d/devshelf
# sudo update-rc.d devshelf defaults
#
# Then use commands:
# service devshelf <command (start|stop|etc)>
NAME=devshelf # Unique name for the application
SOUREC_DIR=/home/node-app # Location of the application source
COMMAND=node # Command to run
SOURCE_NAME=index.js # Name os the applcation entry point script
USER=root # User for process running
NODE_ENVIROMENT=production # Node environment
pidfile=/var/run/$NAME.pid
logfile=/var/log/$NAME.log
forever=forever
start() {
export NODE_ENV=$NODE_ENVIROMENT
echo "Starting $NAME node instance : "
touch $logfile
chown $USER $logfile
touch $pidfile
chown $USER $pidfile
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo -H -u $USER $forever start --pidFile $pidfile -l $logfile -a --sourceDir $SOUREC_DIR -c $COMMAND $SOUREC_DIR/$SOURCE_NAME
RETVAL=$?
}
restart() {
echo -n "Restarting $NAME node instance : "
sudo -H -u $USER $forever restart $SOUREC_DIR/$SOURCE_NAME
RETVAL=$?
}
status() {
echo "Status for $NAME:"
sudo -H -u $USER $forever list
RETVAL=$?
}
stop() {
echo -n "Shutting down $NAME node instance : "
sudo -H -u $USER $forever stop $SOUREC_DIR/$SOURCE_NAME
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit $RETVAL

31
config-files/nginx-config Normal file
View File

@ -0,0 +1,31 @@
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
upstream project {
server localhost:3000;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
proxy_pass http://project;
}
}

View File

@ -1,400 +0,0 @@
#!/bin/bash
# Installs node.js only (no development dependencies) for both Ubuntu and OS X
#
# See https://git.coolaj86.com/coolaj86/node-installer.sh
#
# curl -fsSL bit.ly/nodejs-min | bash
# wget -nv bit.ly/nodejs-min -O - | bash
# curl -fsSL https://example.com/setup-min.bash | bash
# wget -nv https://example.com/setup-min.bash -O - | bash
# Not every platform has or needs sudo, gotta save them O(1)s...
sudo_cmd=""
((EUID)) && [[ -z "${ANDROID_ROOT:-}" ]] && sudo_cmd="sudo"
deps_flag="$1"
set -e
set -u
#set -o pipefail
if [ -z "${PREFIX-}" ]; then
PREFIX=""
fi
NODEJS_NAME="node"
NODEJS_BASE_URL="https://nodejs.org"
BASE_URL="https://git.coolaj86.com/coolaj86/node-installer.sh/raw/master"
#NO_FAIL2BAN=""
NO_FAIL2BAN="nope"
OS="unsupported"
ARCH=""
SETUP_FILE=""
my_tmp="$(mktemp -d -t node-installer.XXXXXXXX)"
export my_tmp
clear
#########################
# Which OS and version? #
#########################
if [ "$(uname | grep -i 'Darwin')" ]; then
OSX_VER="$(sw_vers | grep ProductVersion | cut -d':' -f2 | cut -f2)"
OSX_MAJOR="$(echo ${OSX_VER} | cut -d'.' -f1)"
OSX_MINOR="$(echo ${OSX_VER} | cut -d'.' -f2)"
OSX_PATCH="$(echo ${OSX_VER} | cut -d'.' -f3)"
#
# Major
#
if [ "$OSX_MAJOR" -lt 10 ]; then
echo "unsupported OS X version (os 9-)"
exit 1
fi
if [ "$OSX_MAJOR" -gt 10 ]; then
echo "unsupported OS X version (os 11+)"
exit 1
fi
#
# Minor
#
if [ "$OSX_MINOR" -le 5 ]; then
echo "unsupported OS X version (os 10.5-)"
exit 1
fi
# Snow
if [ "$OSX_MINOR" -eq 6 ]; then
OS='snow'
fi
# Lion
if [ $OSX_MINOR -eq 7 ]; then
OS='lion'
fi
# Mountain Lion
if [ "$OSX_MINOR" -eq 8 ]; then
OS='mountain'
fi
# Mavericks, Yosemite
if [ "$OSX_MINOR" -ge 9 ]; then
OS='mavericks'
fi
if [ -n "$(sysctl hw | grep 64bit | grep ': 1')" ]; then
ARCH="64"
else
ARCH="32"
fi
elif [ "$(uname | grep -i 'Linux')" ]; then
if [ ! -f "/etc/issue" ]; then
echo "unsupported linux os"
exit 1
fi
if [ -n "$(uname -a | grep 64)" ]; then
ARCH="64"
else
ARCH="32"
fi
if [ "$(cat /etc/issue | grep -i 'Ubuntu')" ]; then
OS='ubuntu'
elif [ "$(cat /etc/issue | grep -i 'Linux Mint')" ]; then
OS='ubuntu'
elif [ "$(cat /etc/issue | grep -i 'elementary OS')" ]; then
OS='ubuntu'
elif [ "$(cat /etc/issue | grep -i 'Arch ')" ]; then
OS='ubuntu'
elif [ "$(cat /etc/issue | grep -i 'Debian')" ]; then
OS='ubuntu'
elif [ "$(cat /etc/issue | grep -i 'Trisquel')" ]; then
OS='ubuntu'
elif [ "$(cat /etc/issue | grep -i 'Zorin')" ]; then
OS='ubuntu'
elif [ "$(cat /etc/issue | grep -i 'Raspbian')" ]; then
OS='raspbian'
elif [ "$(cat /etc/issue | grep -i 'Fedora')" ]; then
OS='ubuntu'
elif [ "$(cat /etc/issue | grep -i 'Marvell')" ]; then
OS='marvell'
else
OS='ubuntu'
fi
else
echo "unsupported unknown os (non-mac, non-linux)"
exit 500
fi
case "${OS}" in
fedora)
echo "FEDORA not yet supported (feel free to pull request)"
exit 1
;;
ubuntu)
SETUP_FILE="ubuntu"
;;
raspbian)
SETUP_FILE="ubuntu"
;;
marvell)
SETUP_FILE="ubuntu"
;;
yosemite)
# mavericks
SETUP_FILE="mavericks"
;;
mavericks)
SETUP_FILE="mavericks"
;;
mountain)
echo "Mountain Lion not yet supported (feel free to pull request)"
exit 1
;;
lion)
echo "Lion not yet supported (feel free to pull request)"
exit 1
;;
snow)
echo "Snow Leopard not yet supported (feel free to pull request)"
exit 1
;;
*)
echo "unsupported unknown os ${OS}"
exit 1
;;
esac
#######################
# Download installers #
#######################
if [ "--dev-deps" == "$deps_flag" ]; then
echo "Preparing to install node.js (and common development dependencies) for ${OS}" "${ARCH}"
else
echo "Preparing to install node.js (minimal) for ${OS}" "${ARCH}"
fi
INSTALL_DEPS_FILE="setup-deps-${SETUP_FILE}.bash"
INSTALL_FILE="setup-node-${SETUP_FILE}.bash"
if [ ! -e "$my_tmp/${INSTALL_FILE}" ]; then
if [ -n "$(type -p curl)" ]; then
curl --silent -L "${BASE_URL}/${INSTALL_FILE}" \
-o "$my_tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
elif [ -n "$(type -p wget)" ]; then
wget --quiet "${BASE_URL}/${INSTALL_FILE}" \
-O "$my_tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
else
echo "Found neither 'curl' nor 'wget'. Can't Continue."
exit 1
fi
fi
if [ "--dev-deps" == "$deps_flag" ]; then
if [ ! -e "$my_tmp/${INSTALL_DEPS_FILE}" ]; then
if [ -n "$(type -p curl)" ]; then
curl --silent -L "${BASE_URL}/${INSTALL_DEPS_FILE}" \
-o "$my_tmp/${INSTALL_DEPS_FILE}" || echo 'error downloading os deps script: '"${BASE_URL}/${INSTALL_DEPS_FILE}"
elif [ -n "$(type -p wget)" ]; then
wget --quiet "${BASE_URL}/${INSTALL_DEPS_FILE}" \
-O "$my_tmp/${INSTALL_DEPS_FILE}" || echo 'error downloading os deps script: '"${BASE_URL}/${INSTALL_DEPS_FILE}"
else
echo "Found neither 'curl' nor 'wget'. Can't Continue."
exit 1
fi
fi
fi
if [ ! -e "$my_tmp/${INSTALL_FILE}" ]
then
echo "Error Downloading Install File"
exit 1
fi
if [ "--dev-deps" == "$deps_flag" ]; then
if [ ! -e "$my_tmp/${INSTALL_DEPS_FILE}" ]
then
echo "Error Downloading Deps File"
exit 1
fi
fi
#########################
# Which node.js VERSION ? #
#########################
NODE_VERSION=${NODE_VERSION:-}
NODEJS_VER=${NODEJS_VER:-}
if [ -n "$NODE_VERSION" ]; then
NODEJS_VER=$NODE_VERSION
fi
if [ -z "${NODEJS_VER:-}" ]; then
# For backwards compat
if [ -f "$my_tmp/NODEJS_VER" ]; then
NODEJS_VER=$(cat $my_tmp/NODEJS_VER | grep v)
elif [ -f "/tmp/IOJS_VER" ]; then
NODEJS_VER=$(cat $my_tmp/IOJS_VER | grep v)
fi
fi
if [ -n "${NODEJS_VER:-}" ]; then
NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1)
if [ $NODEJS_VERT -ge 1 ] && [ $NODEJS_VERT -lt 4 ]
then
echo "Selecting io.js instead of node.js for this version (>= 1.0.0 < 4.0.0)"
NODEJS_BASE_URL="https://iojs.org"
NODEJS_NAME="iojs"
fi
fi
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
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'
elif [ -n "$(type -p wget)" ]; then
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'
else
echo "Found neither 'curl' nor 'wget'. Can't Continue."
exit 1
fi
fi
#
# node
#
if [ -z "${NODE_PATH-}" ]; then
if [ -n "$(type -p node | grep node 2>/dev/null)" ]; then
# /usr/local/bin/node => /usr/local
node_install_path="$(dirname $(dirname $(type -p node)))"
echo "NODE_PATH is not set. Using existing node install path: '$node_install_path'"
if ! echo "test" > $node_install_path/.test
then
echo "Node install path is not writable. Run: NODE_PATH=$HOME/.local/opt/node/lib/node_modules"
if [ -f "$node_install_path"/.test ]; then
rm "$node_install_path"/.test
fi
fi
else
node_install_path=$PREFIX/usr/local
echo "NODE_PATH is not set. Using default install path '$node_install_path'"
if ! echo "test" > $node_install_path/.test
then
echo "Node install path is not writable. Run: NODE_PATH=$HOME/.local/opt/node/lib/node_modules"
if [ -f "$node_install_path"/.test ]; then
rm "$node_install_path"/.test
fi
fi
fi
else
node_install_path=$(dirname $(dirname $NODE_PATH))
echo "NODE_PATH is '$NODE_PATH', so install path is '$node_install_path'"
fi
if [ -e "$node_install_path/bin/node" ]; then
# node of some version is already installed
if [ "${NODEJS_VER}" == "$($node_install_path/bin/node -v 2>/dev/null)" ]; then
echo node ${NODEJS_VER} is already installed
exit 0
else
echo ""
echo "HEY, LISTEN:"
echo ""
echo "node.js is already installed as node $($node_install_path/bin/node -v | grep v)"
echo ""
echo "to reinstall as ${NODEJS_VER} please first run: rm $node_install_path/bin/node"
echo ""
exit 1
fi
NODEJS_VER=""
fi
if [ -n "${NODEJS_VER}" ]; then
bash "$my_tmp/${INSTALL_FILE}" "${NODEJS_VER}"
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
echo ""
if [ "--dev-deps" == "$deps_flag" ]; then
################
# DEPENDENCIES #
################
#if [ -z "$(which fail2ban-server | grep fail2ban)" ]; then
# echo ""
# echo "Your server didn't come with fail2ban preinstalled!!!"
# echo "Among other things, fail2ban secures ssh so that your server isn't reaped by botnets."
# echo ""
# echo "Since you're obviously connecting this computer to a network, you should install fail2ban before continuing"
# echo ""
# echo "Install fail2ban? [Y/n]"
# echo "(if unsure, just hit [enter])"
# read INSTALL_FAIL2BAN
#
# if [ "n" == "${INSTALL_FAIL2BAN}" ] || [ "no" == "${INSTALL_FAIL2BAN}" ] || [ "N" == "${INSTALL_FAIL2BAN}" ] || [ "NO" == "${INSTALL_FAIL2BAN}" ]; then
# echo ""
# echo "I don't think you understand: This is important."
# echo ""
# echo "Your server will be under constant attack by botnets via ssh."
# echo "It only takes a few extra seconds to install and the defaults are adequate for protecting you."
# echo ""
# echo "Change your mind?"
# echo "Ready to install fail2ban? [Y/n]"
# read INSTALL_FAIL2BAN
# if [ "n" == "${INSTALL_FAIL2BAN}" ] || [ "no" == "${INSTALL_FAIL2BAN}" ] || [ "N" == "${INSTALL_FAIL2BAN}" ] || [ "NO" == "${INSTALL_FAIL2BAN}" ]; then
# clear
# echo "you make me sad :-("
# sleep 0.5
# echo "but whatever, it's your funeral..."
# sleep 1
# NO_FAIL2BAN="nope"
# else
# echo "Phew, dodged the bullet on that one... Will install fail2ban.. :-)"
# fi
# fi
#fi
bash "$my_tmp/${INSTALL_DEPS_FILE}" "${NO_FAIL2BAN}"
# yarn
#if [ -z "$(type -p yarn)" ]; then
# echo "installing yarn..."
# npm install --silent yarn -g > /dev/null
#fi
# jshint
if [ -z "$(type -p jshint)" ]; then
echo "installing jshint..."
#yarn global add jshint > /dev/null
$node_install_path/bin/npm install -g jshint > /dev/null
fi
echo ""
fi
rm -rf "$my_tmp"

View File

@ -1,40 +0,0 @@
#!/bin/bash
# curl -fsSL https://ldsconnect.org/setup-linux.bash | bash -c
# Not every platform has or needs sudo, gotta save them O(1)s...
sudo_cmd=""
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
NO_FAIL2BAN=${1}
echo ""
echo ""
echo "Checking for"
echo ""
echo " * build-essential"
echo " * rsync"
echo " * wget"
echo " * curl"
echo " * pkg-config"
echo " * node"
echo " * jshint"
echo ""
echo "updating apt-get..."
$sudo_cmd bash -c "apt-get update -qq -y < /dev/null" > /dev/null
# fail2ban
#if [ -z "$(which fail2ban-server | grep fail2ban)" ]; then
# if [ -z "${NO_FAIL2BAN}" ]; then
# echo "installing fail2ban..."
# sudo bash -c "apt-get install -qq -y fail2ban < /dev/null" > /dev/null
# fi
#fi
# git, wget, curl, build-essential
if [ -z "$(type -p pkg-config)" ] || [ -z "$(type -p git)" ] || [ -z "$(type -p wget)" ] || [ -z "$(type -p curl)" ] || [ -z "$(type -p gcc)" ] || [ -z "$(type -p rsync)" ] || [ -z "$(type -p python)" ]
then
echo "installing git, wget, curl, build-essential, rsync, pkg-config, python..."
$sudo_cmd bash -c "apt-get install -qq -y git wget curl build-essential rsync pkg-config python < /dev/null" > /dev/null 2>/dev/null
fi

View File

@ -1,18 +1,10 @@
#!/bin/bash
# curl -fsSL https://ldsconnect.org/setup-osx.bash | bash -c
NO_FAIL2BAN=${1}
NODE_VER=${1}
echo ""
echo ""
echo "Checking for"
echo ""
echo " * XCode Command Line Tools"
echo " * wget"
echo " * pkg-config"
echo " * node"
echo " * jshint"
echo ""
# XCode
# testing for which git, gcc, etc will not work because the tools are aliased to the install script
@ -31,13 +23,6 @@ if [ -z "$(xcode-select --print-path 2>/dev/null)" ] || [ -z "$(git --version 2>
while true; do
sleep 5
if [ -n "$(xcode-select --print-path 2>/dev/null)" ]; then
# Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
echo "Now running 'sudo xcodebuild -license' so that you can accept the license agreement"
sudo xcodebuild -license
fi
# http://stackoverflow.com/questions/15371925/how-to-check-if-command-line-tools-is-installed
if [ -n "$(git --version 2>/dev/null)" ] && [ -n "$(xcode-select --print-path 2>/dev/null)" ]; then
break;
fi
@ -46,6 +31,8 @@ if [ -z "$(xcode-select --print-path 2>/dev/null)" ] || [ -z "$(git --version 2>
echo "It looks like the other install is finishing up."
echo "This installation will begin in one minute."
sleep 60
else
echo "XCode Command Line Tools already installed"
fi
# homebrew
@ -61,18 +48,46 @@ fi
if [ -z "$(which wget | grep wget)" ]; then
echo "installing wget..."
brew install wget
else
echo "wget already installed"
fi
# http://www.fail2ban.org/wiki/index.php/HOWTO_Mac_OS_X_Server_(10.5)
#if [ -z "$(which fail2ban-server | grep fail2ban)" ]; then
# if [ -z "${NO_FAIL2BAN}" ]; then
# brew install fail2ban
# sudo cp -fv /usr/local/opt/fail2ban/*.plist /Library/LaunchDaemons
# sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.fail2ban.plist
# fi
#fi
if [ -z "$(which fail2ban-server | grep fail2ban)" ]; then
echo "installing fail2ban..."
brew install fail2ban
sudo cp -fv /usr/local/opt/fail2ban/*.plist /Library/LaunchDaemons
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.fail2ban.plist
else
echo "fail2ban already installed"
fi
if [ -z "$(which pkg-config | grep pkg-config)" ]; then
echo "installing pkg-config..."
brew install pkg-config
else
echo "pkg-config already installed"
fi
# node
if [ -n "$(which node | grep node 2>/dev/null)" ]; then
NODE_VER=""
if [ "${NODE_VER}" == "$(node -v 2>/dev/null)" ]; then
echo node ${NODE_VER} already installed
else
echo ""
echo "HEY, LISTEN:"
echo "node is already installed as $(node -v | grep v)"
echo ""
echo "to reinstall please first run: rm $(which node)"
echo ""
fi
fi
if [ -n "${NODE_VER}" ]; then
echo "installing node ${NODE_VER}..."
curl -fsSL "http://nodejs.org/dist/${NODE_VER}/node-${NODE_VER}.pkg" -o "/tmp/node-${NODE_VER}.pkg"
sudo /usr/sbin/installer -pkg "/tmp/node-${NODE_VER}.pkg" -target /
sudo chown -R $(whoami) /usr/local 2>/dev/null
fi

View File

@ -1,44 +0,0 @@
#!/bin/bash
# Installs node.js + dependencies for both Ubuntu and OS X
#
# See https://git.colaj86.com/coolaj86/node-installer.sh
#
# curl -fsSL https://example.com/setup.bash | bash
# wget -nv https://example.com/setup.bash -O - | bash
set -e
set -u
BASE_URL="https://git.coolaj86.com/coolaj86/node-installer.sh/raw/master"
#######################
# Download installers #
#######################
INSTALL_FILE_REMOTE="install.sh"
INSTALL_FILE="node-installer.sh"
if [ ! -e "/tmp/${INSTALL_FILE}" ]
then
if [ -n "$(which curl)" ]; then
curl --silent -L "${BASE_URL}/${INSTALL_FILE_REMOTE}" \
-o "/tmp/${INSTALL_FILE}" || echo 'error setup script: '"${BASE_URL}/${INSTALL_FILE_REMOTE}"
elif [ -n "$(which wget)" ]; then
wget --quiet "${BASE_URL}/${INSTALL_FILE_REMOTE}" \
-O "/tmp/${INSTALL_FILE}" || echo 'error setup script: '"${BASE_URL}/${INSTALL_FILE_REMOTE}"
else
echo "Found neither 'curl' nor 'wget'. Can't Continue."
exit 1
fi
fi
if [ ! -e "/tmp/${INSTALL_FILE}" ]
then
echo "Error Downloading Install File"
exit 1
fi
bash "/tmp/${INSTALL_FILE}" --no-dev-deps

View File

@ -1,60 +0,0 @@
#!/bin/bash
set -e
set -u
set -o pipefail
if [ -z "${my_tmp-}" ]; then
my_tmp=$(mkdir -p)
fi
if [ -z "${PREFIX-}" ]; then
PREFIX=""
fi
if [ -z "${NODE_PATH-}" ]; then
node_install_path=$PREFIX/usr/local
else
node_install_path=$(dirname $(dirname $NODE_PATH))
fi
NODEJS_VER=${1}
NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1)
NODEJS_NAME="node"
NODEJS_BASE_URL="https://nodejs.org"
if [ $NODEJS_VERT -ge 1 ] && [ $NODEJS_VERT -lt 4 ]
then
echo "Selecting io.js instead of node.js for this version (>= 1.0.0 < 4.0.0)"
NODEJS_BASE_URL="https://iojs.org"
NODEJS_NAME="iojs"
fi
# When using .pkg
#NODEJS_REMOTE="$NODEJS_BASE_URL/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}.pkg"
#NODEJS_PKG="/tmp/${NODEJS_NAME}-${NODEJS_VER}.pkg"
NODEJS_REMOTE="$NODEJS_BASE_URL/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64.tar.gz"
NODEJS_PKG="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64.tar.gz"
NODEJS_UNTAR="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64"
if [ -n "${NODEJS_VER}" ]; then
echo "installing ${NODEJS_NAME} as ${NODEJS_NAME} ${NODEJS_VER}..."
curl -fsSL "${NODEJS_REMOTE}" -o "${NODEJS_PKG}"
# When using .pkg
#sudo /usr/sbin/installer -pkg "${NODEJS_PKG}" -target /
# When using .tar.gz
mkdir -p ${NODEJS_UNTAR}/
tar xf "${NODEJS_PKG}" -C "${NODEJS_UNTAR}/" --strip-components=1
rm -f ${NODEJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
mkdir -p "$node_install_path/" || sudo mkdir -p "$node_install_path/"
rsync -a "${NODEJS_UNTAR}/" "$node_install_path/" || sudo rsync -a "${NODEJS_UNTAR}/" "$node_install_path/"
chown -R $(whoami) "$node_install_path/lib/node_modules/" || sudo chown -R $(whoami) "$node_install_path/lib/node_modules/"
chown $(whoami) "$node_install_path/bin/" || sudo chown $(whoami) "$node_install_path/bin/"
fi

View File

@ -1,87 +0,0 @@
#!/bin/bash
# Not every platform has or needs sudo, gotta save them O(1)s...
sudo_cmd=""
((EUID)) && [[ -z "${ANDROID_ROOT:-}" ]] && sudo_cmd="sudo"
set -e
set -u
set -o pipefail
if [ -z "${my_tmp-}" ]; then
my_tmp="$(mktemp -d -t node-installer.XXXXXXXX)"
fi
if [ -z "${PREFIX-}" ]; then
PREFIX=""
fi
if [ -z "${NODE_PATH-}" ]; then
node_install_path=$PREFIX/usr/local
else
node_install_path=$(dirname $(dirname $NODE_PATH))
fi
NODEJS_VER=${1}
NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1)
NODEJS_NAME="node"
NODEJS_BASE_URL="https://nodejs.org"
if [ $NODEJS_VERT -ge 1 ] && [ $NODEJS_VERT -lt 4 ]
then
echo "Selecting io.js instead of node.js for this version (>= 1.0.0 < 4.0.0)"
NODEJS_BASE_URL="https://iojs.org"
NODEJS_NAME="iojs"
fi
if [ -n "$(uname -a | grep aarch64)" ]; then
ARCH="arm64"
elif [ -n "$(uname -a | grep 64)" ]; then
ARCH="x64"
elif [ -n "$(uname -a | grep armv8l)" ]; then
ARCH="arm64"
elif [ -n "$(uname -a | grep armv7l)" ]; then
ARCH="armv7l"
elif [ -n "$(uname -a | grep armv6l)" ]; then
ARCH="armv6l"
else
ARCH="x86"
fi
NODEJS_REMOTE="${NODEJS_BASE_URL}/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
NODEJS_LOCAL="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
NODEJS_UNTAR="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}"
if [ -n "${NODEJS_VER}" ]; then
echo "installing ${NODEJS_NAME} as ${NODEJS_NAME} ${NODEJS_VER}..."
if [ -n "$(command -v curl 2>/dev/null | grep curl)" ]; then
curl -fsSL ${NODEJS_REMOTE} -o ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
elif [ -n "$(command -v wget 2>/dev/null | grep wget)" ]; then
wget --quiet ${NODEJS_REMOTE} -O ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
else
echo "'wget' and 'curl' are missing. Please run the following command and try again"
echo " sudo apt-get install --yes curl wget"
exit 1
fi
mkdir -p ${NODEJS_UNTAR}/
# --strip-components isn't portable, switch to portable version by performing move step after untar
tar xf ${NODEJS_LOCAL} -C ${NODEJS_UNTAR}/ #--strip-components=1
mv ${NODEJS_UNTAR}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}/* ${NODEJS_UNTAR}/
rm -rf ${NODEJS_UNTAR}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH} # clean up the temporary unzip folder
rm ${NODEJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then
echo $sudo_cmd rsync -Krl "${NODEJS_UNTAR}/" "$node_install_path/"
rsync -Krl "${NODEJS_UNTAR}/" "$node_install_path/" || $sudo_cmd rsync -Krl "${NODEJS_UNTAR}/" "$node_install_path/"
else
# due to symlink issues on Arch Linux, don't copy the share directory
rm -rf ${NODEJS_UNTAR}/share
echo $sudo_cmd cp -Hr "${NODEJS_UNTAR}/*" "$node_install_path/"
cp -Hr "${NODEJS_UNTAR}"/* "$node_install_path/" || $sudo_cmd cp -Hr "${NODEJS_UNTAR}"/* "$node_install_path/"
fi
rm -rf "${NODEJS_UNTAR}"
chown -R $(whoami) "$node_install_path/lib/node_modules/" || $sudo_cmd chown -R $(whoami) "$node_install_path/lib/node_modules/"
chown $(whoami) ""$node_install_path"/bin/" || $sudo_cmd chown $(whoami) ""$node_install_path"/bin/"
fi

56
setup-ubuntu.bash Normal file
View File

@ -0,0 +1,56 @@
#!/bin/bash
# curl -fsSL https://ldsconnect.org/setup-linux.bash | bash -c
NODE_VER=${1}
echo ""
echo ""
echo "updating apt-get..."
sudo bash -c "apt-get update -qq -y < /dev/null" > /dev/null
# fail2ban
if [ -z "$(which fail2ban-server | grep fail2ban)" ]; then
echo "installing fail2ban..."
sudo bash -c "apt-get install -qq -y fail2ban < /dev/null" > /dev/null
fi
# git, wget, curl, build-essential
if [ -z "$(which pkg-config | grep pkg-config)" ] || [ -z "$(which git | grep git)" ] || [ -z "$(which wget | grep wget)" ] || [ -z "$(which curl | grep curl)" ] || [ -z "$(which gcc | grep gcc)" ] || [ -z "$(which rsync | grep rsync)" ]
then
echo "installing git, wget, curl, build-essential, rsync, pkg-config..."
sudo bash -c "apt-get install -qq -y git wget curl build-essential rsync pkg-config < /dev/null" > /dev/null 2>/dev/null
fi
# node
if [ -n "$(which node | grep node 2>/dev/null)" ]; then
NODE_VER=""
if [ "${NODE_VER}" == "$(node -v 2>/dev/null)" ]; then
echo node ${NODE_VER} already installed
else
echo ""
echo "HEY, LISTEN:"
echo "node is already installed as $(node -v | grep v)"
echo ""
echo "to reinstall please first run: rm $(which node)"
echo ""
fi
fi
if [ -n "${NODE_VER}" ]; then
if [ -n "$(arch | grep 64)" ]; then
ARCH="x64"
else
ARCH="x86"
fi
echo "installing node ${NODE_VER}..."
curl -fsSL "http://nodejs.org/dist/${NODE_VER}/node-${NODE_VER}-linux-${ARCH}.tar.gz" \
-o "/tmp/node-${NODE_VER}-linux-${ARCH}.tar.gz"
pushd /tmp
tar xf /tmp/node-${NODE_VER}-linux-${ARCH}.tar.gz
rm node-${NODE_VER}-linux-x64/{LICENSE,ChangeLog,README.md}
sudo rsync -a "/tmp/node-${NODE_VER}-linux-${ARCH}/" /usr/local/
sudo chown -R $(whoami) /usr/local
fi

View File

@ -1,44 +1,180 @@
#!/bin/bash
# Installs node.js + dependencies for both Ubuntu and OS X
#
# See https://git.colaj86.com/coolaj86/node-installer.sh
#
# curl -fsSL https://example.com/setup.bash | bash
# wget -nv https://example.com/setup.bash -O - | bash
set -e
set -u
echo ""
echo "Script starting..."
BASE_URL="https://git.coolaj86.com/coolaj86/node-installer.sh/raw/master"
BASE_URL="https://raw.githubusercontent.com/coolaj86/node-install-script/master"
#######################
# Download installers #
#######################
if [ -n "$(which node 2>/dev/null || false)" ]; then
echo ""
echo "HEY, LISTEN:"
echo "node is already installed as $(node -v | grep v)"
echo ""
echo "to reinstall please first run: rm $(which node)"
echo ""
fi
INSTALL_FILE_REMOTE="install.sh"
INSTALL_FILE="node-installer.sh"
if [ ! -e "/tmp/${INSTALL_FILE}" ]
then
if [ -n "$(which curl)" ]; then
curl --silent -L "${BASE_URL}/${INSTALL_FILE_REMOTE}" \
-o "/tmp/${INSTALL_FILE}" || echo 'error setup script: '"${BASE_URL}/${INSTALL_FILE_REMOTE}"
elif [ -n "$(which wget)" ]; then
wget --quiet "${BASE_URL}/${INSTALL_FILE_REMOTE}" \
-O "/tmp/${INSTALL_FILE}" || echo 'error setup script: '"${BASE_URL}/${INSTALL_FILE_REMOTE}"
else
echo "Found neither 'curl' nor 'wget'. Can't Continue."
if [ -f "/tmp/NODE_VER" ]; then
NODE_VER=$(cat /tmp/NODE_VER)
fi
if [ -f "/tmp/APP_URL" ]; then
APP_URL=$(cat /tmp/APP_URL)
fi
echo "app url: $APP_URL"
echo "node version: $NODE_VER"
if [ -z "$NODE_VER" ]; then
NODE_VER="v4.2.3"
fi
OS="unsupported"
ARCH=""
if [ "$(uname | grep -i 'Darwin')" ]; then
OSX_VER="$(sw_vers | grep ProductVersion | cut -d':' -f2 | cut -f2)"
OSX_MAJOR="$(echo ${OSX_VER} | cut -d'.' -f1)"
OSX_MINOR="$(echo ${OSX_VER} | cut -d'.' -f2)"
OSX_PATCH="$(echo ${OSX_VER} | cut -d'.' -f3)"
#
# Major
#
if [ "$OSX_MAJOR" -lt 10 ]; then
echo "unsupported OS X version (os 9-)"
exit 1
fi
fi
if [ ! -e "/tmp/${INSTALL_FILE}" ]
then
echo "Error Downloading Install File"
if [ "$OSX_MAJOR" -gt 10 ]; then
echo "unsupported OS X version (os 11+)"
exit 1
fi
#
# Minor
#
if [ "$OSX_MINOR" -le 5 ]; then
echo "unsupported OS X version (os 10.5-)"
exit 1
fi
# Snow
if [ "$OSX_MINOR" -eq 6 ]; then
OS='snow'
fi
# Lion
if [ $OSX_MINOR -eq 7 ]; then
OS='lion'
fi
# Mountain Lion
if [ "$OSX_MINOR" -eq 8 ]; then
OS='mountain'
fi
# Mavericks, Yosemite
if [ "$OSX_MINOR" -ge 9 ]; then
OS='mavericks'
fi
if [ -n "$(sysctl hw | grep 64bit | grep ': 1')" ]; then
ARCH="64"
else
ARCH="32"
fi
elif [ "$(uname | grep -i 'Linux')" ]; then
if [ ! -f "/etc/issue" ]; then
echo "unsupported linux os"
exit 1
fi
if [ -n "$(arch | grep 64)" ]; then
ARCH="64"
else
ARCH="32"
fi
if [ "$(cat /etc/issue | grep -i 'Ubuntu')" ]; then
OS='ubuntu'
elif [ "$(cat /etc/issue | grep -i 'Fedora')" ]; then
OS='fedora'
fi
else
echo "unsupported unknown os (non-mac, non-linux)"
exit 1
fi
case "${OS}" in
fedora)
echo "sudo yum"
echo "wget --quiet ${BASE_URL}/setup-fedora.bash -O /tmp/install-node.bash || echo 'error downloading os setup script'"
;;
ubuntu)
wget --quiet "${BASE_URL}/setup-ubuntu.bash" -O /tmp/install-node.bash || echo 'error downloading os setup script'
;;
yosemite)
# mavericks
curl --silent "${BASE_URL}/setup-mavericks.bash" -o /tmp/install-node.bash || echo 'error downloading os setup script'
;;
mavericks)
curl --silent "${BASE_URL}/setup-mavericks.bash" -o /tmp/install-node.bash || echo 'error downloading os setup script'
;;
mountain)
echo "wget cltools"
echo "curl --silent ${BASE_URL}/setup-mountain.bash -o /tmp/install-node.bash || echo 'error downloading os setup script'"
;;
lion)
echo "wget cltools"
echo "curl --silent ${BASE_URL}/setup-lion.bash -o /tmp/install-node.bash || echo 'error downloading os setup script'"
;;
snow)
echo "wget gcc-0.6.pkg"
echo "curl --silent ${BASE_URL}/setup-snow.bash -o /tmp/install-node.bash || echo 'error downloading os setup script'"
;;
*)
echo "unsupported unknown os ${OS}"
exit 1
;;
esac
bash "/tmp/${INSTALL_FILE}"
echo "${OS}" "${ARCH}"
bash /tmp/install-node.bash "${NODE_VER}"
# jshint
if [ -z "$(which jshint | grep jshint)" ]; then
echo "installing jshint..."
npm install --silent jshint -g > /dev/null
else
echo "jshint already installed"
fi
# clone app
if [[ $APP_URL ]]; then
sudo bash -c "cd /home/ && git clone ${APP_URL} node-app && cd node-app && npm install"
fi
# forever
sudo bash -c "npm -g install forever"
wget --quiet "${BASE_URL}/config-files/forever-node-init.sh" -O /etc/init.d/forever || echo 'error downloading forever config script'
sudo bash -c "chmod a+x /etc/init.d/forever"
sudo bash -c "update-rc.d forever defaults"
if [[ $APP_URL ]]; then
sudo bash -c "forever start /home/node-app/index.js"
fi
# nginx
echo "installing nginx..."
sudo bash -c "apt-get install -qq -y nginx < /dev/null" > /dev/null
wget --quiet "${BASE_URL}/config-files/nginx-config" -O /etc/nginx/sites-enabled/default || echo 'error configuring nginx'
sudo bash -c "service nginx reload"
echo ""