#!/usr/bin/env php
<?php

use Symfony\Component\Console\Input\ArgvInput;

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

// The agent's PHP never runs as root (the code is root's and the agent runs as its service user): as root it would
// leave root-owned caches and files the agent cannot change. The suricatavel-agent CLI drops to the service user.
// Package builds and CI containers set SURICATAVEL_AGENT_ALLOW_ROOT=1; the standalone binary (support/phar/stub.php),
// which appliances run as root, is not affected.
if (! defined('SURICATAVEL_AGENT_STANDALONE') && function_exists('posix_geteuid') && posix_geteuid() === 0 && getenv('SURICATAVEL_AGENT_ALLOW_ROOT') !== '1') {
    fwrite(STDERR, "Do not run the agent's artisan as root: use `suricatavel-agent <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);
