#!/bin/bash


# ensure we are in the right dir
cd $(dirname $0)/..;

# check for a git dir
if [[ ! -e .git ]]; then
    echo "No .git directory here, exiting" >&2;
    exit 1;
fi

# be on master and get the updates
git checkout master;
git fetch origin;

# inspect what has changed
flist=$(git diff --name-only origin/master);

if [[ -z "${flist}" ]]; then
    # no changes, we are done
    exit 0;
fi

# there are updates, do them
git pull;

if echo -e "${flist}" | grep -i package.json > /dev/null; then
    # package.json has been changed, need to rebuild the modules
    rm -rf node_modules;
    npm install;
fi

# now, restart the service
systemctl restart mobileapps;

exit $?;


Add a script to check for git changes and rebuild the deps if needed
Add a script to check for git changes and rebuild the deps if needed

The script checks for new, committed changes and pulls them in. If
package.json changes as well, the node dependencies are rebuilt and the
service is restarted.

The script is meant to be run by cron every couple of minutes, so keep
the git tree in labs clean!

Change-Id: Ic0897cce30aef1d450fc975d96389e5983756657
