CAL_DIR="/app/content/"
DATA_DIR="/app/data/"
CWC_PATH="/app/CalibreWebCompanion"
if [ ! -d "$CAL_DIR" ]; then
  echo "Calibre Library not mounted at the correct location."
  echo "Mount it at /app/content/"
  echo "Exiting..."
  exit 1
fi

if [ ! -d "$DATA_DIR" ]; then
  echo "A data directory not mounted at the correct location, exiting"
  echo "This is used to store the database and logs"
  echo "mount something at /app/data/"
  echo "exiting"
  exit 1
fi

cp -R -u -p "/app/CalibreWebCompanion/db.sqlite3" "/app/data/"
ls -l /app
python "${CWC_PATH}/manage.py" makemigrations
python "${CWC_PATH}/manage.py" migrate
