parent
a73793937b
commit
fb1f307d05
@ -0,0 +1,20 @@ |
||||
<?php |
||||
|
||||
final class neato { |
||||
|
||||
use \traits\linux_core; |
||||
use \traits\packages; |
||||
use \traits\init_systems; |
||||
|
||||
const get_opt = '/opt/'; |
||||
const get_etc = '/etc/'; |
||||
const get_bin = '/bin/'; |
||||
const get_user_bin = '/usr/bin/'; |
||||
const get_super_user_bin = '/usr/sbin/'; |
||||
const get_user_local_bin = '/usr/local/bin/'; |
||||
|
||||
protected function __construct() { } |
||||
|
||||
} |
||||
|
||||
// end of neato installer commands |
||||
@ -0,0 +1,44 @@ |
||||
<?php |
||||
|
||||
namespace init_systems; |
||||
|
||||
// Used by: Gentoo, Alpine |
||||
|
||||
class open_rc { |
||||
|
||||
private static function get_valid_action_for_service(string $action): string|false { |
||||
return match($action) { |
||||
'start'=>'start', |
||||
'stop'=>'stop', |
||||
'status'=>'status', |
||||
'restart'=>'restart', |
||||
'reload'=>'reload', |
||||
default=>'restart', |
||||
}; |
||||
} |
||||
|
||||
private static function get_valid_action_for_system_ctl(string $action): string|false { |
||||
return match($action) { |
||||
'show'=>'show', |
||||
'add'=>'add', |
||||
'del'=>'del', |
||||
default=>'add', |
||||
}; |
||||
} |
||||
|
||||
public static function service($name, $action = 'restart') { |
||||
$my_action = get_valid_action_for_service($action); |
||||
exec(\neato::get_super_user_bin . 'rc-service ' . safe_cmd($name, $action), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function systemctl($name, $action = 'add') { |
||||
$my_action = get_valid_action_for_system_ctl($action); |
||||
exec(\neato::get_super_bin . 'rc-update ' . safe_cmd($action, $name), $output, $exit_code); |
||||
check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
<?php |
||||
|
||||
namespace init_systems; |
||||
|
||||
// Used by: Void, Alpine, and Artix |
||||
|
||||
class runit { |
||||
|
||||
private static function get_valid_action(string $action): string|false { |
||||
return match($action) { |
||||
'start'=>'start', |
||||
'stop'=>'stop', |
||||
'status'=>'status', |
||||
'force-restart'=>'force-restart', |
||||
'enable'=>'enable', |
||||
'disable'=>'disable', |
||||
'log'=>'log', // View service log |
||||
default=>'restart', |
||||
}; |
||||
} |
||||
|
||||
public static function service(string $name, string $action = 'restart') { |
||||
$my_action = get_valid_action($action); |
||||
exec(\neato::get_super_user_bin . 'sv ' . safe_cmd($my_action, $name), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function systemctl(string $name, string $action = 'enable') { |
||||
return \neato::service($name, $action); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,45 @@ |
||||
<?php |
||||
|
||||
namespace init_systems; |
||||
|
||||
class sys_v_init { |
||||
|
||||
private static function get_valid_action_for_service(string $action): string|false { |
||||
return match($action) { |
||||
'start'=>'start', |
||||
'stop'=>'stop', |
||||
'status'=>'status', |
||||
'restart'=>'restart', |
||||
'reload'=>'reload', |
||||
'enable'=>'enable', |
||||
'disable'=>'disable', |
||||
default=>'restart', |
||||
}; |
||||
} |
||||
|
||||
private static function get_valid_action_for_system_ctl(string $action): string|false { |
||||
return match($action) { |
||||
'list'=>'--list', |
||||
'on'=>'on', |
||||
'off'=>'off', |
||||
default=>'on', |
||||
}; |
||||
} |
||||
|
||||
public static function service(string $name, string $action = 'restart') { |
||||
$my_action = get_valid_action_for_service($action); |
||||
exec(\neato::get_super_user_bin . '/etc/init.d/' . safe_cmd($name, $my_action), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function systemctl(string $name, string $action = 'on') { |
||||
$my_action = get_valid_action_for_system_ctl($action); |
||||
exec(\neato::get_bin . 'chkconfig ' . safe_cmd($action, $name), $output, $exit_code); |
||||
check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,59 @@ |
||||
<?php |
||||
|
||||
namespace init_systems; |
||||
|
||||
// Used by: RHEL, Fedora, Debian, Ubuntu, Arch, openSUSE |
||||
|
||||
class systemd { |
||||
|
||||
private static function get_valid_action_for_service(string $action): string|false { |
||||
return match($action) { |
||||
'start'=>'start', |
||||
'stop'=>'stop', |
||||
'status'=>'status', |
||||
'restart'=>'restart', |
||||
'reload'=>'reload', |
||||
'enable'=>'enable', |
||||
'disable'=>'disable', |
||||
'mask'=>'mask', // disable |
||||
'unmask'=>'unmask', // re-enable |
||||
'reboot'=>'reboot', |
||||
'poweroff'=>'poweroff', |
||||
'list-units'=>'list-units', |
||||
'list-unit-files'=>'list-unit-files', |
||||
'isolate'=>'isolate', // Change system runlevel target |
||||
'log'=>'journalctl -u', // View service log |
||||
'realtime'=>'journalctl -f', // watch live logs |
||||
default=>'restart', |
||||
}; |
||||
} |
||||
|
||||
private static function get_valid_action_for_system_ctl(string $action): string|false { |
||||
return match($action) { |
||||
'start'=>'start', |
||||
'stop'=>'stop', |
||||
'status'=>'status', |
||||
'restart'=>'restart', |
||||
'reload'=>'reload', |
||||
'enable'=>'enable', |
||||
'disable'=>'disable', |
||||
default=>'restart', |
||||
}; |
||||
} |
||||
|
||||
public static function service(string $name, string $action = 'restart') { |
||||
$my_action = get_valid_action_for_service($action); |
||||
exec(self::get_super_user_bin . 'service ' . safe_cmd($name, $my_action), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function systemctl(string $name, string $action = 'enable') { |
||||
$my_action = get_valid_action_for_system_ctl($action); |
||||
exec(self::get_bin . 'systemctl ' . safe_cmd($my_action, $name), $output, $exit_code); |
||||
check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,53 @@ |
||||
<?php |
||||
|
||||
namespace package_managers; |
||||
|
||||
class apk { |
||||
|
||||
public static function is_installed($prog) { |
||||
exec(\neato::get_user_bin . 'apk -e info ' . safe_cmd($prog), $out, $exit_code); |
||||
return ($exit_code == 0) ? ['installed' => true, 'version' => $out] : ['installed' => false]; |
||||
} |
||||
|
||||
public static function upgrade($prog) { |
||||
exec(\neato::get_user_bin . 'apk upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to upgrade: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function install($prog) { |
||||
exec(\neato::get_user_bin . 'apk add -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to install: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function uninstall($prog) { |
||||
exec(\neato::get_user_bin . 'apk del -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function add_repo($repo) { |
||||
exec("echo \"$repo\" >> /etc/apk/repositories"); |
||||
exec(\neato::get_user_bin . 'apk update' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to add new repo: {$repo}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function update() { |
||||
exec(\neato::get_user_bin . 'apk update -y ' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function full_update() { |
||||
exec(\neato::get_user_bin . 'apk update -y && ' . self::get_user_bin . 'apk upgrade -y' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,68 @@ |
||||
<?php |
||||
|
||||
namespace package_managers; |
||||
|
||||
class apt { |
||||
|
||||
public static function is_installed(string $prog) { |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); |
||||
$version = str_replace('Version: ', '', $output[0]); |
||||
return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; |
||||
} |
||||
|
||||
public static function upgrade(string $prog) { |
||||
exec(\neato::get_user_bin . 'apt upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to upgrade: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function install(string $prog) { |
||||
exec(\neato::get_user_bin . 'apt install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to install: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function purge(string $prog) { |
||||
exec(\neato::get_user_bin . 'apt --purge remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function uninstall(string $prog) { |
||||
exec(\neato::get_user_bin . 'apt remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function add_repo(string $repo) { |
||||
exec(\neato::get_user_bin . 'add-apt-repository -y -u ' . safe_cmd_quotes($repo) . stderr(), $output, $exit_code); |
||||
display($output); // -u = DO UPDATE once done... |
||||
check_for_error($exit_code, "Unable to uninstall: {$repo}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function update() { |
||||
exec(\neato::get_user_bin . 'apt update -y ' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function full_update() { |
||||
exec(\neato::get_user_bin . 'apt update -y && '. \neato::get_user_bin . 'apt-get upgrade -y && ' . \neato::get_user_bin . 'apt autoremove -y && ' . \neato::get_user_bin . 'apt autoclean -y' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
// Have a Backup!! |
||||
public static function full_system_upgrade() { |
||||
exec(\neato::get_user_bin . 'apt update -y && '. \neato::get_user_bin . 'apt upgrade -y '. \neato::get_user_bin . 'apt full-upgrade -y && ' . \neato::get_user_bin . 'apt autoremove -y && ' . \neato::get_user_bin . 'apt autoclean -y' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,68 @@ |
||||
<?php |
||||
|
||||
namespace package_managers; |
||||
|
||||
class apt_get { |
||||
|
||||
public static function is_installed(string $prog) { |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); |
||||
$version = str_replace('Version: ', '', $output[0]); |
||||
return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; |
||||
} |
||||
|
||||
public static function upgrade(string $prog) { |
||||
exec(\neato::get_user_bin . 'apt-get upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to upgrade: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function install(string $prog) { |
||||
exec(\neato::get_user_bin . 'apt-get install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to install: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function purge(string $prog) { |
||||
exec(\neato::get_user_bin . 'apt-get --purge remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function uninstall(string $prog) { |
||||
exec(\neato::get_user_bin . 'apt-get remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function add_repo(string $repo) { |
||||
exec(\neato::get_user_bin . 'add-apt-repository -y -u ' . safe_cmd_quotes($repo) . stderr(), $output, $exit_code); |
||||
display($output); // -u = DO UPDATE once done... |
||||
check_for_error($exit_code, "Unable to uninstall: {$repo}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function update() { |
||||
exec(\neato::get_user_bin . 'apt-get update -y ' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function full_update() { |
||||
exec(\neato::get_user_bin . 'apt-get update -y && '. \neato::get_user_bin . 'apt-get upgrade -y && ' . \neato::get_user_bin . 'apt-get autoremove -y && ' . \neato::get_user_bin . 'apt-get autoclean -y' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
// Have a Backup!! |
||||
public static function full_system_upgrade() { |
||||
exec(\neato::get_user_bin . 'apt-get update -y && '. \neato::get_user_bin . 'apt-get upgrade -y '. \neato::get_user_bin . 'apt-get dist-upgrade -y && && ' . \neato::get_user_bin . 'apt-get autoremove -y && ' . \neato::get_user_bin . 'apt-get autoclean -y' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,57 @@ |
||||
<?php |
||||
|
||||
namespace package_managers; |
||||
|
||||
class dnf { |
||||
|
||||
public static function is_installed(string $prog) { |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); |
||||
$version = str_replace('Version: ', '', $output[0]); |
||||
return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; |
||||
} |
||||
|
||||
public static function upgrade($prog) { |
||||
exec(\neato::get_user_bin . 'dnf upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to upgrade: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function install($prog) { |
||||
exec(\neato::get_user_bin . 'dnf add -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to install: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function uninstall($prog) { |
||||
exec(\neato::get_user_bin . 'dnf del -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/** |
||||
* @todo figure out this method |
||||
*/ |
||||
public static function add_repo($repo) { |
||||
exec(\neato::get_user_bin . 'dnf update' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to add new repo: {$repo}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function update() { |
||||
exec(\neato::get_user_bin . 'dnf update -y ' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function full_update() { |
||||
exec(\neato::get_user_bin . 'dnf update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,66 @@ |
||||
<?php |
||||
|
||||
namespace package_managers; |
||||
|
||||
class flatpak { |
||||
|
||||
public static function is_installed(string $prog) { |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); |
||||
$version = str_replace('Version: ', '', $output[0]); |
||||
return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; |
||||
} |
||||
|
||||
public static function upgrade(string $prog) { |
||||
return self::update($prog); |
||||
} |
||||
|
||||
public static function install(string $prog) { |
||||
exec(\neato::get_user_bin . 'flatpak install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to install: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function purge(string $prog) { |
||||
return self::uninstall($prog); |
||||
} |
||||
|
||||
public static function uninstall(string $prog) { |
||||
exec(\neato::get_user_bin . 'flatpak uninstall -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/** |
||||
* @todo fix me |
||||
*/ |
||||
public static function add_repo(string $name, string $url) { |
||||
exec(\neato::get_user_bin . 'flatpak remote-add --if-not-exists ' . safe_cmd($name, $url) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function update() { |
||||
exec(\neato::get_user_bin . 'flatpak update' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function full_update() { |
||||
return false; |
||||
} |
||||
|
||||
// Have a Backup!! |
||||
public static function full_system_upgrade() { |
||||
return false; |
||||
} |
||||
|
||||
public static function list() { |
||||
exec(\neato::get_user_bin . 'flatpak list' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,99 @@ |
||||
<?php |
||||
|
||||
namespace package_managers; |
||||
|
||||
class nala { |
||||
|
||||
public static function is_installed(string $prog) { |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); |
||||
$version = str_replace('Version: ', '', $output[0]); |
||||
return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; |
||||
} |
||||
|
||||
public static function upgrade(string $prog) { |
||||
exec(\neato::get_user_bin . 'nala upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to upgrade: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function install(string $prog) { |
||||
exec(\neato::get_user_bin . 'nala install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to install: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function purge(string $prog) { |
||||
exec(\neato::get_user_bin . 'nala purge -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function uninstall(string $prog) { |
||||
exec(\neato::get_user_bin . 'nala remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/** |
||||
* @todo fix me |
||||
*/ |
||||
public static function add_repo(string $repo) { |
||||
return false; |
||||
} |
||||
|
||||
public static function update() { |
||||
exec(\neato::get_user_bin . 'nala update -y ' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function full_update() { |
||||
exec(\neato::get_user_bin . 'nala update -y && ' . \neato::get_user_bin . 'nala autoremove -y && ' . \neato::get_user_bin . 'nala clean -y' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
// Have a Backup!! |
||||
public static function full_system_upgrade() { |
||||
return false; |
||||
} |
||||
|
||||
public static function list() { |
||||
exec(\neato::get_user_bin . 'nala list --upgradeable' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/* |
||||
* shows only the packages installed on the system. |
||||
*/ |
||||
public static function installed() { |
||||
exec(\neato::get_user_bin . 'nala list --installed' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/* |
||||
* View the list of mirrors by using the fetch command. |
||||
*/ |
||||
public static function fetch() { |
||||
exec(\neato::get_user_bin . 'nala fetch' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/* |
||||
* Delete the local cache files with the clean command. |
||||
*/ |
||||
public static function clean() { |
||||
exec(\neato::get_user_bin . 'nala fetch' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,57 @@ |
||||
<?php |
||||
|
||||
namespace package_managers; |
||||
|
||||
class pacman { |
||||
|
||||
public static function is_installed(string $prog) { |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); |
||||
$version = str_replace('Version: ', '', $output[0]); |
||||
return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; |
||||
} |
||||
|
||||
public static function upgrade($prog) { |
||||
exec(\neato::get_user_bin . 'pacman upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to upgrade: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function install($prog) { |
||||
exec(\neato::get_user_bin . 'pacman -S ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to install: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function uninstall($prog) { |
||||
exec(\neato::get_user_bin . 'pacman del -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/** |
||||
* @todo figure out this method |
||||
*/ |
||||
public static function add_repo($repo) { |
||||
exec(\neato::get_user_bin . 'pacman update' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to add new repo: {$repo}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function update() { |
||||
exec(\neato::get_user_bin . 'pacman update -y ' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function full_update() { |
||||
exec(\neato::get_user_bin . 'pacman update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,91 @@ |
||||
<?php |
||||
|
||||
namespace package_managers; |
||||
|
||||
class snap { |
||||
|
||||
public static function is_installed(string $prog) { |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); |
||||
$version = str_replace('Version: ', '', $output[0]); |
||||
return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; |
||||
} |
||||
|
||||
public static function upgrade(string $prog) { |
||||
return self::update($prog); |
||||
} |
||||
|
||||
public static function install(string $prog) { |
||||
exec(\neato::get_user_bin . 'snap install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to install: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function purge(string $prog) { |
||||
return self::uninstall($prog); |
||||
} |
||||
|
||||
public static function uninstall(string $prog) { |
||||
exec(\neato::get_user_bin . 'snap remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/** |
||||
* @todo fix me |
||||
*/ |
||||
public static function add_repo(string $repo) { |
||||
return false; |
||||
} |
||||
|
||||
public static function update() { |
||||
exec(\neato::get_user_bin . 'snap refresh' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function full_update() { |
||||
return false; |
||||
} |
||||
|
||||
// Have a Backup!! |
||||
public static function full_system_upgrade() { |
||||
return false; |
||||
} |
||||
|
||||
public static function list() { |
||||
exec(\neato::get_user_bin . 'snap list --upgradeable' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/* |
||||
* shows only the packages installed on the system. |
||||
*/ |
||||
public static function installed() { |
||||
exec(\neato::get_user_bin . 'snap --installed' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/* |
||||
* View the list of mirrors by using the fetch command. |
||||
*/ |
||||
public static function info() { |
||||
exec(\neato::get_user_bin . 'snap info --verbose' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/* |
||||
* Revert a Snap package to a previous version: |
||||
*/ |
||||
public static function revert() { |
||||
exec(\neato::get_user_bin . 'snap revert' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,57 @@ |
||||
<?php |
||||
|
||||
namespace package_managers; |
||||
|
||||
class yum { |
||||
|
||||
public static function is_installed(string $prog) { |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); |
||||
exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); |
||||
$version = str_replace('Version: ', '', $output[0]); |
||||
return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; |
||||
} |
||||
|
||||
public static function upgrade($prog) { |
||||
exec(\neato::get_user_bin . 'yum upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to upgrade: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function install($prog) { |
||||
exec(\neato::get_user_bin . 'yum add -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to install: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function uninstall($prog) { |
||||
exec(\neato::get_user_bin . 'yum del -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to uninstall: {$prog}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
/** |
||||
* @todo figure out this method |
||||
*/ |
||||
public static function add_repo($repo) { |
||||
exec(\neato::get_user_bin . 'yum update' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
check_for_error($exit_code, "Unable to add new repo: {$repo}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function update() { |
||||
exec(\neato::get_user_bin . 'yum update -y ' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function full_update() { |
||||
exec(\neato::get_user_bin . 'yum update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stderr(), $output, $exit_code); |
||||
display($output); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,41 @@ |
||||
<?php |
||||
|
||||
namespace traits; |
||||
|
||||
trait init_systems { |
||||
|
||||
private static function get_init_system(): string|false { |
||||
$a_init_systems = [ |
||||
'/etc/systemd'=>'systemd', |
||||
'/etc/init.d'=>'sys_v_init', |
||||
'/etc/init'=>'upstart', |
||||
'/etc/runlevels'=>'open_rc', |
||||
'/etc/runit'=>'runit', |
||||
]; |
||||
foreach($a_init_systems as $init_dir=>$init_system_name) { |
||||
if (file_exists($init_dir) && is_dir($init_dir)) { |
||||
return $init_system_name; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public static function service(string $name, string $action = 'restart') { |
||||
$my_init = self::get_init_system(); |
||||
if ($my_init === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\package_managers\\{$my_init}::service"; |
||||
return $namespaced($name, $action); |
||||
} |
||||
|
||||
public static function systemctl(string $name, string $action = 'enable') { |
||||
$my_init = self::get_init_system(); |
||||
if ($my_init === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\init_systems\\{$my_init}::systemctl"; |
||||
return $namespaced($name, $action); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,128 @@ |
||||
<?php |
||||
|
||||
namespace traits; |
||||
|
||||
trait linux_core { |
||||
|
||||
public static function no_sticky_bit(string $file) { |
||||
if (! file_exists($file)) { |
||||
return true; |
||||
} |
||||
exec(self::get_user_bin . 'chmod -s ' . safe_cmd($file), $output, $exit_code); |
||||
check_for_error($exit_code, "Unable to remove sticky bit with chmod: {$file}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function chmod_on_folders(string $dir, $kind) { |
||||
if (!is_dir($dir)) { |
||||
$exit_code = false; |
||||
} else { |
||||
$perm = get_perms($kind); |
||||
exec(self::get_user_bin . 'find ' . safe_cmd($dir) . ' -type d -exec ' . self::get_bin . 'chmod ' . $perm . ' {} \;', $output, $exit_code); |
||||
} |
||||
check_for_error($exit_code, "Unable to chmod folders in: {$dir}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function chmod_on_files(string $dir, $kind) { |
||||
if (!is_dir($dir)) { |
||||
$exit_code = false; |
||||
} else { |
||||
$perm = get_perms($kind); |
||||
exec(self::get_user_bin . 'find ' . safe_cmd($dir) . ' -type f -exec ' . self::get_bin . 'chmod ' . $perm . ' {} \;', $output, $exit_code); |
||||
} |
||||
check_for_error($exit_code, "Unable to chmod files in: {$dir}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function write_protect_file(string $file) { |
||||
if (!is_file($file)) { |
||||
$exit_code = false; |
||||
} else { |
||||
exec(self::get_user_bin . 'chattr +i ' . safe_cmd($file), $output, $exit_code); |
||||
} |
||||
check_for_error($exit_code, "Unable to write protect: {$file}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function unwrite_protect_file(string $file) { |
||||
if (!is_file($file)) { |
||||
$exit_code = false; |
||||
} else { |
||||
exec(self::get_user_bin . 'chattr -i ' . safe_cmd($file), $output, $exit_code); |
||||
} |
||||
check_for_error($exit_code, "Unable to un-write protect: {$file}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function groupadd(string $groupname, int $gid = 0) { |
||||
$group_id = ($gid > 0) ? "-g {$gid} " : ""; |
||||
exec(self::get_super_user_bin . 'groupadd '. $group_id . safe_cmd($groupname), $output, $exit_code); |
||||
if ($exit_code === true || $exit_code === 0) { |
||||
display(getTermColors("Added new group named: $groupname", ['color'=>'green'])); |
||||
} |
||||
check_for_error($exit_code, "Unable to add new group: {$groupname}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function userdel(string $username) { |
||||
exec(self::get_super_user_bin . 'userdel ' . safe_cmd($username), $output, $exit_code); |
||||
if ($exit_code === true || $exit_code === 0) { |
||||
display(getTermColors("Deleted user account named: $username", ['color'=>'green'])); |
||||
} |
||||
check_for_error($exit_code, "Unable to delete user: {$username}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function useradd(string $username, int $uid = 0, string $shell="/bin/bash", string $comment = "", string $groups="", string $homedir="") { |
||||
$user_id = ($uid > 0) ? "-u {$uid} " : ""; |
||||
$dir = (empty($homedir)) ? " -m " : " -d " . safe_cmd($homedir); |
||||
exec(self::get_super_user_bin . 'useradd '. $user_id . '-s '. safe_cmd($shell) . $dir . ' -c '. safe_cmd($comment) .'-G'. safe_cmd($groups) . ' ' . safe_cmd($username), $output, $exit_code); |
||||
if ($exit_code === true || $exit_code === 0) { |
||||
display(getTermColors("Added new user account named: $username", ['color'=>'green'])); |
||||
} |
||||
check_for_error($exit_code, "Unable to add new user: {$username}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function lock_status(string $username) { |
||||
exec(self::get_user_bin . 'passwd -S ' . safe_cmd($username) . " | awk '{print $2}'", $output, $exit_code); |
||||
$sw = $output[0] ?? ""; |
||||
switch ($sw) { |
||||
case "P": echo "Account is not locked"; break; |
||||
case "NP": echo "Account has no password"; break; |
||||
case "L": echo "Account is Locked"; break; |
||||
default: echo "Account does not exist?!"; break; |
||||
} |
||||
check_for_error($exit_code, "Unable to view account: {$username}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function passwd(string $username) { |
||||
exec(self::get_user_bin . 'passwd ' . safe_cmd($username), $output, $exit_code); |
||||
check_for_error($exit_code, "Unable to set user password: {$username}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
// Details about age of passwords |
||||
public static function chage(string $username) { |
||||
exec(self::get_user_bin . 'chage -l ' . safe_cmd($username), $output, $exit_code); |
||||
check_for_error($exit_code, "Unable to view user password changes: {$username}"); |
||||
return $exit_code; |
||||
} |
||||
// yyyy-mm-dd |
||||
public static function lock(string $username, string $expires_on="") { |
||||
$exp = (! empty($expires_on)) ? "--expiredate ". safe_cmd($expires_on) . " " : ""; |
||||
exec(self::get_super_user_bin . 'usermod -L '. $exp . safe_cmd($username), $output, $exit_code); |
||||
check_for_error($exit_code, "Unable to Lock user account: {$username}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function unlock(string $username, string $expires_on="") { |
||||
$exp = (! empty($expires_on)) ? "--expiredate ". safe_cmd($expires_on) . " " : "--expiredate '' "; |
||||
exec(self::get_super_user_bin . 'usermod -U ' . $exp . safe_cmd($username), $output, $exit_code); |
||||
check_for_error($exit_code, "Unable to Unlock user account: {$username}"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,168 @@ |
||||
<?php |
||||
|
||||
namespace traits; |
||||
|
||||
trait packages { |
||||
|
||||
private static function get_package_manager(string $os): string|false { |
||||
$linux_package_managers = [ |
||||
'ubuntu' => 'apt', |
||||
'debian' => 'apt_get', |
||||
'fedora' => 'dnf', |
||||
'centos' => 'yum', |
||||
'arch linux' => 'pacman', |
||||
'arch' => 'pacman', |
||||
'opensuse' => 'zypper', |
||||
'gentoo' => 'emerge', |
||||
'slackware' => 'slackpkg', |
||||
'rhel' => 'yum', |
||||
'mageia' => 'dnf', |
||||
'alpine linux' => 'apk', |
||||
'alpine' => 'apk', |
||||
'manjaro' => 'pacman', |
||||
'linux mint' => 'apt', |
||||
'elementary os' => 'apt', |
||||
'solus' => 'eopkg', |
||||
'void linux' => 'xbps_install', |
||||
'mx linux' => 'apt', |
||||
'kali linux' => 'apt', |
||||
'pclinuxos' => 'apt_get', |
||||
'funtoo' => 'emerge', |
||||
'fedora silverblue' => 'rpm_ostree', |
||||
// Add more distributions and their package managers as needed |
||||
]; |
||||
$selected_distribution = strtolower($os); |
||||
if (isset($linux_package_managers[$selected_distribution])) { |
||||
return $linux_package_managers[$selected_distribution]; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
private static function find_package_managers($pkg_mgr): string|false { |
||||
$list = [ |
||||
'nala'=>'/usr/bin/nala', |
||||
'apt'=>'/usr/bin/apt', |
||||
'apt_get'=>'/usr/bin/apt-get', |
||||
'dnf'=>'/usr/bin/dnf', |
||||
'yum'=>'/usr/bin/yum', |
||||
'pacman'=>'/usr/bin/pacman', |
||||
'zypper'=>'/usr/bin/zypper', |
||||
'flatpak'=>'/usr/bin/flatpak', |
||||
'snap'=>'/usr/bin/snap', |
||||
]; |
||||
foreach($list as $name=>$app) { |
||||
if (is_executable($app)) { |
||||
return $name; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
private static function get_OS_and_package_manager($pkg_mgr=false, $user_os = false) { |
||||
$pkg_name = self::find_package_managers($pkg_mgr); |
||||
if ($pkg_name !== false) { |
||||
return $pkg_name; |
||||
} |
||||
$os = $GLOBALS['os']; |
||||
$detected_os = $os['id'] ?? "ubuntu"; |
||||
$selected_OS = ($user_os !== false) ? $user_os : $detected_os; |
||||
return self::get_package_manager($selected_OS); |
||||
} |
||||
|
||||
public static function is_installed(string $prog, $pkg_mgr=false, $user_os = false) { |
||||
$pkg = self::get_OS_and_package_manager($pkg_mgr, $user_os); |
||||
if ($pkg === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\package_managers\\{$pkg}::is_installed"; |
||||
return $namespaced($prog); |
||||
} |
||||
|
||||
public static function upgrade(string $prog, $pkg_mgr=false, $user_os = false) { |
||||
$pkg = self::get_OS_and_package_manager($pkg_mgr, $user_os); |
||||
if ($pkg === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\package_managers\\{$pkg}::upgrade"; |
||||
return $namespaced($prog); |
||||
} |
||||
|
||||
public static function install(string $prog, $pkg_mgr=false, $user_os = false) { |
||||
$pkg = self::get_OS_and_package_manager($pkg_mgr, $user_os); |
||||
if ($pkg === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\package_managers\\{$pkg}::install"; |
||||
return $namespaced($prog); |
||||
} |
||||
|
||||
public static function purge(string $prog, $pkg_mgr=false, $user_os = false) { |
||||
$pkg = self::get_OS_and_package_manager($pkg_mgr, $user_os); |
||||
if ($pkg === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\package_managers\\{$pkg}::purge"; |
||||
return $namespaced($prog); |
||||
|
||||
} |
||||
|
||||
public static function uninstall(string $prog, $pkg_mgr=false, $user_os = false) { |
||||
$pkg = self::get_OS_and_package_manager($pkg_mgr, $user_os); |
||||
if ($pkg === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\package_managers\\{$pkg}::uninstall"; |
||||
return $namespaced($prog); |
||||
|
||||
} |
||||
|
||||
public static function add_repo(string $repo, $pkg_mgr=false, $user_os = false) { |
||||
$pkg = self::get_OS_and_package_manager($pkg_mgr, $user_os); |
||||
if ($pkg === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\package_managers\\{$pkg}::add_repo"; |
||||
return $namespaced($prog); |
||||
|
||||
} |
||||
|
||||
public static function update($pkg_mgr=false, $user_os = false) { |
||||
$pkg = self::get_OS_and_package_manager($pkg_mgr, $user_os); |
||||
if ($pkg === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\package_managers\\{$pkg}::update"; |
||||
return $namespaced($prog); |
||||
|
||||
} |
||||
|
||||
public static function full_update($pkg_mgr=false, $user_os = false) { |
||||
$pkg = self::get_OS_and_package_manager($pkg_mgr, $user_os); |
||||
if ($pkg === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\package_managers\\{$pkg}::full_update"; |
||||
return $namespaced($prog); |
||||
} |
||||
|
||||
// Have a Backup!! |
||||
public static function full_system_upgrade($pkg_mgr=false, $user_os = false) { |
||||
$pkg = self::get_OS_and_package_manager($pkg_mgr, $user_os); |
||||
if ($pkg === false) { |
||||
return false; |
||||
} |
||||
$namespaced = "\\package_managers\\{$pkg}::full_system_upgrade"; |
||||
return $namespaced($prog); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
/* |
||||
osInfo[/etc/redhat-release]="yum install" |
||||
osInfo[/etc/arch-release]="pacman -S" |
||||
osInfo[/etc/gentoo-release]="emerge" |
||||
osInfo[/etc/SuSE-release]="zypper install" |
||||
osInfo[/etc/debian_version]="apt install" |
||||
osInfo[/etc/alpine-release]="apk add --no-cache" |
||||
*/ |
||||
@ -0,0 +1,50 @@ |
||||
<?php |
||||
|
||||
namespace utils; |
||||
|
||||
class php_composer { |
||||
|
||||
const composer_exe = "/usr/local/bin/composer"; |
||||
|
||||
public static function init($dir) { |
||||
chdir($dir); |
||||
exec(self::composer_exe . " init", $output, $exit_code); |
||||
check_for_error($exit_code, "PHP Composer init error"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function install($dir) { |
||||
chdir($dir); |
||||
exec(self::composer_exe . " install", $output, $exit_code); |
||||
check_for_error($exit_code, "PHP Composer init error"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function update($dir) { |
||||
chdir($dir); |
||||
exec(self::composer_exe . " update", $output, $exit_code); |
||||
check_for_error($exit_code, "PHP Composer init error"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function require($dir, $vendor) { |
||||
chdir($dir); |
||||
exec(self::composer_exe . " require " . safe_cmd($vendor), $output, $exit_code); |
||||
check_for_error($exit_code, "PHP Composer init error"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function remove($dir, $vendor) { |
||||
chdir($dir); |
||||
exec(self::composer_exe . " remove " . safe_cmd($vendor), $output, $exit_code); |
||||
check_for_error($exit_code, "PHP Composer init error"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
public static function self_update() { |
||||
exec(self::composer_exe . " self-update", $output, $exit_code); |
||||
check_for_error($exit_code, "PHP Composer init error"); |
||||
return $exit_code; |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue