Last active
August 29, 2015 14:23
-
-
Save nweldev/17c436bc3fb615a833a8 to your computer and use it in GitHub Desktop.
Install a complete (and customizable) development environnement for AngularJS on Linux & Mac OS X
This file contains 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
#!/usr/bin/env bash | |
##################### | |
# automatically installs a complete AngularJS development environment | |
# you can run this script even if a lot of this tools are already installed | |
# this will just update the all thing (maybe not the beter way, but it will) | |
# don't run this script as root (or via sudo) | |
# sudo is just used when needed | |
# you need of course to be a sudoer to run it | |
# author : Noël Macé (noelmace.com) | |
# license : GPLv3 | |
# version : 0.2.2 | |
# last edit : 2015-06-16 | |
# TODO : Linux 32bits tests, Mac OS X support, Redhat support | |
# tested on : | |
# 0.2.2 : Debian Jessie 64bits, CrunBang Janice 32 bits | |
# 0.2 : Debian Jessie 64 bits | |
# 0.1 : Debian Jessie 64 bits, CrunchBang Janice 32 bits | |
# sorry for my poor english (feel free to correct my faults if you want) ;) | |
# if you want to contribute, please test your version (both install and update) | |
# in virtual machines, and join the outputs to your pull request | |
##### your conf ##### | |
# here is the list of all tools that need to be installed | |
# remove the ones you don't need (or which are already installed and up to date) | |
# atm-extensions stand for atom-extensions, and n-tools for npm-tools, of course | |
#tools="nodejs npm atom atm-extensions git ruby n-tools" | |
tools="vundle" | |
# npm packages to install | |
npm_tools="grunt-cli bower yo generator-karma generator-angular" | |
# atom extensions to install | |
atom_ext="angularjs atom-beautify atom-jshint file-icons javascript-snippets seti-syntax todo-show ask-stack atom-bootstrap3 emmet isotope-ui monokai seti-ui turbo-javascript" | |
# atom version to install on Debian | |
# this version number is not considered on 32bits Debian / Ubuntu | |
atom_version="0.209.0" | |
# set to true if you want to force this script to install atom via a repository | |
# if false, it use the official way (download the amd64 .deb via wget and install it via dpkg) | |
atom_force_rep_use=true | |
# colors for messages | |
# commant all if you don't want it | |
# success messages | |
SUCCESS_COLOR="\\033[1;32m" # green | |
# return to normal color | |
NORMAL_COLOR="\\033[0;39m" | |
# error messages | |
ERROR_COLOR="\\033[1;31m" # red | |
# messages about a new step in the installation | |
STEP_COLOR="\\033[1;33m" # yellow | |
# message before asking to sudo | |
SUDO_COLOR="\\033[1;31m" # red | |
# discreet colors | |
DISCREET_BG_COLOR="\e[40m" | |
DISCREET_COLOR="\e[90m" | |
# normal colors | |
NORMAL_BG_COLOR="\e[49m" | |
NORMAL_COLOR="\e[39m" | |
##################### | |
## base functions ### | |
PROGNAME=$0 | |
# show an error message | |
function error_msg | |
{ | |
echo -e "$ERROR_COLORError: ${1:-"Unknown Error"}$NORMAL_COLOR" 1>&2 | |
} | |
# exit after showing an error message | |
function error_exit | |
{ | |
error_msg $1 | |
exit $2 | |
} | |
function success_msg | |
{ | |
echo -e "$SUCCESS_COLOR${1:-"Success !"}$NORMAL_COLOR" | |
} | |
function head_msg | |
{ | |
echo -e "\n\n$STEP_COLOR=== ${1} ===$NORMAL_COLOR\n\n" | |
} | |
function step_msg | |
{ | |
echo -e "\n$STEP_COLOR${1} ...$NORMAL_COLOR\n" | |
} | |
function discreet_mode | |
{ | |
echo -e $DISCREET_COLOR$DISCREET_BG_COLOR | |
} | |
function normal_mode | |
{ | |
echo -e $NORMAL_COLOR$NORMAL_BG_COLOR | |
} | |
function npm_verify | |
{ | |
if [ -x /usr/local/bin/npm ]; then | |
local_npm=true | |
npm="/usr/local/bin/npm"; | |
elif [ -x /usr/bin/npm ]; then | |
npm="/usr/bin/npm" | |
else | |
error_msg "impossible to find npm command" | |
return 1 | |
fi | |
return 0 | |
} | |
function sudo_prompt | |
{ | |
echo -e "$SUDO_COLOR Warning: $@ will be run via sudo $NORMAL_COLOR"; | |
sudo $@ | |
} | |
function node_verify | |
{ | |
if [ -x /usr/local/bin/node ]; then | |
nodejs="/usr/local/bin/node" | |
elif [ -x /usr/bin/node ]; then | |
nodejs="/usr/bin/node" | |
elif [ -x /usr/local/bin/nodejs ]; then | |
sudo_prompt ln -s /usr/local/bin/nodejs /usr/local/bin/node | |
rm /usr/bin/nodejs | |
rm /usr/bin/node | |
nodejs="/usr/local/bin/nodejs"; | |
elif [ -x /usr/bin/nodejs ]; then | |
sudo_prompt ln -s /usr/bin/nodejs /usr/bin/node | |
nodejs="/usr/bin/nodejs" | |
else | |
error_msg "impossible to find nodejs command" | |
return 1 | |
fi | |
return 0 | |
} | |
function show_version | |
{ | |
local option | |
case $1 in | |
word) | |
option="--version" | |
;; | |
letter) | |
option="-v" | |
;; | |
esac | |
# TODO : clean error messages | |
rslt=$($3 $option) | |
local is_present=$? | |
if [ "$is_present" = 0 ]; then | |
case $2 in | |
direct) | |
success_msg "\t$rslt" | |
;; | |
*) | |
success_msg "\t$3 $rslt" | |
;; | |
esac | |
else | |
error_msg "$3 is not installed" | |
return 1 | |
fi | |
return 0 | |
} | |
## init ############# | |
cd /tmp | |
head_msg "initialisation" | |
exit_code_bad_os=2 | |
exit_code_unknown_arch=3 | |
case `uname -m` in | |
i[3456789]86|x86|i86pc) | |
arch='x86' | |
;; | |
x86_64|amd64|AMD64) | |
arch='amd64' | |
;; | |
*) | |
error_exit "Unknown architecture `uname -m`." $exit_code_unknown_arch | |
;; | |
esac | |
if [[ "$(uname)" == "Darwin" ]]; then | |
# Mac OS X | |
os="Darwin" | |
# TODO (soon) | |
wget="curl" | |
error_exit "Mac OS X is not suported yet" $exit_code_bad_os | |
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]]; then | |
# GNU/Linux | |
step_msg "GNU/Linux detected" | |
if [ -f /etc/debian_version ] ; then | |
# Debian, Crunchbang, ubuntu ... | |
step_msg "Debian based distribution detected" | |
os="Debian" | |
wget=$(if [ -x /usr/bin/wget ]; then echo "/usr/bin/wget"; fi) | |
pkg_get='sudo_prompt '$(if [ -x /usr/bin/apt-get ]; then echo "/usr/bin/apt-get"; fi) | |
# force-yes option is needed because of w8t repository package authentification ... | |
# TODO : verify that ! | |
pkg_install=$(if [ -n pkg_get ] ; then echo $pkg_get" install -y --force-yes" ; fi) | |
pkg_update=$(if [ -n pkg_get ] ; then echo $pkg_get" update" ; fi) | |
pkg_base='sudo_prompt '$(if [ -x /usr/bin/dpkg ]; then echo "/usr/bin/dpkg"; fi) | |
pkg_remove=$(if [ -n pkg_get ] ; then echo $pkg_get" remove -y" ; fi) | |
term_soft="terminator" | |
nodejs_pkg_name="nodejs npm" | |
ruby_pkg_name="ruby-full" | |
elif [ -f /etc/redhat-release ] ; then | |
# RedHat, CentOS ... | |
os="Redhat" | |
# TODO, if you need it :) ('cause i don't) | |
error_exit "RedHat is not suported yet" $exit_code_bad_os | |
else | |
error_exit "This Linux distribution is not supported !" $exit_code_bad_os | |
fi | |
else | |
error_exit "\nThis OS is not supported, sorry ..." $exit_code_bad_os | |
fi | |
success_msg | |
step_msg "update package manager" | |
discreet_mode | |
$pkg_update && success_msg || error_exit "update error" 1 | |
normal_mode | |
## Install ## | |
## git ###### | |
if [[ "$tools" == *"git"* ]]; then | |
head_msg "git" | |
$pkg_install git | |
fi | |
## nodejs ### | |
if [[ "$tools" == *"nodejs"* ]]; then | |
head_msg "nodejs" | |
case $os in | |
Debian) | |
# pre-installation script from nodesource | |
step_msg "pre-installation script" | |
$wget https://deb.nodesource.com/setup | sudo bash - && success_msg || error_msg | |
;; | |
*) | |
error_msg "npm installation is not supported on $os" | |
;; | |
esac | |
# install nodejs via package | |
if ( npm_verify && node_verify ) ; then | |
success_msg "npm and nodejs are already installed. Just updating ..." | |
else | |
step_msg "install nodejs and npm via your system's package manager" | |
$pkg_install $nodejs_pkg_name | |
fi | |
if npm_verify; then | |
# update nodejs to last version via npm | |
$pkg_install curl | |
sudo_prompt $npm cache clean -f | |
sudo_prompt $npm install -g n | |
# n don't seems to return a posix value ... | |
sudo_prompt n stable | |
# update npm to last version | |
# npm don't seems to return a posix value ... | |
sudo_prompt $npm install -g npm | |
# remove this line if you want to keep the npm and nodejs packages after updating via npm and n | |
# I don't know if it is a good practice, but I just don't need a package manager over a package manager ... | |
$pkg_remove $nodejs_pkg_name | |
# TODO : verify for other systems than Debian | |
npm_verify && success_msg "nodejs and npm are installed and up to date" || error_msg | |
fi | |
fi | |
## ruby ##### | |
if [[ "$tools" == *"ruby"* ]]; then | |
head_msg "ruby" | |
$pkg_install $ruby_pkg_name | |
fi | |
## npm tools ## | |
if [[ "$tools" == *"n-tools"* ]]; then | |
head_msg "npm tools" | |
if npm_verify; then | |
sudo_prompt $npm install -g $npm_tools | |
else | |
error_msg "impossible to install npm tools" | |
fi | |
fi | |
## atom editor ## | |
if [[ "$tools" == *"atom"* ]]; then | |
head_msg "atom" | |
if [[ "$os" == "Debian" ]]; then | |
if [[ "$arch" == "amd64" ]] && [ "$atom_force_rep_use" = false ]; then | |
# cd /tmp | |
# TODO : use https://github.com/atom/atom/releases/latest | |
$wget https://github.com/atom/atom/releases/download/v0.209.0/atom-amd64.deb | |
$pkg_base -i atom-amd64.deb | |
else | |
# add webupd8team repository if not present | |
sources="/etc/apt/sources.list" | |
if ls /etc/apt/sources.list.d/*.list 1> /dev/null 2&>1; then | |
sources=$sources" /etc/apt/sources.list.d/*.list" | |
fi | |
if [ $(cat $sources | grep "webupd8team.*atom"| wc -l) -eq 0 ]; then | |
step_msg "add w8t repository" | |
# we can't use debian_version for this repository, cause only ubuntu version are suported | |
# you are not supposed to run this script on old Debian (or afiliated distribution) anyway | |
echo "deb http://ppa.launchpad.net/webupd8team/atom/ubuntu wily main" | sudo_prompt tee /etc/apt/sources.list.d/atom-w8t.list | |
discreet_mode | |
$pkg_update | |
normal_mode | |
else | |
success_msg "w8t repository already present" | |
fi | |
$pkg_install atom | |
fi | |
elif [[ "$os" == "Redhat" ]]; then | |
# TODO | |
error_msg "atom install on Redhat is not supported yet" | |
elif [[ "$os" == "Darwin" ]]; then | |
# TODO | |
error_msg "atom install on Mac OS X is not supported yet" | |
fi | |
fi | |
## atom extensions ## | |
if [[ "$tools" == *"atm-extensions"* ]]; then | |
head_msg "atom extensions" | |
if [ -x /usr/bin/apm ]; then | |
/usr/bin/apm install $atom_ext | |
else | |
error_msg "impossible to find /usr/bin/apm" | |
fi | |
fi | |
## vim ######### | |
if [[ "$tools" == *"vim"* ]]; then | |
head_msg "vim" | |
$pkg_install vim | |
fi | |
## vim-extensions ## | |
# TODO : verify vim required options | |
if [[ "$tools" == *"vundle"* ]]; then | |
head_msg "vim vundle" | |
if [ ! -d "~/.vim/bundle" ]; then | |
mkdir -p ~/.vim/bundle | |
fi | |
if (show_version word direct git) ; then | |
step_msg "clone vundle" | |
if [ ! -d ~/.vim/bundle/Vundle.vim ]; then | |
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim | |
fi | |
step_msg "configure vundle" | |
cat <<EOF >> ~/.vimrc | |
""""""""""""""""" general configuration """"""""""""""""""""" | |
syntax on | |
set nu | |
filetype plugin indent on | |
set tabstop=4 | |
set shiftwidth=4 | |
set expandtab | |
""""""""""""""""" vundle configuration """""""""""""""""""""" | |
"" autogenerated by angularde installer "" | |
"" edit what you want, and just save the file to continue """ | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
set nocompatible " be iMproved, required | |
filetype off " required | |
" set the runtime path to include Vundle and initialize | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
" alternatively, pass a path where Vundle should install plugins | |
"call vundle#begin('~/some/path/here') | |
" let Vundle manage Vundle, required | |
Plugin 'gmarik/Vundle.vim' | |
" The following are examples of different formats supported. | |
" Keep Plugin commands between vundle#begin/end. | |
" plugin on GitHub repo | |
"Plugin 'tpope/vim-fugitive' | |
" plugin from http://vim-scripts.org/vim/scripts.html | |
"Plugin 'L9' | |
" Git plugin not hosted on GitHub | |
"Plugin 'git://git.wincent.com/command-t.git' | |
" git repos on your local machine (i.e. when working on your own plugin) | |
"Plugin 'file:///home/gmarik/path/to/plugin' | |
" The sparkup vim script is in a subdirectory of this repo called vim. | |
" Pass the path to set the runtimepath properly. | |
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} | |
" Avoid a name conflict with L9 | |
"Plugin 'user/L9', {'name': 'newL9'} | |
Plugin 'burnettk/vim-angular' | |
Plugin 'pangloss/vim-javascript' | |
Plugin 'othree/javascript-libraries-syntax.vim' | |
Plugin 'Valloric/YouCompleteMe' | |
Plugin 'SirVer/ultisnips' | |
Plugin 'honza/vim-snippets' | |
Plugin 'matthewsimo/angular-vim-snippets' | |
" All of your Plugins must be added before the following line | |
call vundle#end() " required | |
filetype plugin indent on " required | |
" To ignore plugin indent changes, instead use: | |
"filetype plugin on | |
" | |
" Brief help | |
" :PluginList - lists configured plugins | |
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate | |
" :PluginSearch foo - searches for foo; append `!` to refresh local cache | |
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal | |
" | |
" see :h vundle for more details or wiki for FAQ | |
" Put your non-Plugin stuff after this line | |
"""""""""""""""""" end of vundle configuration """"""""""""""" | |
"""""""""""""""""" plugins configuration """"""""""""""""""""" | |
" map CtrlP to Ctrl+P | |
let g:ctrlp_map = '<c-p>' | |
"""" UltiNips """" | |
let g:UltiSnipsSnippetsDir = '~/.vim/bundle/' | |
" add your snippets extensions name here | |
let g:UltiSnipsSnippetDirectories = ['ultisnips', 'vim-snippets', 'angular-vim-snippets'] | |
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe. | |
let g:UltiSnipsExpandTrigger="<tab>" | |
let g:UltiSnipsJumpForwardTrigger="<c-b>" | |
let g:UltiSnipsJumpBackwardTrigger="<c-z>" | |
" If you want :UltiSnipsEdit to split your window. | |
let g:UltiSnipsEditSplit="vertical" | |
"""""""""""""""""" end of plugins configuration """""""""""""" | |
EOF | |
# TODO : put this file online, and wget it | |
step_msg "edit vimrc" | |
vim ~/.vimrc | |
step_msg "install vundle plugins dependencies" | |
# for youcompleteme (cmake, python-dev) | |
$pkg_install cmake python-dev | |
step_msg "install vundle plugin" | |
vim +PluginInstall +qall now | |
step_msg "post install" | |
~/.vim/bundle/YouCompleteMe/install.sh --clang-completer | |
success_msg "vundle and vundle plugins are now installed" | |
# TODO : non-vundle plugins | |
else | |
error_msg "impossible de install vundle. Verify your git and vim installation." | |
fi | |
fi | |
## conclusion ## | |
npm_verify | |
node_verify | |
success_msg "you now have installed :\n" | |
show_version word direct git | |
show_version letter no ruby | |
show_version letter no node | |
show_version letter no npm | |
show_version word no yo | |
show_version word direct grunt | |
show_version word no bower | |
show_version letter no atom | |
atom_installed_ext=$(ls ~/.atom/packages 2> /dev/null | tr "\n" " ") | |
if [ -n "$atom_installed_ext" ];then | |
success_msg "\natom extensions : \n\t$atom_installed_ext" | |
fi | |
step_msg "Have fun with AngularJS :)" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment