Nothing
#' Get info on the system's Linux distribution
#'
#' @return On Linux distributions, it returns a list of four elements:
#' * `id`, e.g. "ubuntu", "debian"
#' * `version`, e.g. "18.04", "7.7.1908"
#' * `codename`, e.g. "bionic", "bullseye"
#' * `short_version`, which for Ubuntu is the `yy.mm` version ("18.04") but for
#' all other distributions is the major version number only ("7")
#'
#' Not all fields are guaranteed to be defined on all systems. On non-Linux
#' systems, the function returns `NULL`.
#' @export
#' @examples
#' distro()
distro <- function() {
out <- lsb_release()
if (is.null(out)) {
out <- os_release()
if (is.null(out)) {
out <- system_release()
}
}
if (is.null(out)) {
return(NULL)
}
out$id <- tolower(out$id)
if (grepl("bullseye", out$codename)) {
# debian unstable doesn't include a number but we can map from pretty name
out$short_version <- "11"
} else if (out$id == "ubuntu") {
# Keep major.minor version
out$short_version <- sub('^"?([0-9]+\\.[0-9]+).*"?.*$', "\\1", out$version)
} else {
# Only major version number
out$short_version <- sub('^"?([0-9]+).*"?.*$', "\\1", out$version)
}
out
}
lsb_release <- function() {
if (have_lsb_release()) {
list(
id = call_lsb("-is"),
version = call_lsb("-rs"),
codename = call_lsb("-cs")
)
} else {
NULL
}
}
have_lsb_release <- function() nzchar(Sys.which("lsb_release"))
call_lsb <- function(args) system(paste("lsb_release", args), intern = TRUE)
os_release <- function() {
rel_data <- read_os_release()
if (!is.null(rel_data)) {
vals <- as.list(sub('^.*="?(.*?)"?$', "\\1", rel_data))
names(vals) <- sub("^(.*)=.*$", "\\1", rel_data)
out <- list(
id = vals[["ID"]],
version = vals[["VERSION_ID"]]
)
if ("VERSION_CODENAME" %in% names(vals)) {
out$codename <- vals[["VERSION_CODENAME"]]
} else {
# This probably isn't right, maybe could extract codename from pretty name?
out$codename = vals[["PRETTY_NAME"]]
}
out
} else {
NULL
}
}
read_os_release <- function() {
if (file.exists("/etc/os-release")) {
readLines("/etc/os-release")
}
}
system_release <- function() {
rel_data <- read_system_release()
if (!is.null(rel_data)) {
# Something like "CentOS Linux release 7.7.1908 (Core)"
list(
id = sub("^([a-zA-Z]+) .* ([0-9.]+).*$", "\\1", rel_data),
version = sub("^([a-zA-Z]+) .* ([0-9.]+).*$", "\\2", rel_data),
codename = NA
)
} else {
NULL
}
}
read_system_release <- function() {
if (file.exists("/etc/system-release")) {
readLines("/etc/system-release")[1]
}
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.