diff --git a/NAMESPACE b/NAMESPACE index 5d84cd9..d6ff8b9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,9 +1,15 @@ # Generated by roxygen2: do not edit by hand +export(kernel_state) export(read_dsstore) export(software_update_history) +export(sw_vers) +export(system_profile) import(reticulate) import(sys) import(xml2) importFrom(anytime,anytime) +importFrom(purrr,"%>%") +importFrom(purrr,flatten_chr) importFrom(purrr,map_df) +importFrom(purrr,set_names) diff --git a/R/kernel-state.R b/R/kernel-state.R new file mode 100644 index 0000000..b9f2cc7 --- /dev/null +++ b/R/kernel-state.R @@ -0,0 +1,22 @@ +#' Retrieve kernel state information +#' +#' @export +kernel_state <- function() { + + res <- sys::exec_internal("sysctl", "-a") + + if (res$status != 0) { + stop("Error retrieving kernel state info. Are you on macOS?", call.=FALSE) + } + + out <- rawToChar(res$stdout) + purrr::map_df(strsplit(out, "\n")[[1]], ~{ + .x <- strsplit(.x, ": ", fixed = TRUE)[[1]] + list( + setting = .x[1], + value = .x[2] + ) + }) + + +} \ No newline at end of file diff --git a/R/mactheknife-package.R b/R/mactheknife-package.R index 369b137..5514e86 100644 --- a/R/mactheknife-package.R +++ b/R/mactheknife-package.R @@ -7,6 +7,6 @@ #' @docType package #' @author Bob Rudis (bob@@rud.is) #' @import reticulate sys xml2 -#' @importFrom purrr map_df +#' @importFrom purrr map_df %>% flatten_chr set_names #' @importFrom anytime anytime NULL diff --git a/R/su-hist-file.R b/R/su-hist-file.R index deb41d3..fc3342a 100644 --- a/R/su-hist-file.R +++ b/R/su-hist-file.R @@ -45,7 +45,7 @@ software_update_history <- function(su_hist_file = "/Library/Receipts/InstallHis "real" = as.numeric(unlist(grandkids[[i+1]])), "true" = TRUE, "false" = FALSE, - "array" = list(setNames(list(unlist(grandkids[[i+1]], use.names=FALSE)), key_name)), + "array" = list(purrr::set_names(list(unlist(grandkids[[i+1]], use.names=FALSE)), key_name)), "data" = "TODO", "UNKNOWN - TODO" ) diff --git a/R/sw-vers.R b/R/sw-vers.R new file mode 100644 index 0000000..e35440d --- /dev/null +++ b/R/sw-vers.R @@ -0,0 +1,19 @@ +#' Retrieve macOS Operating System Version Information +#' +#' @return data frame (tibble) +#' @export +sw_vers <- function() { + + res <- sys::exec_internal("sw_vers") + + if (length(res$stdout) == 0) { + stop('Error retrieving macOS version info. Are you running on macOS?', call.=FALSE) + } + + out <- rawToChar(res$stdout) + purrr::map_dfc(strsplit(out, "\n")[[1]], ~{ + .x <- strsplit(.x, "\t")[[1]] + as.list(purrr::set_names(.x[2], gsub(":", "", .x[1]))) + }) + +} \ No newline at end of file diff --git a/R/system-profile.R b/R/system-profile.R new file mode 100644 index 0000000..571db4a --- /dev/null +++ b/R/system-profile.R @@ -0,0 +1,32 @@ +#' Report system hardware and software configuration +#' +#' TODO Do more than just return an xml document once a generica plist reader +#' is created. +#' +#' @md +#' @note Even the `mini` option takes a noticeable amount of time to complete. +#' @param detail_level how much information to return: +#' - `mini` report with no personal information +#' - `basic` basic hardware and network information +#' - `full` all available information +#' @export +system_profile <- function(detail_level = c("mini", "basic", "full")) { + + match.arg( + tolower(trimws(detail_level[1])), + c("mini", "basic", "full") + ) -> detail_level + + sys::exec_internal( + "system_profiler", + c("-xml", "-detailLevel", "mini") + ) -> res + + if (res$status != 0) { + stop("Error running system profiler. Are you on macOS?", call.=FALSE) + } + + xml2::read_xml(res$stdout) + +} + diff --git a/README.Rmd b/README.Rmd index abbcb04..e15b15b 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,8 +16,10 @@ A set of tools/methods and data that are geared towards the 'macOS' ecosystem. ## What's Inside The Tin +- `kernel_state`: Retrieve kernel state information - `read_dsstore`: Read a '.DS_Store' from a file/URL - `software_update_history`: Retrieve Software Update history +- `sw_vers`: Retrieve macOS Operating System Version Information The following functions are implemented: @@ -41,6 +43,12 @@ packageVersion("mactheknife") ``` +### Kernel state vars + +```{r} +kernel_state() +``` + ### `.DS_Store` example Using built-in data @@ -80,3 +88,10 @@ str(x) ```{r} software_update_history() ``` + + +### macOS Version Info (short) + +```{r} +sw_vers() +``` diff --git a/README.md b/README.md index c659701..c5f87ab 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,10 @@ ecosystem. ## What’s Inside The Tin + - `kernel_state`: Retrieve kernel state information - `read_dsstore`: Read a ‘.DS\_Store’ from a file/URL - `software_update_history`: Retrieve Software Update history + - `sw_vers`: Retrieve macOS Operating System Version Information The following functions are implemented: @@ -36,6 +38,27 @@ packageVersion("mactheknife") ## [1] '0.1.0' +### Kernel state vars + +``` r +kernel_state() +``` + + ## # A tibble: 1,217 x 2 + ## setting value + ## + ## 1 user.cs_path /usr/bin:/bin:/usr/sbin:/sbin + ## 2 user.bc_base_max 99 + ## 3 user.bc_dim_max 2048 + ## 4 user.bc_scale_max 99 + ## 5 user.bc_string_max 1000 + ## 6 user.coll_weights_max 2 + ## 7 user.expr_nest_max 32 + ## 8 user.line_max 2048 + ## 9 user.re_dup_max 255 + ## 10 user.posix2_version 200112 + ## # ... with 1,207 more rows + ### `.DS_Store` example Using built-in data @@ -120,3 +143,14 @@ software_update_history() ## 9 Degrees Pro 4.2.1 2017-01-23 16:06:56 storedownloadd ## 10 WordService 2.8.1 2017-01-23 16:06:57 storedownloadd ## # ... with 580 more rows + +### macOS Version Info (short) + +``` r +sw_vers() +``` + + ## # A tibble: 1 x 3 + ## ProductName ProductVersion BuildVersion + ## + ## 1 Mac OS X 10.12.6 16G1405 diff --git a/man/kernel_state.Rd b/man/kernel_state.Rd new file mode 100644 index 0000000..69701da --- /dev/null +++ b/man/kernel_state.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/kernel-state.R +\name{kernel_state} +\alias{kernel_state} +\title{Retrieve kernel state information} +\usage{ +kernel_state() +} +\description{ +Retrieve kernel state information +} diff --git a/man/sw_vers.Rd b/man/sw_vers.Rd new file mode 100644 index 0000000..a863d72 --- /dev/null +++ b/man/sw_vers.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sw-vers.R +\name{sw_vers} +\alias{sw_vers} +\title{Retrieve macOS Operating System Version Information} +\usage{ +sw_vers() +} +\value{ +data frame (tibble) +} +\description{ +Retrieve macOS Operating System Version Information +} diff --git a/man/system_profile.Rd b/man/system_profile.Rd new file mode 100644 index 0000000..eb614d2 --- /dev/null +++ b/man/system_profile.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/system-profile.R +\name{system_profile} +\alias{system_profile} +\title{Report system hardware and software configuration} +\usage{ +system_profile(detail_level = c("mini", "basic", "full")) +} +\arguments{ +\item{detail_level}{how much information to return: +\itemize{ +\item \code{mini} report with no personal information +\item \code{basic} basic hardware and network information +\item \code{full} all available information +}} +} +\description{ +TODO Do more than just return an xml document once a generica plist reader +is created. +} +\note{ +Even the \code{mini} option takes a noticeable amount of time to complete. +}