#!/bin/sh

#### clear proxy
unset http_proxy
unset https_proxy

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

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

    mkdir -p /data/$APPNAME/log
    python3 /usr/local/bin/pull.py
  fi

  cd /data/$APPNAME
  uwsgi --http 0.0.0.0:7000 --http-websockets --greenlet --master --asyncio 100 --wsgi wsgi:application --python-autoreload 1
fi

#### update source
if [ "$1" = '--update' ]; then
  echo "update"
  python3 /usr/local/bin/pull.py
fi

#### start
if [ "$1" = '--run' ]; then
  echo "run"
  cd /data/$APPNAME
  uwsgi --http 0.0.0.0:7000 --http-websockets --greenlet --master --asyncio 100 --wsgi wsgi:application --python-autoreload 1
fi

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