Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix has_command, CentOS detection, source installation and add OS update support #7

Merged
merged 7 commits into from
Mar 23, 2015
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions depext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this will work well. Based on experience with cmdliner that's a correct and multiplatform way of checking whether a command exists or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command is POSIX, but I can believe that it's not portable despite that. Would it be possible for cmdliner to expose the find_cmd logic so that we dont have to cut and paste it here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible for cmdliner to expose the find_cmd logic so that we dont have to cut and paste it here?

I don't think cmdliner is the place to expose such things. I'd say either just c&p or use Bos which exposes this logic in its API (but that's another dependency).

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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "1.2"
name: "depext"
version: "0.1"
version: "0.4"
maintainer: "Louis Gesbert <louis.gesbert@ocamlpro.com>"
authors: "Louis Gesbert <louis.gesbert@ocamlpro.com>"
homepage: "https://github.com/AltGr/opam-depext"
Expand Down