From 66cb933b898924d35e1b19c08b46c541eeaaea4a Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Sat, 21 Mar 2015 01:01:24 +0000 Subject: [PATCH 1/7] Fix has_command by not going through a subshell ``` $ command -v fooooo $ echo $? 1 $ /bin/sh -c command -v foooo $ echo $? 0 ``` We now just call `command` directly, which fixes #6 --- depext.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depext.ml b/depext.ml index 3085630..63f4629 100644 --- a/depext.ml +++ b/depext.ml @@ -41,7 +41,7 @@ let string_split char str = aux 0 let has_command c = - let cmd = Printf.sprintf "/bin/sh -c command -v %s" c in + let cmd = Printf.sprintf "command -v %s" c in try Sys.command cmd = 0 with Sys_error _ -> false let run_command c = From 0541f628dc8994d5d2494beaf544d2404634dc9e Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Sat, 21 Mar 2015 01:05:04 +0000 Subject: [PATCH 2/7] bump the working version of depext to 0.4 --- opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opam b/opam index e6c7357..6063328 100644 --- a/opam +++ b/opam @@ -1,6 +1,6 @@ opam-version: "1.2" name: "depext" -version: "0.1" +version: "0.4" maintainer: "Louis Gesbert " authors: "Louis Gesbert " homepage: "https://github.com/AltGr/opam-depext" From 0c75ffabff8e836adc5f6b6b31257b904420df7b Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Sat, 21 Mar 2015 01:14:11 +0000 Subject: [PATCH 3/7] Fix CentOS depext The distribution name is "CentOS", not "Centos". Just force lowercase comparison to simplify this, as this may have varied between CentOS 6 and 7. Also improve the error message to distinguish between an unknown distribution and other parsing error. --- depext.ml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/depext.ml b/depext.ml index 63f4629..527ad8f 100644 --- a/depext.ml +++ b/depext.ml @@ -90,12 +90,12 @@ let distribution = function in List.hd (string_split ' ' (List.hd (lines_of_file release_file))) in - match name with - | "Debian" -> Some `Debian - | "Ubuntu" -> Some `Ubuntu - | "Centos" -> Some `Centos - | "Fedora" -> Some `Fedora - | "Mageia" -> Some `Mageia + match String.lowercase name with + | "debian" -> Some `Debian + | "ubuntu" -> Some `Ubuntu + | "centos" -> Some `Centos + | "fedora" -> Some `Fedora + | "mageia" -> Some `Mageia | s -> Some (`Other s) with Not_found | Failure _ -> None) | _ -> None @@ -168,7 +168,9 @@ let install_packages_command distribution packages = "pkg"::"install"::packages | Some (`OpenBSD | `NetBSD) -> "pkg_add"::packages - | _ -> + | Some (`Other d) -> + failwith ("Sorry, don't know how to install packages on your " ^ d ^ " system") + | None -> failwith "Sorry, don't know how to install packages on your system" let sudo os distribution cmd = match os, distribution with From bdf10cf2f178ab60fd777c7673e0caf9754a8a4e Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Sat, 21 Mar 2015 10:16:24 +0000 Subject: [PATCH 4/7] Do not double-escape in run_command, which fixes source depexts --- depext.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depext.ml b/depext.ml index 527ad8f..2c3f7bb 100644 --- a/depext.ml +++ b/depext.ml @@ -45,7 +45,7 @@ let has_command c = try Sys.command cmd = 0 with Sys_error _ -> false let run_command c = - let c = String.concat " " (List.map (Printf.sprintf "%S") c) in + let c = String.concat " " (List.map (Printf.sprintf "%s") c) in if !debug then Printf.eprintf "+ %s\n%!" c; Unix.system c From 50e2f28861bd815fe4014ef604ccd5801a3fdfb9 Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Sun, 22 Mar 2015 09:43:03 +0000 Subject: [PATCH 5/7] Add `-u` to trigger an OS update before external dependency installation. This is useful on Debian or Ubuntu where package installation may fail if the sets are not up-to-date with respect to latest security updates. --- depext.ml | 30 ++++++++++++++++++++++++++---- opam | 3 ++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/depext.ml b/depext.ml index 2c3f7bb..086382d 100644 --- a/depext.ml +++ b/depext.ml @@ -184,6 +184,23 @@ let sudo os distribution cmd = match os, distribution with ) else cmd | _ -> cmd +let update_command = function + | Some (`Debian | `Ubuntu) -> + ["apt-get";"update"] + | Some (`Homebrew) -> + ["brew"; "update"] + | Some (`Centos | `Fedora | `Mageia) -> + ["yum"; "update"] + | _ -> ["echo"; "Skipping system update on this platform."] + +let update os distribution = + let cmd = update_command distribution in + let cmd = sudo os distribution cmd in + match run_command cmd with + | Unix.WEXITED 0 -> + Printf.printf "# OS package update successful\n%!" + | _ -> failwith "OS package update failed" + let install os distribution = function | [] -> () | os_packages -> @@ -216,7 +233,7 @@ let run_source_scripts = function (* Command-line handling *) -let main print_flags list short no_sources debug_arg install_arg opam_packages = +let main print_flags list short no_sources debug_arg install_arg update_arg opam_packages = if debug_arg then debug := true; let arch = arch () in let os = os () in @@ -246,7 +263,8 @@ let main print_flags list short no_sources debug_arg install_arg opam_packages = Printf.printf "# The following scripts need to be run:\n# - %s\n%!" (String.concat "\n# - " source_urls); if os_packages = [] && source_urls = [] then - Printf.printf "# No extra OS packages requirements found.\n%!"; + Printf.printf "# No extra OS packages requirements found.\n%!" + else (if update_arg then update os distribution); install os distribution os_packages; run_source_scripts source_urls; if install_arg && opam_packages <> [] then @@ -281,6 +299,10 @@ let debug_arg = Arg.(value & flag & info ~doc:"Print commands that are run by the program" ["d";"debug"]) +let update_arg = + Arg.(value & flag & + info ~doc:"Update the OS package sets before installation" ["u";"update"]) + let install_arg = Arg.(value & flag & info ~doc:"Install the packages through \"opam install\" after \ @@ -304,9 +326,9 @@ let command = ] in let doc = "Query and install external dependencies of OPAM packages" in Term.(pure main $ print_flags_arg $ list_arg $ short_arg $ - no_sources_arg $ debug_arg $ install_arg $ + no_sources_arg $ debug_arg $ install_arg $ update_arg $ packages_arg), - Term.info "opam-depext" ~version:"0.3" ~doc ~man + Term.info "opam-depext" ~version:"0.4" ~doc ~man let () = match Term.eval command with diff --git a/opam b/opam index 6063328..f3a62e9 100644 --- a/opam +++ b/opam @@ -2,7 +2,8 @@ opam-version: "1.2" name: "depext" version: "0.4" maintainer: "Louis Gesbert " -authors: "Louis Gesbert " +authors: ["Louis Gesbert " + "Anil Madhavapeddy ] homepage: "https://github.com/AltGr/opam-depext" bug-reports: "https://github.com/AltGr/opam-depext/issues" license: "LGPL-3.0 with OCaml linking exception" From cf297ee630afc7d35c7393f229694f12bd153de0 Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Sun, 22 Mar 2015 09:45:04 +0000 Subject: [PATCH 6/7] Add a CHANGES file --- CHANGES | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 CHANGES diff --git a/CHANGES b/CHANGES new file mode 100644 index 0000000..314efc6 --- /dev/null +++ b/CHANGES @@ -0,0 +1,17 @@ +0.4 (2015-03-22): +* Add `-u` or `--update` flag to trigger an OS package set update + before performing external dependency installation. This is useful + on Debian or Ubuntu where package installation may fail if the + sets are not up-to-date with respect to latest security updates. +* Fix installation of source packages. +* Detect the CentOS distribution correctly. +* Fix external command detection to not go through a subshell. + +0.3 (2015-01-27): +* Add OCaml 3.12.1 compatibility. +* Add `-i` flag to perform OPAM package installation after the + external OS dependencies are installed. +* Fixes for MacPorts and CentOS support. + +0.2 (2015-01-21): +* Initial public release. From 50bd3c3f6d85c05bc3198816bd5da120e68099b8 Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Sun, 22 Mar 2015 13:10:10 +0000 Subject: [PATCH 7/7] fix typo in opam file --- opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opam b/opam index f3a62e9..d2043ab 100644 --- a/opam +++ b/opam @@ -3,7 +3,7 @@ name: "depext" version: "0.4" maintainer: "Louis Gesbert " authors: ["Louis Gesbert " - "Anil Madhavapeddy ] + "Anil Madhavapeddy "] homepage: "https://github.com/AltGr/opam-depext" bug-reports: "https://github.com/AltGr/opam-depext/issues" license: "LGPL-3.0 with OCaml linking exception"