Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base: 3dcee1334c
...
compare: 1ac11edaa2
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
21 apps/htoad/src/htoad_pkg.erl
View
@@ -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}) ->
22 apps/htoad/src/htoad_pkg_yum.erl
View
@@ -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)).
4 apps/htoad/src/htoad_shell.erl
View
@@ -19,7 +19,7 @@ user(Engine, {output, #shell{ cmd = "id" }, Result}) ->
#group{ id = list_to_integer(Gid), name = Group }]).
superuser(Engine, #init{}, {operating_system_type, unix},
- {user, "root"}) ->
+ #user{ name = "root" }) ->
htoad:assert(Engine, {?MODULE, superuser}).
command_run_in_superuser(Engine, #shell{ run_as = superuser } = Shell,
@@ -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]),

No commit comments for this range

Something went wrong with that request. Please try again.