Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix command bug in superuser assertion and add {ensure, absent to yum

  • Loading branch information...
commit 1ac11edaa22f486d717ebdbdc1d160565e5b5f3d 1 parent 64d2c31
@DeadZen authored
View
21 apps/htoad/src/htoad_pkg.erl
@@ -3,7 +3,7 @@
-include_lib("htoad/include/toadie.hrl").
-include_lib("htoad/include/stdlib.hrl").
--export([ensure_package/3, package_not_present/3]).
+-export([ensure_package/3, remove_package/3, package_not_present/3, package_present/3]).
-export([format_package/1]).
-rules([package_present]).
@@ -26,6 +26,18 @@ ensure_package(Engine, #package{} = Package, Command) ->
{package_check, Package, '_'})
]).
+remove_package(Engine, #package{} = Package, Command) ->
+ lager:debug("Checking if package ~s should be removed",[format_package(Package)]),
+ htoad:assert(Engine,
+ [
+ Command,
+ htoad_utils:on({match,
+ [{{output, Command, '$1'},
+ [],
+ ['$1']}]},
+ {package_remove, Package, '_'})
+ ]).
+
package_not_present(Engine, #package{} = Package, Command) ->
lager:debug("Package ~s is absent, installing",[format_package(Package)]),
htoad:assert(Engine, [Command, htoad_utils:on({match,
@@ -33,6 +45,13 @@ package_not_present(Engine, #package{} = Package, Command) ->
[],
[true]}]}, Package)]).
+package_present(Engine, #package{} = Package, Command) ->
+ lager:debug("Package ~s is present, removing",[format_package(Package)]),
+ htoad:assert(Engine, [Command, htoad_utils:on({match,
+ [{{output, Command, "removed"},
+ [],
+ [true]}]}, Package)]).
+
format_package(#package{ name = Name, version = undefined }) ->
Name;
format_package(#package{ name = Name, version = Version}) ->
View
22 apps/htoad/src/htoad_pkg_yum.erl
@@ -3,7 +3,7 @@
-include_lib("htoad/include/toadie.hrl").
-include_lib("htoad/include/stdlib.hrl").
--rules([init, ensure_package, package_not_present]).
+-rules([init, ensure_package, remove_package, package_not_present, package_present]).
init(Engine, #init{}, {operating_system_name, linux}, {linux_distribution, "RedHat"}) ->
initialize(Engine);
@@ -37,10 +37,30 @@ initialize(Engine) ->
run_as = superuser }
end).
+-define(YUM_SHELL_REMOVE(Package),
+ case Package of
+ #package{ name = Name, version = undefined } ->
+ #shell{ cmd = "yum -y remove " ++ Name ++
+ " 1>/dev/null 2>/dev/null && printf removed || printf not_removed",
+ run_as = superuser };
+ #package{ name = Name, version = Version } ->
+ #shell{ cmd = "yum -y remove " ++ Name ++ "-" ++ Version ++
+ " 1>/dev/null 2>/dev/null && printf removed || printf not_removed",
+ run_as = superuser }
+ end).
+
ensure_package(Engine, {ensure, present, #package{} = Package}, {package_manager, yum}) ->
htoad_pkg:ensure_package(Engine, Package, ?YUM_SHELL_CHECK(Package)).
+remove_package(Engine, {ensure, absent, #package{} = Package}, {package_manager, yum}) ->
+ htoad_pkg:remove_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)).
+
+package_present(Engine, {package_remove,
+ #package{} = Package,
+ "present"}, {package_manager, yum}) ->
+ htoad_pkg:package_present(Engine, Package, ?YUM_SHELL_REMOVE(Package)).
View
2  apps/htoad/src/htoad_shell.erl
@@ -35,7 +35,7 @@ command_run_as_superuser(Engine, #shell{ cmd = Cmd, run_as = superuser } = Shell
htoad:assert(Engine, {output, Shell, Result}).
-command(Engine, #shell{ cmd = Cmd, run_as = undefined } = Shell) ->
+command(Engine, #shell{ cmd = Cmd, run_as = _ } = Shell) ->
lager:debug("Executing shell command: ~s", [Cmd]),
Result = string:strip(os:cmd(Cmd), right, $\n),
lager:debug("Shell output for `~s`: ~s", [Cmd, Result]),
Please sign in to comment.
Something went wrong with that request. Please try again.