better script

This commit is contained in:
martind2000 2016-04-04 13:08:21 +01:00
parent 8ebe4cafbe
commit 57c0a99285

View File

@ -1,45 +1,64 @@
#!/bin/bash
NVM="~/.nvm"
DEV="~/dev"
LIVE="~/live"
NVM="$HOME/.nvm"
NVM_VERSION="5.7.0"
DEV="$HOME/dev"
LIVE="$HOME/live"
SWAP="/swapfile"
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\n$fmt\n" "$@"
}
fancy_echo "Installing Obrand Admin Server ..."
## Update initial packages
sudo apt-get -y --force-yes update
#sudo apt-get -y --force-yes upgrade
sudo apt-get -y -q --force-yes update
# sudo apt-get -y -q --force-yes upgrade
# install apps
sudo apt-get --assume-yes install build-essential git nginx htop screen wget curl
sudo apt-get --assume-yes install build-essential git nginx htop screen wget curl postgresql-9.4
# set up and install swap file
sudo swapon -s
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon -s
sudo swapon /swapfile
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
source .bashrc
nvm install v5.7.0
npm install -g gulp bower pm2 npm-check npm-install-missing ember-cli phantomjs
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.
fancy_echo "Installing global packages ..."
npm set progress=false
npm install -g gulp bower pm2 npm-check npm-install-missing ember-cli phantomjs-prebuilt
if [ ! -d "$LIVE" ]; then
mkdir ~/live
mkdir $LIVE
fi
if [ ! -d "$DEV" ]; then
mkdir ~/dev
mkdir $DEV
fi
cd ~/dev
cd $DEV
# Get latest version of Obrand Admin
git clone https://censis.visualstudio.com/DefaultCollection/_git/O-Brand
@ -47,27 +66,28 @@ git clone https://censis.visualstudio.com/DefaultCollection/_git/O-Brand
# Get latest version of Obrand Admin Server
git clone http://gitlab.silvrtree.co.uk/martind2000/obrand-admin-server.git
cd ~/dev/O-Brand
cd $DEV/O-Brand
npm install .
npm-install-missing
bower install
ember build --environtment production
ember build --environment production
cd ~/dev/obrand-admin-server
cd $DEV/obrand-admin-server
npm install . && npm-install-missing
cd ~/dev/O-Brand/dist
cp -ra . ~/dev/obrand-admin-server/wwwroot
cd $DEV/O-Brand/dist
cp -ra . $DEV/obrand-admin-server/wwwroot
cd ~/dev/obrand-admin-server
cp -ra . ~/live
cd $DEV/obrand-admin-server
rsync -uav --exclude .git $DEV/obrand-admin-server/ $LIVE
# Configure nginx
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
sudo service restart nginx
npm set progress=true
sudo /etc/init.d/nginx restart