osrelease -- detect operating system, distro, and version information#
Detect the local system's architecture, operating system, distribution, and
version from OCaml. Works by inspecting environment variables and running
system commands such as uname and reading /etc/os-release.
Installation#
Install with opam:
$ opam install osrelease
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install osrelease
Usage#
let detect () =
let arch = Osrelease.Arch.v () in
let os = Osrelease.OS.v () in
Fmt.pr "Running on %a / %a@." Osrelease.OS.pp os Osrelease.Arch.pp arch;
match Osrelease.Distro.v () with
| Ok distro -> Fmt.pr "Distro: %a@." Osrelease.Distro.pp distro
| Error (`Msg msg) -> Fmt.epr "Detection failed: %s@." msg
API#
Osrelease.Arch.v ()-- current CPU architecture (X86_64,Aarch64,Arm32,Ppc64, etc.)Osrelease.OS.v ()-- operating system (Linux,MacOS,FreeBSD,Win32, etc.)Osrelease.Distro.v ()-- distribution (Ubuntu,Debian,Alpine,Fedora,Homebrew, etc.)Osrelease.Distro.os_release_field key-- read a field from/etc/os-releaseOsrelease.Version.v ()-- OS version string
All modules provide to_string, of_string, and pp functions.
Supported Platforms#
Linux (Alpine, Arch, CentOS, Debian, Fedora, Gentoo, NixOS, OpenSUSE, Oracle Linux, RHEL, Ubuntu, Android), macOS (Homebrew, MacPorts), FreeBSD, OpenBSD, DragonFly, Cygwin, Win32.
License#
ISC