Initial commit

This commit is contained in:
Alannah Kearney 2019-05-08 22:04:47 +10:00
commit a34ef4419e
7 changed files with 185 additions and 0 deletions

31
src/Cli/Cli.php Normal file
View file

@ -0,0 +1,31 @@
<?php
namespace pointybeard\Helpers\Functions\Cli;
/**
* Checks if bash can be invoked.
*
* Credit to Troels Knak-Nielsen for inspiring this code.
* (http://www.sitepoint.com/interactive-cli-password-prompt-in-php/)
*
* @return bool true if bash can be invoked
*/
if (!function_exists(__NAMESPACE__ . 'can_invoke_bash')) {
function can_invoke_bash()
{
return (strcmp(trim(shell_exec("/usr/bin/env bash -c 'echo OK'")), 'OK') === 0);
}
}
/**
* Checks if script is running as root user
*
* @return bool true if user is root
*/
if (!function_exists(__NAMESPACE__ . 'is_su')) {
function is_su()
{
$userinfo = posix_getpwuid(posix_geteuid());
return (bool)($userinfo['uid'] == 0 || $userinfo['name'] == 'root');
}
}