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 #!/bin/bash
NVM="~/.nvm" NVM="$HOME/.nvm"
DEV="~/dev" NVM_VERSION="5.7.0"
LIVE="~/live" 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 ## 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 # 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 # set up and install swap file
sudo swapon -s if [[ ! -f "$SWAP" ]]; then
sudo fallocate -l 1G /swapfile sudo fallocate -l 1G $SWAP
sudo chmod 600 /swapfile sudo chmod 600 $SWAP
sudo mkswap /swapfile sudo mkswap $SWAP
sudo swapon -s sudo swapon $SWAP
sudo swapon /swapfile fi
# setup node and npm # setup node and npm
if [ ! -d "$NVM" ]; then if [ ! -d "$NVM" ]; then
# Will enter here if $DIRECTORY exists, even if it contains spaces # 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 curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
source .bashrc export NVM_DIR=$NVM
nvm install v5.7.0 [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
npm install -g gulp bower pm2 npm-check npm-install-missing ember-cli phantomjs
source $HOME/.bashrc
source $NVM/nvm.sh
fi fi
nvm install $NVM_VERSION
# get source and build # 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 if [ ! -d "$LIVE" ]; then
mkdir ~/live mkdir $LIVE
fi fi
if [ ! -d "$DEV" ]; then if [ ! -d "$DEV" ]; then
mkdir ~/dev mkdir $DEV
fi fi
cd ~/dev cd $DEV
# Get latest version of Obrand Admin # Get latest version of Obrand Admin
git clone https://censis.visualstudio.com/DefaultCollection/_git/O-Brand 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 # Get latest version of Obrand Admin Server
git clone http://gitlab.silvrtree.co.uk/martind2000/obrand-admin-server.git git clone http://gitlab.silvrtree.co.uk/martind2000/obrand-admin-server.git
cd ~/dev/O-Brand cd $DEV/O-Brand
npm install . npm install .
npm-install-missing npm-install-missing
bower install 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 npm install . && npm-install-missing
cd ~/dev/O-Brand/dist cd $DEV/O-Brand/dist
cp -ra . ~/dev/obrand-admin-server/wwwroot cp -ra . $DEV/obrand-admin-server/wwwroot
cd ~/dev/obrand-admin-server cd $DEV/obrand-admin-server
cp -ra . ~/live rsync -uav --exclude .git $DEV/obrand-admin-server/ $LIVE
# Configure nginx # Configure nginx
sudo fuser -k 80/tcp 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 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