Skip to content

Commit

Permalink
added installer bash
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Jan 23, 2024
1 parent c5c84bf commit f8294d5
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ jobs:
with:
args: 'c("--no-manual")'
upload-snapshots: false

- name: Check installation
if: runner.os != 'Windows'
run: |
chmod a+x ./inst/installer.sh
./inst/installer.sh
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ravemanager
Title: Manage 'RAVE' Packages
Version: 1.0.35
Version: 1.0.36
Authors@R:
person("Zhengjia", "Wang", email = "[email protected]",
role = c("aut", "cre"))
Expand All @@ -14,6 +14,8 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
URL: https://dipterix.org/ravemanager/,
http://dipterix.org/ravemanager/
Imports:
utils
Suggests:
learnr,
pkgload,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(ravemanager_version)
export(remove_conda)
export(run_tutorials)
export(system_requirements)
export(uninstall)
export(update_rave)
export(upgrade_installer)
export(validate_python)
Expand Down
23 changes: 8 additions & 15 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ is_installed <- function(pkg) {
}

#' Print out 'RAVE' version information
#' @param nightly whether to check 'nightly' build which contains the newest
#' experimental features. However, 'nightly' builds are not stable. This
#' option is only recommended for zero-day bug fixes.
#' @param vanilla whether to use vanilla packages in this function
#' @export
version_info <- function(nightly = FALSE, vanilla = FALSE) {
if( nightly ) {
options("ravemanager.nightly" = TRUE)
} else {
options("ravemanager.nightly" = FALSE)
}
version_info <- function(vanilla = FALSE) {
options("ravemanager.nightly" = FALSE)

versions <- new.env()
versions$ravemanager <- list(
Expand Down Expand Up @@ -102,10 +95,10 @@ version_info <- function(nightly = FALSE, vanilla = FALSE) {
# message(' lib_path <- Sys.getenv("RAVE_LIB_PATH", unset = Sys.getenv("R_LIBS_USER", unset = .libPaths()[[1]]))')
# message(' loadNamespace("ravemanager", lib.loc = lib_path)')
cli$cli_text(cli$col_cyan(sprintf('loadNamespace("ravemanager", lib.loc = "%s")', get_libpaths(first = TRUE, check = TRUE))))
if( nightly ) {
cli$cli_text(cli$col_cyan('ravemanager::update_rave(nightly = TRUE)'))
} else {
if( isFALSE(ravemanager_needsUpdate) ) {
cli$cli_text(cli$col_cyan('ravemanager::update_rave()'))
} else {
cli$cli_text(cli$col_cyan('ravemanager::update_rave(allow_cache = FALSE)'))
}
cat("\n")
}
Expand Down Expand Up @@ -136,9 +129,9 @@ version_info <- function(nightly = FALSE, vanilla = FALSE) {
' lib_path <- Sys.getenv("RAVE_LIB_PATH", unset = Sys.getenv("R_LIBS_USER", unset = .libPaths()[[1]]))',
' loadNamespace("ravemanager", lib.loc = lib_path)',
ifelse(
nightly,
' ravemanager::update_rave(nightly = TRUE)',
' ravemanager::update_rave()'
isFALSE(ravemanager_needsUpdate),
' ravemanager::update_rave()',
' ravemanager::update_rave(allow_cache = FALSE)'
),
sep = "\n"
),
Expand Down
141 changes: 137 additions & 4 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @description Installs the newest version of 'RAVE' and its dependence
#' packages; executes the scripts to finalize installation to update
#' configuration files.
#' @param nightly whether to install the nightly build
#' @param allow_cache whether to allow cache; default is true
#' @param upgrade_manager whether to upgrade the installer (\code{ravemanager})
#' before updating other packages
#' @param force whether to force updating packages even the installed have
Expand Down Expand Up @@ -306,11 +306,25 @@ assert_r_version <- function(min = "4.0.0") {
return(TRUE)
}

pak_cache_dir <- function() {
tools <- asNamespace("tools")
tools$R_user_dir("ravemanager", which = "cache")
}

pak_cache_remove <- function() {
cache_path <- pak_cache_dir()
if(file.exists(cache_path)) {
message("Removing package cache...")
unlink(cache_path, recursive = TRUE)
}
invisible()
}

try_setup_pak <- function(lib_path = get_libpaths(check = TRUE)) {
cdir <- NULL
tryCatch({
tools <- asNamespace("tools")
cdir <- dir_create2(tools$R_user_dir("ravemanager", which = "cache"))

cdir <- dir_create2(pak_cache_dir())

# Try to install package `pak`
if(system.file(package = "pak") == "") {
Expand Down Expand Up @@ -357,6 +371,11 @@ installer_unload_packages <- function() {
install_internal <- function(nightly = FALSE, upgrade_manager = FALSE,
finalize = TRUE, force = FALSE, python = FALSE, ...) {

# DIPSAUS DEBUG START
# list2env(list(nightly = FALSE, upgrade_manager = FALSE,
# finalize = TRUE, force = FALSE, python = FALSE), envir=.GlobalEnv)


if( nightly ) {
options("ravemanager.nightly" = TRUE)
} else {
Expand Down Expand Up @@ -472,8 +491,15 @@ install_internal <- function(nightly = FALSE, upgrade_manager = FALSE,

#' @rdname RAVE-install
#' @export
install <- function(nightly = FALSE, upgrade_manager = FALSE,
install <- function(allow_cache = TRUE, upgrade_manager = FALSE,
finalize = TRUE, force = FALSE, python = FALSE, ...) {

if(!allow_cache) {
pak_cache_remove()
}


nightly <- FALSE
tryCatch({
install_internal(
nightly = nightly,
Expand Down Expand Up @@ -597,3 +623,110 @@ upgrade_installer <- function(reload = TRUE) {
}
return(invisible(FALSE))
}

#' Uninstall RAVE components
#' @description
#' Remove cache, python, and/or all settings. Please be aware that
#' R, 'RStudio', and already installed R packages will not be uninstalled.
#' Please carefully read printed messages.
#' @param components which component to remove, see example for choices.
#' @examples
#'
#' if( FALSE ) {
#'
#' # remove cache only
#' ravemanager::uninstall("cache")
#'
#' # remove python environment
#' ravemanager::uninstall("python")
#'
#' # remove all sample data, settings files
#' ravemanager::uninstall("all")
#'
#' }
#'
#'
#' @export
uninstall <- function(components = c("cache", "python", "all")) {
components <- match.arg(components)
remove_cache <- components %in% c("cache", "all")
remove_python <- components %in% c("python", "all")
remove_all <- components %in% c("all")

if( remove_all ) {
ans <- utils::askYesNo("You are uninstalling RAVE. Please enter Y or yes to confirm: ")
if(!isTRUE(ans)) {
return(invisible())
}
}

tools <- asNamespace("tools")
R_user_dir <- tools$R_user_dir

remove_files <- function(paths) {
lapply(paths, function(path) {
if(!file.exists(path)) { return() }
if(dir.exists(path)) {
unlink(path, recursive = TRUE)
} else {
unlink(path)
}
return()
})
}
if( remove_cache ) {
message("Removing cache...")

# ravemanager
pak_cache_remove()

# raveio
d <- R_user_dir(package = "raveio", which = "data")
fs <- list.files(d, pattern = "^(dipterix|rave-ieeg)-rave-pipelines", include.dirs = TRUE, full.names = TRUE, recursive = FALSE)
remove_files(fs)
if(is_installed("raveio")) {
raveio <- asNamespace("raveio")
raveio$clear_cached_files()
}
}

if( remove_python ) {
message("Removing python...")
remove_conda(ask = FALSE)

# rpymat
d <- R_user_dir(package = "rpymat", which = "config")
remove_files(file.path(d, "jupyter-configurations"))
}

if( remove_all ) {
message("Uninstalling RAVE (we are sorry to say goodbye)...")

# remove ~/rave_modules
remove_files("~/rave_modules")

remove_files( R_user_dir("raveio", "data") )
remove_files( R_user_dir("rpyANTs", "data") )
remove_files( R_user_dir("threeBrain", "data") )

remove_files( R_user_dir("raveio", "config") )
remove_files( R_user_dir("ravemanager", "config") )
remove_files( R_user_dir("rpymat", "config") )

remove_files( R_user_dir("dipsaus", "cache") )
remove_files( R_user_dir("ravemanager", "cache") )
remove_files( R_user_dir("readNSx", "cache") )

message("R and RStudio are not managed by RAVE. Please uninstall them by yourself if necessary.")
msg <- paste(
c(
"There are some files that may contain your data or used other packages. ",
"Please check them manually:\n",
.libPaths(),
normalizePath("~/rave_data", mustWork = FALSE)
),
collapse = "\n"
)
message(msg)
}
}
3 changes: 1 addition & 2 deletions R/python.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,11 @@ system_pkgpath <- function(package, ..., alternative = TRUE) {

#' @rdname configure-python
#' @export
configure_python <- function(python_ver = "3.9", verbose = TRUE) {
configure_python <- function(python_ver = "auto", verbose = TRUE) {

if(!is_installed("rpymat")) {
install_packages("rpymat")
}

rpymat <- asNamespace("rpymat")

# Install conda and create a conda environment
Expand Down
55 changes: 55 additions & 0 deletions inst/installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

set -e
set -u

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

if [ "$2" == "--skip-sysreq" ]; then
echo "Skipping system requisites"
elif [ "$OS_TYPE" == "Darwin" ]; then
echo "Operating System: macOS"
. "${SCRIPT_DIR}/shell/installer-prerequisites-osx.sh"
elif [ "$OS_TYPE" == "Linux" ]; then
echo "Operating System: Linux"
# . "${SCRIPT_DIR}/shell/installer-prerequisites-linux.sh"
fi


# Load installer commons
. "${SCRIPT_DIR}/shell/installer-common.sh"


ohai "Operating System: ${OS_TYPE}"
ohai "R binary path: ${R_CMD}"


# Create a temporary directory
tmpdir=$(mktemp -d -t "rave-installer")
cd "${tmpdir}"

ohai "Current directory: ${tmpdir}"

# Install ravemanager
lib_path=$(${R_CMD} --no-save --no-restore -e 'cat(Sys.getenv("RAVE_LIB_PATH", unset = Sys.getenv("R_LIBS_USER", unset = .libPaths()[[1]])))')

ohai "R Library path: $lib_path"

mkdir -p "$lib_path"


cmd_str="
lib_path <- '$lib_path'
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)
"
ohai "Running R command: ${cmd_str}"
${R_CMD} --no-save --no-restore -e "${cmd_str}"



35 changes: 35 additions & 0 deletions inst/shell/installer-prerequisites-osx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -u

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
HOMEBREW_PREFIX="/opt/homebrew"
HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}"
else
# On Intel macOS, this script installs to /usr/local only
HOMEBREW_PREFIX="/usr/local"
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)"


# Add brew to zsh (z-shell), bash, and sh
# execute echo "eval \"\$($HOMEBREW_PREFIX/bin/brew shellenv)\"" >> "$HOME/.zprofile"
# execute echo "eval \"\$($HOMEBREW_PREFIX/bin/brew shellenv)\"" >> "$HOME/.bash_profile"
# execute echo "eval \"\$($HOMEBREW_PREFIX/bin/brew shellenv)\"" >> "$HOME/.profile"
# Activate brew
eval "$($HOMEBREW_PREFIX/bin/brew shellenv)"

execute $HOMEBREW_PREFIX/bin/brew install hdf5 fftw libgit2 libxml2 pkg-config libjpeg libpng libtiff cmake
6 changes: 3 additions & 3 deletions man/RAVE-install.Rd

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

Loading

0 comments on commit f8294d5

Please sign in to comment.