Files
hartman-server/script-system-update-r

44 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Update the R binaries and RStudio-R4 application menu entry
# $1: R version number, ex. '4.1.2'
# $2: RStudio version number, ex. '2021.09.1-372'
# Copyright 2021 Bryan C. Roessler
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
is_root
if [[ $# -eq 2 ]]; then
re='^[0-9].[0-9].[0-9]$'
if [[ ! $1 =~ $re ]]; then
echo "Bad R version number"
exit 1
fi
re='^[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9]-[0-9]+$'
if [[ ! $2 =~ $re ]]; then
echo "Bad RStudio version number"
exit 1
fi
else
echo "You must provide exactly two arguments!"
echo "\$1: R version, ex. '4.1.2'"
echo "\$2: RStudio version, ex. '2021.09.1-372'"
exit 1
fi
ask_ok "Update R to version $1 and RStudio to version $2?" || exit
if sudo dnf install -y "https://cdn.rstudio.com/r/centos-7/pkgs/R-${1}-1-1.x86_64.rpm" \
"https://download2.rstudio.org/server/centos7/x86_64/rstudio-server-rhel-${2}-x86_64.rpm" \
"https://download1.rstudio.org/desktop/centos7/x86_64/rstudio-${2}-x86_64.rpm" &&
desktop_file="/usr/share/applications/rstudio-R4.desktop" &&
[[ -f "$desktop_file" ]] && sed -i "s|/opt/R/.*/bin/R|/opt/R/$1/bin/R|" "$desktop_file"; then
echo "Successfully updated R and RStudio"
exit 0
else
echo "R and RStudio update failed!"
exit 1
fi