You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
4.0 KiB
120 lines
4.0 KiB
<?php
|
|
|
|
final class neato {
|
|
|
|
const get_opt = '/opt/';
|
|
const get_etc = '/etc/';
|
|
const get_bin = '/bin/';
|
|
const get_super_bin = '/sbin/';
|
|
const get_user_bin = '/usr/bin/';
|
|
const get_super_user_bin = '/usr/sbin/';
|
|
const get_user_local_bin = '/usr/local/bin/';
|
|
|
|
protected function __construct() {
|
|
|
|
}
|
|
|
|
public static function is_installed($prog) {
|
|
exec(self::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 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;
|
|
}
|
|
|
|
}
|
|
|
|
// end of neato installer commands
|
|
|