diff options
author | Renato Botelho <renato@netgate.com> | 2015-10-20 16:10:54 -0200 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2015-10-20 16:19:50 -0200 |
commit | 8df1877b704f9d5cd788def274ff7ffa5349dc23 (patch) | |
tree | 5ae5a36aa9e4a7788a015df332776f9b399648ce /src/etc | |
parent | cd51e4f60e706e2c0e13f50935ca4c006898677a (diff) | |
download | pfsense-8df1877b704f9d5cd788def274ff7ffa5349dc23.zip pfsense-8df1877b704f9d5cd788def274ff7ffa5349dc23.tar.gz |
Add pkg_version_compare()
Diffstat (limited to 'src/etc')
-rw-r--r-- | src/etc/inc/pkg-utils.inc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/etc/inc/pkg-utils.inc b/src/etc/inc/pkg-utils.inc index fee93fd..147d550 100644 --- a/src/etc/inc/pkg-utils.inc +++ b/src/etc/inc/pkg-utils.inc @@ -283,6 +283,26 @@ function pkg_exec($params, &$stdout, &$stderr) { return proc_close($process); } +/* Compare 2 pkg versions and return: + * '=' - versions are the same + * '>' - $v1 > $v2 + * '<' - $v1 < $v2 + * '?' - Error + */ +function pkg_version_compare($v1, $v2) { + if (empty($v1) || empty($v2)) { + return '?'; + } + + $rc = pkg_exec("version -t '{$v1}' '{$v2}'", $stdout, $stderr); + + if ($rc != 0) { + return '?'; + } + + return str_replace("\n", "", $stdout); +} + /* Check if package is installed */ function is_pkg_installed($pkg_name) { global $g; |