Permalink
Browse files

Add support for yum

  • Loading branch information...
1 parent eaa9c6c commit 77399ba8b304d46774df7d2a735f40fa9bcd70e9 @DeadZen committed Feb 6, 2012
Showing with 47 additions and 0 deletions.
  1. +1 −0 apps/htoad/src/htoad.app.src
  2. +46 −0 apps/htoad/src/htoad_pkg_yum.erl
@@ -25,6 +25,7 @@
htoad_lfs,
htoad_deps,
htoad_pkg,
+ htoad_pkg_yum,
htoad_pkg_brew,
htoad_pkg_apt,
htoad_io,
@@ -0,0 +1,46 @@
+-module(htoad_pkg_yum).
+-include_lib("htoad/include/htoad.hrl").
+-include_lib("htoad/include/toadie.hrl").
+-include_lib("htoad/include/stdlib.hrl").
+
+-rules([init, ensure_package, package_not_present]).
+
+init(Engine, #init{}, {operating_system_name, linux}, {linux_distribution, "RedHat"}) ->
+ initialize(Engine);
+init(Engine, #init{}, {operating_system_name, linux}, {linux_distribution, "CentOS"}) ->
+ initialize(Engine).
+
+initialize(Engine) ->
+ lager:info("YUM has been selected as a package manager"),
+ htoad:assert(Engine, {package_manager, yum}).
+
+
+-define(YUM_SHELL_CHECK(Package),
+ case Package of
+ #package{ name = Name, version = undefined } ->
+ #shell{ cmd = "yum -q list installed " ++ Name ++
+ " 1>/dev/null 2>/dev/null && printf present || printf missing"};
+ #package{ name = Name, version = Version } ->
+ #shell{ cmd = "yum -q list installed " ++ Name ++ "-" ++ Version ++
+ " 1>/dev/null 2>/dev/null && printf present || printf missing"}
+ end).
+
+-define(YUM_SHELL_INSTALL(Package),
+ case Package of
+ #package{ name = Name, version = undefined } ->
+ #shell{ cmd = "yum -y install " ++ Name ++
+ " 1>/dev/null 2>/dev/null && printf installed || printf not_installed",
+ run_as = superuser };
+ #package{ name = Name, version = Version } ->
+ #shell{ cmd = "yum -y install " ++ Name ++ "-" ++ Version ++
+ " 1>/dev/null 2>/dev/null && printf installed || printf not_installed",
+ run_as = superuser }
+ end).
+
+ensure_package(Engine, {ensure, present, #package{} = Package}, {package_manager, yum}) ->
+ htoad_pkg:ensure_package(Engine, Package, ?YUM_SHELL_CHECK(Package)).
+
+package_not_present(Engine, {package_check,
+ #package{} = Package,
+ "missing"}, {package_manager, yum}) ->
+ htoad_pkg:package_not_present(Engine, Package, ?YUM_SHELL_INSTALL(Package)).

0 comments on commit 77399ba

Please sign in to comment.