Last active
August 29, 2015 14:07
-
-
Save Unitech/991f11c557b984c202a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
node_version="0.11.14" | |
# Get user name | |
user_name="$(id -u -n)" | |
# Get user id | |
user_id="$(id -u)" | |
# Get Oses's category | |
dist=`grep DISTRIB_ID /etc/*-release | awk -F '=' '{print $2}'` | |
# Get User's home directory ex: /home/nodejs | |
home_directory=$(eval echo ~${SUDO_USER}) | |
#if [ "$(id -u)" == "0" ]; then | |
# echo "Sorry, You can't run this script with root permission." | |
# exit 1 | |
#fi | |
echo " | |
This script will install a fresh Node.js environment (v$node_version) and the process manager PM2 | |
Execution of this script will setup following components: | |
● Basic system tools | |
◦ git | |
◦ curl | |
◦ htop | |
◦ make | |
◦ build-essential | |
◦ g++ | |
◦ libssl-dev | |
◦ zlib1g-dev | |
◦ graphicsmagick | |
● Nodejs | $node_version | |
◦ nvm | |
◦ npm | |
◦ pm2 | |
" | |
read -p "Do you want to proceed? y/N? " result | |
if [ "$result" == "y" ]; then | |
if [ "$dist" == "Ubuntu" ]; then | |
echo "Your OS is Ubuntu" | |
# install base system | |
sudo apt-get update | |
sudo apt-get install -y htop dialog libssl-dev libpcre3 libpcre3-dev zlib1g-dev git-core curl make build-essential g++ graphicsmagick python-software-properties | |
else | |
sudo yum update | |
sudo yum install git curl-devel make gcc gcc-c++ kernel-devel | |
fi | |
echo " | |
# | |
# | |
# Generating RSA keys | |
# | |
#" | |
ssh-keygen -b 2048 -t rsa -q | |
echo " | |
# | |
# | |
# Installing NodeJs | |
# | |
#" | |
# Nodejs install | |
curl -sL http://raw.github.com/creationix/nvm/master/install.sh | sh | |
if [ "$dist" == "Ubuntu" ]; then | |
source $home_directory/.profile | |
else | |
source $home_directory/.bash_profile | |
fi | |
source $home_directory/.nvm/nvm.sh | |
nvm install $node_version | |
nvm use $node_version | |
nvm alias default $node_version | |
source ~/.bashrc | |
echo " | |
# | |
# | |
# Installing pm2 | |
# | |
#" | |
# PM2 install | |
npm install pm2 -g --unsafe-perm | |
pm2 list | |
echo " | |
To finalize installation do: | |
$ source ~/.bashrc | |
To activate PM2 at startup do: | |
$ pm2 startup <ubuntu|centos|gentoo|systemd> | |
Issues: https://github.com/Unitech/pm2/issues | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment