let wget_untar
~host ~(run_program : Machine.Make_fun.t)
~destination_folder ~tar_contains url =
let open KEDSL in
let zip_flags =
let is_gz = Filename.check_suffix url ".gz" in
let is_bzip = Filename.check_suffix url ".bz2" in
if is_gz then "z" else if is_bzip then "j" else ""
in
let tar_filename = (destination_folder // "archive.tar") in
let name = "untar-" ^ tar_filename in
let wgot = wget ~host ~run_program url tar_filename in
let file_in_tar = (destination_folder // tar_contains) in
workflow_node
(single_file file_in_tar ~host)
~edges:[
depends_on (wgot);
on_failure_activate (Remove.path_on_host ~host destination_folder);
]
~name
~make:(
run_program ~name
~requirements:(Machine.Make_fun.stream_processor [])
Program.(
exec ["mkdir"; "-p"; destination_folder]
&& shf "tar -x%s -f %s -C %s"
zip_flags
(Filename.quote wgot#product#path)
(Filename.quote destination_folder)))