diff --git a/lib.cf b/lib.cf index 3ec6871..d012941 100644 --- a/lib.cf +++ b/lib.cf @@ -288,3 +288,74 @@ methods: reports: } + + +bundle agent download_file(method,src,dst,cls,prms_arg) +{ +vars: + "prms_default" data => '{ + "m":"600", + "o":"$(sys.user_data[uid])", + "g":"$(sys.user_data[gid])" + }'; + + "prms" data => mergedata(@(prms_default),parsejson($(prms_arg))); + +classes: + "$(method)"; + wget:: + "run_wget" expression => not(fileexists($(dst))); + +files: + policyhub:: + "$(dst)" + copy_from => remote_dcp("$(src)","$(sys.policy_hub)"), + classes => if_repaired("$(cls)_repaired"), + perms => mog ("$(prms[m])","$(prms[o])","$(prms[g])"); +methods: + wget:: + "any" usebundle => "install_wget", handle=>"wget_installed"; + +commands: + run_wget:: + "$(wget.exe)" + args => "-q -O $(dst) $(src) || (rm -f $(dst) && /usr/bin/false) ", + contain => wmde_cmd_useshell, + handle => "$(cls)_downloaded", + classes => results("namespace","$(cls)"), + depends_on => {"wget_installed"}, + inform => "true"; + + "/usr/bin/true" + depends_on => {"$(cls)_downloaded"}, + classes => if_repaired("$(cls)_kept"); + + + (!run_wget)&(wget):: + "/usr/bin/true" + classes => if_repaired("$(cls)_kept"); + + +files: + "$(dst)" + perms => mog ("$(prms[m])","$(prms[o])","$(prms[g])"), + depends_on => {"$(cls)_downloaded"}; + +reports: + !run_wget:: + "Not run wget"; + run_wget:: + "Run wget"; + + "$(cls)_repaired":: + "$(cls) repaired"; + "!($(cls)_repaired)":: + "$(cls) not repaired"; + + "$(cls)_kept":: + "$(cls) kept"; + "!($(cls)_kept)":: + "$(cls) not kept"; +} + +