#!/bin/bash
if ! bin/cliq ls bin/n98-magerun2.phar; then
  echo "Downloading n98-magerun2.phar, just a moment..."
  bin/clinotty curl -sS -O https://files.magerun.net/n98-magerun2.phar
  bin/clinotty curl -sS -o n98-magerun2.phar.sha256 https://files.magerun.net/sha256.php?file=n98-magerun2.phar
  bin/clinotty shasum -a 256 -c n98-magerun2.phar.sha256
  [ $? != 0 ] && echo "sha256 checksum do not match!" && exit

  bin/cliq chmod +x n98-magerun2.phar
  bin/cliq mkdir -p bin
  bin/cliq mv n98-magerun2.phar bin
fi

S=$(bin/cli cat /usr/local/etc/php/php.ini | grep -iGc 'xdebug.mode = off');

if [[ $S == 1 ]]; then
  bin/cli bin/n98-magerun2.phar "$@"
else
  bin/cli php -dxdebug.mode=debug -dxdebug.start_with_request=yes bin/n98-magerun2.phar "$@"
fi
