#!/bin/sh

#### clear proxy
unset http_proxy
unset https_proxy

#### copy source
if [ "$1" = '--init' ]; then
  echo "init"

  if [ ! -d /data/$APPNAME/log ]; then

    cd /opt/LightDependencies
    node pull.js

    mkdir -p /data/$APPNAME/log
    mkdir -p /data/$APPNAME/backup
    ln -s /opt/LightDependencies/node_modules /data/$APPNAME/node_modules
  fi

  cd /data/$APPNAME
  node /data/$APPNAME/app $APPPARAMS 1>>/data/$APPNAME/log/application.log 2>>/data/$APPNAME/log/error.log
fi

#### update source
if [ "$1" = '--update' ]; then
  echo "update"

  cd /opt/LightDependencies
  node pull.js
fi

#### start
if [ "$1" = '--run' ]; then
  echo "run"

  cd /data/$APPNAME
  node /data/$APPNAME/app $APPPARAMS 1>>/data/$APPNAME/log/application.log 2>>/data/$APPNAME/log/error.log
fi

#### debug
if [ "$1" = '--bash' ]; then
  /bin/bash
fi