Skip to content

Commit

Permalink
Merge pull request #30 from Enchufa2/fix/27
Browse files Browse the repository at this point in the history
close #27: add an optional automated passwordless detection mechanism
  • Loading branch information
Enchufa2 authored Jun 24, 2021
2 parents f01e448 + 86c0779 commit 0aaa340
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: bspm
Type: Package
Title: Bridge to System Package Manager
Version: 0.3.7.1
Version: 0.3.8
Authors@R: c(
person("Iñaki", "Ucar", email="[email protected]",
role=c("aut", "cph", "cre"), comment=c(ORCID="0000-0001-6403-5550")))
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# bspm 0.3.7.1
# bspm 0.3.8

- Fix spurious error with `options(bspm.always.install.deps=TRUE)` (#25).
- Ensure that `options(bspm.sudo=TRUE)` forces `sudo` unconditionally (#28).
- Add new `options(bspm.sudo.autodetect=TRUE)` (not set by default) to enable
passwordless `sudo` autodetection on package load, which then sets
`options(bspm.sudo=TRUE)` accordingly (#27).

# bspm 0.3.7

Expand Down
14 changes: 14 additions & 0 deletions R/init.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.onLoad <- function(libname, pkgname) {
if (getOption("bspm.sudo.autodetect", FALSE))
sudo_autodetect()
}

sudo_autodetect <- function() {
nopass <- !system2nowarn("sudo", c("-n", "true"), stdout=FALSE, stderr=FALSE)
toolbox <- file.exists("/run/.toolboxenv") # see #27

if (nopass || toolbox) {
packageStartupMessage("bspm: passwordless sudo detected and enabled")
options(bspm.sudo=TRUE)
}
}
5 changes: 5 additions & 0 deletions R/manager.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#' that, if you want to fall back to \code{sudo} in a non-interactive session,
#' you need to set \code{options(bspm.sudo=TRUE)}.
#'
#' If \code{options(bspm.sudo.autodetect=TRUE)} on start-up, \pkg{bspm} tries
#' to detect whether it is running in an environment where password-less
#' \code{sudo} can be used (e.g., in a containerized environment such as a
#' Fedora Toolbox), and then sets \code{options(bspm.sudo=TRUE)} accordingly.
#'
#' By default, if a package is not available in the system repositories, it is
#' installed from R's configured repositories along with all its dependencies.
#' This behavior can be changed via \code{options(bspm.always.install.deps=TRUE)},
Expand Down
14 changes: 14 additions & 0 deletions inst/tinytest/test_manager_ci.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
if (!at_home() || !bspm:::root())
exit_file("not in a CI environment")

sudo.avail <- unname(nchar(Sys.which("sudo")) > 0)
in.toolbox <- file.exists("/run/.toolboxenv")
expect_false(getOption("bspm.sudo", FALSE))
bspm:::sudo_autodetect()
if (sudo.avail || in.toolbox) {
expect_true(getOption("bspm.sudo", FALSE))
} else {
expect_false(getOption("bspm.sudo", FALSE))
file.create("/run/.toolboxenv")
bspm:::sudo_autodetect()
expect_true(getOption("bspm.sudo", FALSE))
}
options(bspm.sudo = NULL)

if (requireNamespace("Rcpp", quietly=TRUE))
exit_file("not in a clean environment")

Expand Down
5 changes: 5 additions & 0 deletions man/manager.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0aaa340

Please sign in to comment.