From b95b27f625177f3319f5c8937d85960ce3efd650 Mon Sep 17 00:00:00 2001 From: Ricardo Andrade Date: Fri, 6 Sep 2019 14:38:38 -0500 Subject: [PATCH 1/3] Takes version as 2nd argument, list versions switch, silent json fetch --- install.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index b899598..785fe1e 100755 --- a/install.sh +++ b/install.sh @@ -8,6 +8,10 @@ SCRIPT_ACTION=${SCRIPT_ACTION:-install} # Set to the full version to install. Must be either available on S3 or in the working directory R_VERSION=${R_VERSION:-} +# The version may optionally be provided as a second argument +if [[ "$2" != "" ]]; then + R_VERSION=$2cd +fi SUDO= if [[ $(id -u) != "0" ]]; then @@ -20,7 +24,7 @@ CDN_URL='https://cdn.rstudio.com/r' # The URL for listing available R versions VERSIONS_URL="${CDN_URL}/versions.json" -R_VERSIONS=$(curl ${VERSIONS_URL} | \ +R_VERSIONS=$(curl -s ${VERSIONS_URL} | \ # Matches the JSON line that contains the r versions grep r_versions | \ # Gets the value of the `r_version` property (e.g., "[ 3.0.0, 3.0.3, ... ]") @@ -107,6 +111,14 @@ show_versions () { done } +# Same as above but for automation purposes +do_show_versions () { + for v in ${R_VERSIONS} + do + echo "${v}" + done +} + # Returns the installer name for a given version and OS download_name () { os=$1 @@ -367,7 +379,6 @@ check_commands () { } do_install () { - # Check for curl check_commands @@ -402,4 +413,7 @@ case ${SCRIPT_ACTION} in "install") do_install ;; + "version") + do_show_versions + ;; esac From 5a394f79904ee7ae8f6ecacbb7eaa641fd1ac2ef Mon Sep 17 00:00:00 2001 From: Ricardo Andrade Date: Fri, 6 Sep 2019 14:50:39 -0500 Subject: [PATCH 2/3] Tweaks: blank line and plural "versions" --- install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 785fe1e..2c4533a 100755 --- a/install.sh +++ b/install.sh @@ -379,6 +379,7 @@ check_commands () { } do_install () { + # Check for curl check_commands @@ -413,7 +414,7 @@ case ${SCRIPT_ACTION} in "install") do_install ;; - "version") + "versions") do_show_versions ;; esac From be34efabd716a7022bff4abf53e7b14b1a672d9d Mon Sep 17 00:00:00 2001 From: Ricardo Andrade Date: Fri, 6 Sep 2019 15:13:13 -0500 Subject: [PATCH 3/3] Add help command and standard CLI switches --- install.sh | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 2c4533a..f44da98 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,5 @@ #!/bin/bash +THIS_VERSION="1.0" # Call with: # bash -c "$(curl -L https://rstd.io/r-install)" @@ -10,7 +11,7 @@ SCRIPT_ACTION=${SCRIPT_ACTION:-install} R_VERSION=${R_VERSION:-} # The version may optionally be provided as a second argument if [[ "$2" != "" ]]; then - R_VERSION=$2cd + R_VERSION=$2 fi SUDO= @@ -409,12 +410,28 @@ do_install () { install "${installer_type}" "${installer_file_name}" "${os}" "${os_ver}" } +do_show_usage() { + echo "r-builds quick install version ${THIS_VERSION}" + echo "Usage: `basename $0` [-i|-r|-v|-h|install|rversions|version|help]" + echo "Where:" + echo "'-i' or 'install' [version] (default) install the given version or list R versions available for quick install and prompt for one if none is provided" + echo "'-r' or 'rversions' list the R versions available for quick install, one per line" + echo "'-v' or 'versions' shows the version of this command" + echo "'-h' or 'help' show this info" +} + # Choose a command to perform case ${SCRIPT_ACTION} in - "install") + "-i"|"install") do_install ;; - "versions") + "-r"|"rversions") do_show_versions ;; + "-v"|"version") + echo "r-builds quick install version ${THIS_VERSION}" + ;; + "-h"|"help"|*) + do_show_usage + ;; esac