From fb1f307d052d82d17f50af62fd93e08b01ad7d2a Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 14 Dec 2023 06:40:59 -0500 Subject: [PATCH] init & pkg mgrs... --- README.md | 3 + app/OS/neato_Alpine.php | 103 +--------------- app/OS/neato_Linux_Generic.php | 20 ++++ app/OS/neato_Ubuntu.php | 198 +------------------------------ app/init_systems/open_rc.php | 44 +++++++ app/init_systems/runit.php | 34 ++++++ app/init_systems/sys_v_init.php | 45 +++++++ app/init_systems/systemd.php | 59 +++++++++ app/neato.php | 15 +-- app/neato_common.php | 3 + app/package_managers/apk.php | 53 +++++++++ app/package_managers/apt.php | 68 +++++++++++ app/package_managers/apt_get.php | 68 +++++++++++ app/package_managers/dnf.php | 57 +++++++++ app/package_managers/flatpak.php | 66 +++++++++++ app/package_managers/nala.php | 99 ++++++++++++++++ app/package_managers/pacman.php | 57 +++++++++ app/package_managers/snap.php | 91 ++++++++++++++ app/package_managers/yum.php | 57 +++++++++ app/traits/init_systems.php | 41 +++++++ app/traits/linux_core.php | 128 ++++++++++++++++++++ app/traits/packages.php | 168 ++++++++++++++++++++++++++ app/utils/php_composer.php | 50 ++++++++ 23 files changed, 1229 insertions(+), 298 deletions(-) create mode 100644 app/OS/neato_Linux_Generic.php create mode 100644 app/init_systems/open_rc.php create mode 100644 app/init_systems/runit.php create mode 100644 app/init_systems/sys_v_init.php create mode 100644 app/init_systems/systemd.php create mode 100644 app/package_managers/apk.php create mode 100644 app/package_managers/apt.php create mode 100644 app/package_managers/apt_get.php create mode 100644 app/package_managers/dnf.php create mode 100644 app/package_managers/flatpak.php create mode 100644 app/package_managers/nala.php create mode 100644 app/package_managers/pacman.php create mode 100644 app/package_managers/snap.php create mode 100644 app/package_managers/yum.php create mode 100644 app/traits/init_systems.php create mode 100644 app/traits/linux_core.php create mode 100644 app/traits/packages.php create mode 100644 app/utils/php_composer.php diff --git a/README.md b/README.md index 58ed6eb..86c2686 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ ``` $ git clone https://git.mysnippetsofcode.com/tts/neatoDeploy.git $ cd neatoDeploy +$ nano app/neato.php +# Change the line that reads $pk = "Passphase"; // XOR for sha256sum, CHANGE ME!! +# Save it, then run: $ ./make-installer.sh ``` Then scp over the neato_deploy.tar.gz.self to your sever. diff --git a/app/OS/neato_Alpine.php b/app/OS/neato_Alpine.php index a287b25..78a647b 100644 --- a/app/OS/neato_Alpine.php +++ b/app/OS/neato_Alpine.php @@ -1,6 +1,10 @@ true, 'version' => $out] : ['installed' => false]; - } - - public static function service($name, $action = 'restart') { - exec(self::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; - } - // actions: add or del - public static function systemctl($name, $action = 'add') { - exec(self::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; - } - - public static function upgrade($prog) { - exec(self::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(self::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(self::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(self::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(self::get_user_bin . 'apk update -y ' . stderr(), $output, $exit_code); - display($output); - return $exit_code; - } - - public static function full_update() { - exec(self::get_user_bin . 'apk update -y && ' . self::get_user_bin . 'apk upgrade -y' . stderr(), $output, $exit_code); - display($output); - return $exit_code; - } - - public static function chmod_on_folders($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($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($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($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; - } } diff --git a/app/OS/neato_Linux_Generic.php b/app/OS/neato_Linux_Generic.php new file mode 100644 index 0000000..b32bfb1 --- /dev/null +++ b/app/OS/neato_Linux_Generic.php @@ -0,0 +1,20 @@ + true, 'version' => $version] : ['installed' => false]; - } - - public static function service(string $name, string $action = 'restart') { - exec(self::get_super_user_bin . '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(string $name, string $action = 'enable') { - exec(self::get_bin . 'systemctl ' . safe_cmd($action, $name), $output, $exit_code); - check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); - return $exit_code; - } - - public static function upgrade(string $prog) { - exec(self::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(self::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(self::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(self::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(self::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(self::get_user_bin . 'apt-get update -y ' . stderr(), $output, $exit_code); - display($output); - return $exit_code; - } - - public static function full_update() { - exec(self::get_user_bin . 'apt-get update -y && '. self::get_user_bin . 'apt-get upgrade -y && ' . self::get_user_bin . 'apt-get autoremove -y && ' . self::get_user_bin . 'apt-get autoclean -y' . stderr(), $output, $exit_code); - display($output); - return $exit_code; - } - - 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; - } + protected function __construct() { } } diff --git a/app/init_systems/open_rc.php b/app/init_systems/open_rc.php new file mode 100644 index 0000000..2c03f74 --- /dev/null +++ b/app/init_systems/open_rc.php @@ -0,0 +1,44 @@ +'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; + } + +} diff --git a/app/init_systems/runit.php b/app/init_systems/runit.php new file mode 100644 index 0000000..a52f60d --- /dev/null +++ b/app/init_systems/runit.php @@ -0,0 +1,34 @@ +'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); + } + +} diff --git a/app/init_systems/sys_v_init.php b/app/init_systems/sys_v_init.php new file mode 100644 index 0000000..018df48 --- /dev/null +++ b/app/init_systems/sys_v_init.php @@ -0,0 +1,45 @@ +'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; + } + + +} diff --git a/app/init_systems/systemd.php b/app/init_systems/systemd.php new file mode 100644 index 0000000..3879761 --- /dev/null +++ b/app/init_systems/systemd.php @@ -0,0 +1,59 @@ +'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; + } + +} diff --git a/app/neato.php b/app/neato.php index 7d2d568..1a6e2af 100644 --- a/app/neato.php +++ b/app/neato.php @@ -9,7 +9,7 @@ $cwd = getcwd(); $pk = "@ghsP4JAuhCUxEGpk2y;mP"; // XOR for sha256sum, CHANGE ME!! if (!isset($argv[1])) { - echo 'Please give Script to run, example: neatoDeploy apache' . PHP_EOL; + echo 'Please give Script to run, example: ./neato_deploy.sh apache' . PHP_EOL; echo "Note: deploy_ is added to the beginning of the filename and .php is added to the end!" . PHP_EOL; echo "Also, the deployment file must be in the same path if local file." . PHP_EOL; echo "Insecure: you may pass a http web site text file: IE http://mysite.com/apache.txt" . PHP_EOL; @@ -20,16 +20,17 @@ define('CONFIG_FILE', basename($argv[1]) ); require "neato_common.php"; -if (! isset($os['id'])) { - echo 'Unknown OS'; - exit(1); -} - if ($os_like == 'debian') { putenv("DEBIAN_FRONTEND=noninteractive"); } -require 'OS/neato_' . ucfirst($os['id']) . '.php'; +if (isset($os['id']) && file_exists('OS/neato_' . ucfirst($os['id']) . '.php')) { + include 'OS/neato_' . ucfirst($os['id']) . '.php'; +} else { + $is_Linux = $os['linux'] ?? true; + $generic_OS_file = ($is_Linux) ? 'OS/neato_Linux_Generic.php' : 'OS/neato_Windows_Generic.php'; + include $generic_OS_file; +} function clean_file_name(string & $file) { $file = str_replace("deploy_", "", $file); diff --git a/app/neato_common.php b/app/neato_common.php index 00a60b6..415b309 100644 --- a/app/neato_common.php +++ b/app/neato_common.php @@ -16,6 +16,9 @@ configure::set('logger_time_zone', 'America/Detroit'); registry::set('loader', new \Psr4AutoloaderClass); registry::get('loader')->register(); registry::get('loader')->add_namespace('utils', 'utils'); +registry::get('loader')->add_namespace('traits', 'traits'); +registry::get('loader')->add_namespace('package_managers', 'package_managers'); +registry::get('loader')->add_namespace('init_systems', 'init_systems'); function force_root(): void { if (posix_getuid() > 0) { diff --git a/app/package_managers/apk.php b/app/package_managers/apk.php new file mode 100644 index 0000000..82abdc5 --- /dev/null +++ b/app/package_managers/apk.php @@ -0,0 +1,53 @@ + 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; + } + +} \ No newline at end of file diff --git a/app/package_managers/apt.php b/app/package_managers/apt.php new file mode 100644 index 0000000..0e90ce3 --- /dev/null +++ b/app/package_managers/apt.php @@ -0,0 +1,68 @@ + 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; + } + +} \ No newline at end of file diff --git a/app/package_managers/apt_get.php b/app/package_managers/apt_get.php new file mode 100644 index 0000000..217354b --- /dev/null +++ b/app/package_managers/apt_get.php @@ -0,0 +1,68 @@ + 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; + } + +} \ No newline at end of file diff --git a/app/package_managers/dnf.php b/app/package_managers/dnf.php new file mode 100644 index 0000000..cc34c50 --- /dev/null +++ b/app/package_managers/dnf.php @@ -0,0 +1,57 @@ + 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; + } + +} \ No newline at end of file diff --git a/app/package_managers/flatpak.php b/app/package_managers/flatpak.php new file mode 100644 index 0000000..f3ca79f --- /dev/null +++ b/app/package_managers/flatpak.php @@ -0,0 +1,66 @@ + 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; + } + +} \ No newline at end of file diff --git a/app/package_managers/nala.php b/app/package_managers/nala.php new file mode 100644 index 0000000..4e0f39a --- /dev/null +++ b/app/package_managers/nala.php @@ -0,0 +1,99 @@ + 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; + } + +} \ No newline at end of file diff --git a/app/package_managers/pacman.php b/app/package_managers/pacman.php new file mode 100644 index 0000000..4f43f48 --- /dev/null +++ b/app/package_managers/pacman.php @@ -0,0 +1,57 @@ + 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; + } + +} \ No newline at end of file diff --git a/app/package_managers/snap.php b/app/package_managers/snap.php new file mode 100644 index 0000000..74d86ff --- /dev/null +++ b/app/package_managers/snap.php @@ -0,0 +1,91 @@ + 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; + } + +} \ No newline at end of file diff --git a/app/package_managers/yum.php b/app/package_managers/yum.php new file mode 100644 index 0000000..bd17e93 --- /dev/null +++ b/app/package_managers/yum.php @@ -0,0 +1,57 @@ + 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; + } + +} \ No newline at end of file diff --git a/app/traits/init_systems.php b/app/traits/init_systems.php new file mode 100644 index 0000000..eb0f7df --- /dev/null +++ b/app/traits/init_systems.php @@ -0,0 +1,41 @@ +'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); + } + +} diff --git a/app/traits/linux_core.php b/app/traits/linux_core.php new file mode 100644 index 0000000..c6e16a1 --- /dev/null +++ b/app/traits/linux_core.php @@ -0,0 +1,128 @@ + 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; + } + +} \ No newline at end of file diff --git a/app/traits/packages.php b/app/traits/packages.php new file mode 100644 index 0000000..50ed3ce --- /dev/null +++ b/app/traits/packages.php @@ -0,0 +1,168 @@ + '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" +*/ \ No newline at end of file diff --git a/app/utils/php_composer.php b/app/utils/php_composer.php new file mode 100644 index 0000000..d6aeff4 --- /dev/null +++ b/app/utils/php_composer.php @@ -0,0 +1,50 @@ +