Skip to contents

Detects the host operating system and, on Linux, parses /etc/os-release. On macOS, queries sw_vers. Returns a structured platform object used by the rest of the package. When os_release is supplied and exists, the file is parsed even on macOS or Windows; this makes fixture-driven testing practical.

Usage

detect_platform(os_release = "/etc/os-release")

Arguments

os_release

Path to an os-release file. Defaults to the system file /etc/os-release. Mainly useful for tests and reproducible builds.

Value

An object of class sysreqr_platform (a list).

See also

Examples

platform <- detect_platform()
platform$distro
#> [1] "ubuntu"

# Reproducible reads from a fixture file:
fixture <- system.file(
  "extdata", "os-release-fedora-40",
  package = "sysreqr",
  mustWork = FALSE
)
if (nzchar(fixture)) detect_platform(os_release = fixture)
#> $os
#> [1] "linux"
#> 
#> $distro
#> [1] "fedora"
#> 
#> $version
#> [1] "40"
#> 
#> $codename
#> [1] NA
#> 
#> $package_manager
#> [1] "dnf"
#> 
#> $ppm_binary_url
#> [1] NA
#> 
#> $supported
#> [1] TRUE
#> 
#> $label
#> [1] "Fedora Linux 40 (Workstation Edition) fedora"
#> 
#> attr(,"class")
#> [1] "sysreqr_platform"