usefulfiles/scripts/so_install.sh

162 lines
3.2 KiB
Bash
Raw Normal View History

2016-04-21 15:33:43 +00:00
#!/bin/bash
NVM="$HOME/.nvm"
NVM_VERSION="5.7.0"
DEV="$HOME/dev"
LIVE="$HOME/live"
STAGING="$HOME/staging"
SERVER="smartoffice"
FRONT="SODashServer"
SWAP="/swapfile"
PKG_MANAGER=$( command -v yum || command -v apt-get ) || echo "Neither yum nor apt-get found"
PKG_DEVICE=$(basename $PKG_MANAGER)
UPDATE=no
DATABASE=no
NGINX=no
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\n$fmt\n" "$@"
}
for i in "$@"
do
case $i in
-u|--update)
UPDATE=YES
shift # past argument=value
;;
-d|--database)
DATABASE=YES
shift # past argument=value
;;
-n|--nginx)
NGINX=YES
shift # past argument=value
;;
--default)
DEFAULT=YES
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
fancy_echo "Installing Smart Office Console Server ..."
## Update initial packages
fancy_echo Cleaning...
if [ ! -d "$DEV" ]; then
mkdir -p $DEV
fi
if [ ! -d "$LIVE" ]; then
mkdir -p $LIVE
fi
if [ ! -d "$STAGING" ]; then
rm -rf $STAGING
mkdir -p $STAGING
else
mkdir -p $STAGING
fi
if [[ $UPDATE = "YES" ]]; then
if [ $(basename $PKG_MANAGER) = "yum" ]; then
sudo yum --assumeyes upgrade
sudo yum --assumeyes install git make automake gcc gcc-c++ kernel-devel nginx htop screen wget curl postgresql postgresql-contrib
else
sudo apt-get -y -q --force-yes update
sudo apt-get -y -q --force-yes upgrade
sudo apt-get --assume-yes install build-essential git nginx htop screen wget curl postgresql postgresql-contrib
fi
fi
# set up and install swap file
if [[ ! -f "$SWAP" ]]; then
sudo fallocate -l 1G $SWAP
sudo chmod 600 $SWAP
sudo mkswap $SWAP
sudo swapon $SWAP
fi
# setup node and npm
if [ ! -d "$NVM" ]; then
# Will enter here if $DIRECTORY exists, even if it contains spaces
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
export NVM_DIR=$NVM
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
source $HOME/.bashrc
source $NVM/nvm.sh
fi
nvm install $NVM_VERSION
# get source and build
# Install global packages.
npm set progress=false
if [[ $UPDATE = "YES" ]]; then
fancy_echo "Installing global packages ..."
npm install -g gulp bower pm2 npm-check npm-install-missing ember-cli phantomjs-prebuilt
fi
if [ ! -d "$LIVE" ]; then
mkdir $LIVE
fi
if [ ! -d "$DEV" ]; then
mkdir $DEV
fi
cd $DEV
# Get latest version of Obrand Admin
if [ ! -d "$DEV/$FRONT/.git" ]; then
git clone http://gitlab.silvrtree.co.uk/martind2000/SODashServer.git
else
cd $DEV/$FRONT
git pull origin master
fi
# Get latest version of Obrand Admin Server
cd $DEV/$FRONT
npm install . && npm-install-missing
bower install
gulp default
rsync -uav --exclude .git $DEV/$FRONT/ $STAGING
echo Copying...
rsync -uav --exclude .git $STAGING/ $LIVE
npm set progress=true
# Configure nginx
if [[ $NGINX = "YES" ]]; then
sudo fuser -k 80/tcp
sudo wget https://dl.dropboxusercontent.com/u/233909/smartoffice/smartoffice.nginx -O /etc/nginx/sites-available/smartoffice.nginx && sudo ln -s /etc/nginx/sites-available/smartoffice.nginx /etc/nginx/sites-enabled/smartoffice.nginx
sudo rm /etc/nginx/sites-enabled/default
sudo /etc/init.d/nginx restart
fi