one-click-installation-script/R.sh

89 lines
4.2 KiB
Bash
Raw Normal View History

2023-04-01 18:09:09 +08:00
#!/usr/bin/env bash
#by spiritlhl
#from https://github.com/spiritLHLS/one-click-installation-script
#version: 2023.04.01
ver="2022.04.01"
2023-04-01 18:31:16 +08:00
changeLog="一键安装R语言环境"
2023-04-01 18:09:09 +08:00
source ~/.bashrc
red(){ echo -e "\033[31m\033[01m$1$2\033[0m"; }
green(){ echo -e "\033[32m\033[01m$1$2\033[0m"; }
yellow(){ echo -e "\033[33m\033[01m$1$2\033[0m"; }
2023-04-01 18:14:50 +08:00
blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
2023-04-01 18:09:09 +08:00
reading(){ read -rp "$(green "$1")" "$2"; }
REGEX=("debian" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky" "'amazon linux'" "fedora" "arch")
RELEASE=("Debian" "Ubuntu" "CentOS" "CentOS" "Fedora" "Arch")
PACKAGE_UPDATE=("! apt-get update && apt-get --fix-broken install -y && apt-get update" "apt-get update" "yum -y update" "yum -y update" "yum -y update" "pacman -Sy")
PACKAGE_INSTALL=("apt-get -y install" "apt-get -y install" "yum -y install" "yum -y install" "yum -y install" "pacman -Sy --noconfirm --needed")
PACKAGE_REMOVE=("apt-get -y remove" "apt-get -y remove" "yum -y remove" "yum -y remove" "yum -y remove" "pacman -Rsc --noconfirm")
PACKAGE_UNINSTALL=("apt-get -y autoremove" "apt-get -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove" "")
CMD=("$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)" "$(hostnamectl 2>/dev/null | grep -i system | cut -d : -f2)" "$(lsb_release -sd 2>/dev/null)" "$(grep -i description /etc/lsb-release 2>/dev/null | cut -d \" -f2)" "$(grep . /etc/redhat-release 2>/dev/null)" "$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')" "$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)")
SYS="${CMD[0]}"
[[ -n $SYS ]] || exit 1
for ((int = 0; int < ${#REGEX[@]}; int++)); do
if [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]]; then
SYSTEM="${RELEASE[int]}"
[[ -n $SYSTEM ]] && break
fi
done
apt-get --fix-broken install -y > /dev/null 2>&1
clear
echo "#######################################################################"
2023-04-01 18:31:16 +08:00
echo "# ${YELLOW}一键安装R语言环境${PLAIN} #"
2023-04-01 18:09:09 +08:00
echo "# 版本:$ver #"
echo "# 更新日志:$changeLog #"
echo "# ${GREEN}作者${PLAIN}: spiritlhl #"
2023-04-01 18:31:16 +08:00
echo "# ${GREEN}仓库${PLAIN}: https://github.com/spiritLHLS/one-click-installation-script #"
2023-04-01 18:09:09 +08:00
echo "#######################################################################"
echo "验证已支持的系统:"
echo "Ubuntu 18/20/22 - 推荐,脚本自动挂起到后台"
echo "Debian 9/10/11 - 还行,需要手动挂起到后台,详看脚本运行安装完毕的后续提示"
echo "可能支持的系统centos 7+FedoraAlmalinux 8.5+"
2023-04-01 18:40:21 +08:00
yellow "安装前需用Miniconda3安装虚拟环境jupyter-env再进行jupyter和jupyterlab的安装R环境和内核安装完毕后需要重启jupyter加载内核"
yellow "简单的说需要执行本仓库对应的jupyter安装脚本再运行本脚本安装R语言环境"
2023-04-01 18:09:09 +08:00
yellow "如果是初次安装无脑回车即可,按照提示进行操作即可"
checkupdate(){
yellow "Updating package management sources"
${PACKAGE_UPDATE[int]} > /dev/null 2>&1
apt-key update > /dev/null 2>&1
}
checkroot(){
[[ $EUID -ne 0 ]] && echo -e "${RED}请使用 root 用户运行本脚本!${PLAIN}" && exit 1
}
checkR(){
if ! command -v R &> /dev/null
then
2023-04-01 18:18:28 +08:00
reading "R is not installed on this system. Do you want to install it? (y/n) " confirminstall
echo ""
if [ "$confirminstall" != "y" ]; then
exit 0
fi
echo "R is not installed, install R language and dependent libraries..."
${PACKAGE_INSTALL[int]} r-base libssl-dev libcurl4-openssl-dev libxml2-dev
2023-04-01 18:09:09 +08:00
else
2023-04-01 18:18:28 +08:00
echo "R is already installed, skip..."
2023-04-01 18:09:09 +08:00
fi
if ! R -q -e "library('IRkernel')" &> /dev/null
then
2023-04-01 18:18:28 +08:00
reading "IRkernel is not installed on this system. Do you want to install it? (y/n) " confirminstall
echo ""
if [ "$confirminstall" != "y" ]; then
exit 0
fi
2023-04-01 18:40:21 +08:00
source activate jupyter-env
conda install -c r r-irkernel
2023-04-01 18:18:28 +08:00
green "Installed IRkernel package and registered kernel"
2023-04-01 18:09:09 +08:00
else
2023-04-01 18:18:28 +08:00
blue "IRkernel is installed"
2023-04-01 18:09:09 +08:00
fi
}
checkroot
checkupdate
checkR
2023-04-01 18:21:29 +08:00
green "R语言已安装完毕"