let generic_installation
~(run_program : Machine.Make_fun.t)
~host ~install_path
~install_program ~witness ~url
?unarchived_directory
?(archive_is_directory = true)
tool_name =
let archive = Filename.basename url in
let archive_kind =
if Filename.check_suffix url "bz2" then `Tar "j"
else if Filename.check_suffix url "gz" then `Tar "z"
else if Filename.check_suffix url "tar" then `Tar ""
else if Filename.check_suffix url "zip" then `Zip
else if Filename.check_suffix url "deb" then `Deb
else `None
in
let open KEDSL in
let unarchival =
let open Program in
let and_cd =
if archive_is_directory then
[shf "cd %s" (Option.value unarchived_directory
~default:(tool_name ^ "*"))]
else [] in
match archive_kind with
| `Tar tar_option ->
chain ([shf "tar xvf%s %s" tar_option archive;
shf "rm -f %s" archive; ] @ and_cd)
| `Zip ->
chain ([shf "unzip %s" archive; shf "rm -f %s" archive;] @ and_cd)
| `Deb ->
chain [
exec ["ar"; "x"; archive];
exec ["tar"; "xvfz"; "data.tar.gz"];
exec ["rm"; "-f"; "data.tar.gz"];
]
| `None -> sh "echo Not-an-archive"
in
workflow_node
~name:(sprintf "Install %s" tool_name)
witness
~edges:[
on_failure_activate (rm_path ~host install_path);
]
~make:(
run_program
~requirements:[
`Internet_access;
`Self_identification ["generic-instalation"; tool_name];
]
Program.(
shf "mkdir -p %s" install_path
&& shf "cd %s" install_path
&& Workflow_utilities.Download.wget_program url
&& unarchival
&& install_program
&& sh "echo Done"
))