Skip to content

Commit

Permalink
allow prerequisite run without sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Jan 23, 2024
1 parent 5df3a8b commit ced56e6
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 9 deletions.
12 changes: 8 additions & 4 deletions inst/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ set -u

SCRIPT_DIR=$(dirname "$0")
OS_TYPE=$(/usr/bin/uname)
R_CMD=$(/usr/bin/which Rscript)
R_CMD=$(/usr/bin/which Rscript || echo "Rscript")

# 0 no install; 1 assuming no sudo access; 2 have sudo
SYSREQ="1"

while getopts ":s:r:" opt; do
Expand Down Expand Up @@ -34,10 +36,10 @@ ohai "R binary path: ${R_CMD}"
if [ "${SYSREQ}" == "1" ]; then
if [ "$OS_TYPE" == "Darwin" ]; then
ohai "Operating System: macOS"
. "${SCRIPT_DIR}/shell/installer-prerequisites-osx.sh"
. "${SCRIPT_DIR}/shell/installer-prerequisites-osx.sh" -s "${SYSREQ}"
elif [ "$OS_TYPE" == "Linux" ]; then
ohai "Operating System: Linux"
# . "${SCRIPT_DIR}/shell/installer-prerequisites-linux.sh"
# . "${SCRIPT_DIR}/shell/installer-prerequisites-linux.sh" -s "${SYSREQ}"
fi
else
ohai "Skipping system requisites"
Expand All @@ -64,10 +66,12 @@ if( system.file(package = 'ravemanager', lib.loc = lib_path) == '' ) {
install.packages('ravemanager', repos = 'https://rave-ieeg.r-universe.dev', lib = lib_path)
}
loadNamespace('ravemanager', lib.loc = lib_path)
ravemanager::install(allow_cache = FALSE)
ravemanager::install(allow_cache = FALSE, python = TRUE)
"
ohai "Running R command: ${cmd_str}"
${R_CMD} --no-save --no-restore -e "${cmd_str}"

ohai "Check python loading"

execute ${R_CMD} --no-save --no-restore -e "rpyANTs::load_ants()"

31 changes: 26 additions & 5 deletions inst/shell/installer-prerequisites-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@

set -u

SYSREQ="1"
while getopts ":s:" opt; do
case $opt in
s)
SYSREQ="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done

# SCRIPT_DIR=$(dirname "$0")
#
# # Load installer commons
# . "${SCRIPT_DIR}/installer-common.sh"

ohai "Checking sudo access (may require your password): "
have_sudo_access true

UNAME_MACHINE="$(/usr/bin/uname -m)"
if [[ "$UNAME_MACHINE" == "arm64" ]]; then
# On ARM macOS, this script installs to /opt/homebrew only
Expand All @@ -21,8 +35,15 @@ else
HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"
fi

# Install brew
execute_sudo echo | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [ "${SYSREQ}" == "2" ]; then
ohai "Checking sudo access (may require your password): "
have_sudo_access true

# Install brew
execute_sudo echo | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi




# Add brew to zsh (z-shell), bash, and sh
Expand Down
48 changes: 48 additions & 0 deletions tests/testthat/test-installation.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
# DIPSAUS DEBUG START
# library(testthat)

remove_conda <- function() {
try(silent = TRUE, {
rpymat <- asNamespace("rpymat")
root <- normalizePath(rpymat$install_root(), mustWork = FALSE)
unlink(root, recursive = TRUE, force = TRUE)
})
}

get_os <- function ()
{
if ("windows" %in% tolower(.Platform$OS.type)) {
return("windows")
}
os <- tolower(R.version$os)
if (startsWith(os, "darwin")) {
return("darwin")
}
if (startsWith(os, "linux")) {
return("linux")
}
if (startsWith(os, "solaris")) {
return("solaris")
}
if (startsWith(os, "win")) {
return("windows")
}
return("unknown")
}

test_that("Installation works", {
if(detect_gh_ci() && get_os() == "windows") {
ravemanager::install()
libpath <- .libPaths()[[1]]
expect_true(nzchar(system.file(package = "ravebuiltins", lib.loc = libpath)))
expect_true(nzchar(system.file(package = "rpyANTs", lib.loc = libpath)))
rpyANTs <- asNamespace("rpyANTs")
rpymat <- asNamespace("rpymat")

on.exit({
remove_conda()
})

# remove_conda()
# ravemanager::configure_python()
# expect_s3_class(rpyANTs$ants, c("ants.proxy", "python.builtin.module"))
}
})

0 comments on commit ced56e6

Please sign in to comment.