#!/usr/bin/php
<?php

use Symfony\Component\Console\Input\ArgvInput;

define('LARAVEL_START', microtime(true));

// The controller's PHP never runs as root (the code is root's and the controller runs as its service user): as root
// it would leave root-owned caches, logs and keys the service cannot change. The suricatavel CLI drops to the service
// user. Image builds and CI containers set SURICATAVEL_ALLOW_ROOT=1.
if (function_exists('posix_geteuid') && posix_geteuid() === 0 && getenv('SURICATAVEL_ALLOW_ROOT') !== '1') {
    fwrite(STDERR, "Do not run Suricatavel's artisan as root: use `suricatavel <command>`, which runs as the service user,\n"
        ."or run it as that user: runuser -u suricatavel -- php artisan ...\n");
    exit(1);
}

// Register the Composer autoloader...
require __DIR__.'/vendor/autoload.php';

// Bootstrap Laravel and handle the command...
$status = (require_once __DIR__.'/bootstrap/app.php')
    ->handleCommand(new ArgvInput);

exit($status);
