usefulfiles/scripts/obrand_install.sh

185 lines
3.7 KiB
Bash
Raw Normal View History

2016-04-04 09:28:46 +00:00
#!/bin/bash
2016-04-04 12:08:21 +00:00
NVM="$HOME/.nvm"
NVM_VERSION="5.7.0"
DEV="$HOME/dev"
LIVE="$HOME/live"
2016-04-15 13:52:35 +00:00
STAGING="$HOME/staging"
SERVER="O-BrandServer"
FRONT="O-Brand"
2016-04-04 12:08:21 +00:00
SWAP="/swapfile"
2016-04-04 13:21:53 +00:00
DBSETUP="obrand-admin-server/dbrebuild.sh"
2016-04-06 13:38:52 +00:00
PKG_MANAGER=$( command -v yum || command -v apt-get ) || echo "Neither yum nor apt-get found"
PKG_DEVICE=$(basename $PKG_MANAGER)
2016-04-15 13:52:35 +00:00
UPDATE=no
DATABASE=no
NGINX=no
2016-04-04 09:28:46 +00:00
2016-04-04 12:08:21 +00:00
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\n$fmt\n" "$@"
}
2016-04-15 13:52:35 +00:00
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
2016-04-04 12:08:21 +00:00
fancy_echo "Installing Obrand Admin Server ..."
2016-04-04 09:28:46 +00:00
## Update initial packages
2016-04-04 12:08:21 +00:00
2016-04-15 13:52:35 +00:00
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
2016-04-04 09:28:46 +00:00
2016-04-15 13:52:35 +00:00
if [[ $UPDATE = "yes" ]]; then
if [ $(basename $PKG_MANAGER) = "yum" ]; then
2016-04-06 13:38:52 +00:00
sudo yum --assumeyes upgrade
sudo yum --assumeyes install git make automake gcc gcc-c++ kernel-devel nginx htop screen wget curl postgresql postgresql-contrib
2016-04-15 13:52:35 +00:00
else
2016-04-06 13:38:52 +00:00
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
2016-04-15 13:52:35 +00:00
fi
2016-04-06 13:38:52 +00:00
fi
2016-04-04 09:28:46 +00:00
# set up and install swap file
2016-04-04 12:08:21 +00:00
if [[ ! -f "$SWAP" ]]; then
sudo fallocate -l 1G $SWAP
sudo chmod 600 $SWAP
sudo mkswap $SWAP
sudo swapon $SWAP
fi
2016-04-04 09:28:46 +00:00
# setup node and npm
2016-04-04 09:56:28 +00:00
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
2016-04-04 12:08:21 +00:00
export NVM_DIR=$NVM
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
2016-04-04 09:56:28 +00:00
2016-04-04 12:08:21 +00:00
source $HOME/.bashrc
source $NVM/nvm.sh
2016-04-04 09:56:28 +00:00
fi
2016-04-04 09:28:46 +00:00
2016-04-04 12:08:21 +00:00
nvm install $NVM_VERSION
2016-04-04 09:28:46 +00:00
# get source and build
2016-04-04 09:56:28 +00:00
2016-04-04 12:08:21 +00:00
# Install global packages.
fancy_echo "Installing global packages ..."
npm set progress=false
npm install -g gulp bower pm2 npm-check npm-install-missing ember-cli phantomjs-prebuilt
2016-04-04 09:56:28 +00:00
if [ ! -d "$LIVE" ]; then
2016-04-04 12:08:21 +00:00
mkdir $LIVE
2016-04-04 09:56:28 +00:00
fi
if [ ! -d "$DEV" ]; then
2016-04-04 12:08:21 +00:00
mkdir $DEV
2016-04-04 09:56:28 +00:00
fi
2016-04-04 09:42:04 +00:00
2016-04-04 12:08:21 +00:00
cd $DEV
2016-04-04 09:28:46 +00:00
# Get latest version of Obrand Admin
2016-04-15 13:52:35 +00:00
if [ ! -d "$DEV/$FRONT/.git" ]; then
git clone https://censis.visualstudio.com/DefaultCollection/_git/O-Brand
else
cd $DEV/$FRONT
git pull origin master
fi
if [ ! -d "$DEV/$SERVER/.git" ]; then
git clone https://censis.visualstudio.com/DefaultCollection/O-Brand/_git/O-BrandServer
else
cd $DEV/$SERVER
git pull origin master
fi
2016-04-04 09:28:46 +00:00
# Get latest version of Obrand Admin Server
2016-04-15 13:52:35 +00:00
cd $DEV/$FRONT
2016-04-04 09:28:46 +00:00
2016-04-15 13:52:35 +00:00
npm install . && npm-install-missing
2016-04-04 09:28:46 +00:00
bower install
2016-04-04 12:08:21 +00:00
ember build --environment production
2016-04-04 09:28:46 +00:00
2016-04-15 13:52:35 +00:00
cd $DEV/$SERVER
2016-04-04 09:28:46 +00:00
npm install . && npm-install-missing
2016-04-15 13:52:35 +00:00
npm install git+http://gitlab.silvrtree.co.uk/martind2000/md-utils.git
npm install git+http://gitlab.silvrtree.co.uk/martind2000/node-validator.git
rsync -uav --exclude .git $DEV/$SERVER/ $STAGING
cd $DEV/$FRONT/dist
2016-04-04 09:28:46 +00:00
2016-04-15 13:52:35 +00:00
cp -ra . $STAGING/wwwroot
2016-04-04 09:28:46 +00:00
2016-04-15 13:52:35 +00:00
if [[ $DATABASE = "yes" ]]; then
2016-04-04 13:21:53 +00:00
echo Setting up Database server...
2016-04-15 13:52:35 +00:00
# sudo su - postgres -c "$DEV/$DBSETUP"
# node dbconfig.js
fi
2016-04-04 13:21:53 +00:00
echo Copying...
2016-04-15 13:52:35 +00:00
rsync -uav --exclude .git $STAGING/ $LIVE
2016-04-04 09:28:46 +00:00
# Configure nginx
2016-04-15 13:52:35 +00:00
if [[ $NGINX = "yes" ]]; then
2016-04-04 09:28:46 +00:00
sudo fuser -k 80/tcp
sudo wget https://dl.dropboxusercontent.com/u/233909/obrand/obrand.nginx -O /etc/nginx/sites-available/obrand && sudo ln -s /etc/nginx/sites-available/obrand /etc/nginx/sites-enabled/obrand
2016-04-06 13:38:52 +00:00
sudo rm /etc/nginx/sites-enabled/default
2016-04-04 12:08:21 +00:00
npm set progress=true
sudo /etc/init.d/nginx restart
2016-04-04 09:28:46 +00:00
2016-04-15 13:52:35 +00:00
fi