download_file bundle added

This commit is contained in:
Tube 2023-11-01 15:58:35 +01:00
parent 504a72a48c
commit 8eb884a046
1 changed files with 71 additions and 0 deletions

71
lib.cf
View File

@ -288,3 +288,74 @@ methods:
reports: 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";
}