#!/bin/bash # © Copyright IBM Corporation 2022. # LICENSE: Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) # # Instructions: # Download build script: wget https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/R/4.1.3/build_r.sh # Execute build script: bash build_r.sh (provide -h for help) # set -e -o pipefail shopt -s extglob PACKAGE_NAME="R" PACKAGE_VERSION="4.1.3" CURDIR="$(pwd)" JAVA_PROVIDED="OpenJDK" FORCE="false" TESTS="false" LOG_FILE="$CURDIR/logs/${PACKAGE_NAME}-${PACKAGE_VERSION}-$(date +"%F-%T").log" R_URL="https://cran.r-project.org/src/base/R-4" R_URL+="/R-${PACKAGE_VERSION}.tar.gz" BUILD_ENV="$HOME/setenv.sh" trap cleanup 0 1 2 ERR #Check if directory exsists if [ ! -d "$CURDIR/logs" ]; then mkdir -p "$CURDIR/logs" fi if [ -f "/etc/os-release" ]; then source "/etc/os-release" fi DISTRO="$ID-$VERSION_ID" function checkPrequisites() { if command -v "sudo" >/dev/null; then printf -- 'Sudo : Yes\n' >>"$LOG_FILE" else printf -- 'Sudo : No \n' >>"$LOG_FILE" printf -- 'Install sudo from repository using apt, yum or zypper based on your distro. \n' exit 1 fi if [[ "$FORCE" == "true" ]]; then printf -- 'Force attribute provided hence continuing with install without confirmation message\n' |& tee -a "$LOG_FILE" else # Ask user for prerequisite installation printf -- "\nAs part of the installation , dependencies would be installed/upgraded.\n" while true; do read -r -p "Do you want to continue (y/n) ? : " yn case $yn in [Yy]*) printf -- 'User responded with Yes. \n' >>"$LOG_FILE" break ;; [Nn]*) exit ;; *) echo "Please provide confirmation to proceed." ;; esac done fi } function cleanup() { # Remove artifacts printf -- "Cleaned up the artifacts\n" >> "$LOG_FILE" } function configureAndInstall(){ printf -- 'Configuration and Installation started \n' printf -- "Building R %s \n,$PACKAGE_VERSION" echo "Java provided by user $JAVA_PROVIDED" >> "$LOG_FILE" if [[ "$JAVA_PROVIDED" == "Semeru11" ]]; then # Install AdoptOpenJDK 11 (With OpenJ9) printf -- "\nInstalling IBM Semeru Runtime (previously known as AdoptOpenJDK openj9) . . . \n" cd "$CURDIR" wget https://github.com/ibmruntimes/semeru11-binaries/releases/download/jdk-11.0.14.1%2B1_openj9-0.30.1/ibm-semeru-open-jdk_s390x_linux_11.0.14.1_1_openj9-0.30.1.tar.gz tar -xf ibm-semeru-open-jdk_s390x_linux_11.0.14.1_1_openj9-0.30.1.tar.gz export JAVA_HOME=$CURDIR/jdk-11.0.14.1+1 printf -- "Installation of IBM Semeru Runtime (previously known as AdoptOpenJDK openj9) is successful\n" >> "$LOG_FILE" elif [[ "$JAVA_PROVIDED" == "Temurin11" ]]; then printf -- "\nInstalling Eclipse Adoptium Temurin Runtime (previously known as AdoptOpenJDK hotspot) . . . \n" cd $CURDIR wget https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.14.1%2B1/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.14.1_1.tar.gz tar -xf OpenJDK11U-jdk_s390x_linux_hotspot_11.0.14.1_1.tar.gz export JAVA_HOME=$CURDIR/jdk-11.0.14.1+1 printf -- "Installation of Eclipse Adoptium Temurin Runtime (previously known as AdoptOpenJDK hotspot) is successful\n" >> "$LOG_FILE" elif [[ "$JAVA_PROVIDED" == "OpenJDK" ]]; then cd "$CURDIR" case "$DISTRO" in "ubuntu-"* ) sudo apt-get install -y openjdk-11-jdk openjdk-11-jdk-headless export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-s390x/ printf -- "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-s390x/\n" >> "$BUILD_ENV" ;; "rhel-"*) sudo yum install -y java-11-openjdk java-11-openjdk-devel export JAVA_HOME=/usr/lib/jvm/java-11-openjdk printf -- "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk\n" >> "$BUILD_ENV" ;; "sles-"*) sudo zypper install -y java-11-openjdk java-11-openjdk-devel export JAVA_HOME=/usr/lib64/jvm/java-11-openjdk/ printf -- "export JAVA_HOME=/usr/lib64/jvm/java-11-openjdk/\n" >> "$BUILD_ENV" ;; esac else err "$JAVA_PROVIDED is not supported, Please use valid java from {Semeru11, Temurin11, OpenJDK} only" exit 1 fi export PATH=$JAVA_HOME/bin:/usr/local/bin:/sbin:$PATH printf -- 'export PATH=$JAVA_HOME/bin:/usr/local/bin:/sbin:$PATH\n' >> "$BUILD_ENV" printf -- 'export JAVA_HOME for "$ID" \n' >> "$LOG_FILE" cd "$CURDIR" java -version curl -sSL $R_URL | tar xzf - mkdir build && cd build ../R-${PACKAGE_VERSION}/configure --with-x=no --with-pcre1 make sudo make install # Run Tests runTest #Cleanup cleanup printf -- "\n Installation of %s %s was successful \n\n" $PACKAGE_NAME $PACKAGE_VERSION } function runTest() { if [[ "$TESTS" == "true" ]]; then printf -- "TEST Flag is set , Continue with running test \n" printf -- "Installing the dependencies for testing %s,$PACKAGE_NAME \n" case "$DISTRO" in "ubuntu-"* ) sudo apt-get install -y texlive-latex-base texlive-latex-extra \ texlive-fonts-recommended texlive-fonts-extra sudo locale-gen "en_US.UTF-8" sudo locale-gen "en_GB.UTF-8" export LANG="en_US.UTF-8" printf -- 'export LANG="en_US.UTF-8"\n' >> "$BUILD_ENV" ;; "rhel-"*) sudo yum install -y texlive export LANG="en_US.UTF-8" printf -- 'export LANG="en_US.UTF-8"\n' >> "$BUILD_ENV" ;; "sles-"*) sudo zypper install -y texlive-courier texlive-dvips export LANG="en_US.UTF-8" printf -- 'export LANG="en_US.UTF-8"\n' >> "$BUILD_ENV" ;; esac cd "$CURDIR/build" set +e make check set -e printf -- "\nTest execution completed.\n" fi } function logDetails() { printf -- '**************************** SYSTEM DETAILS *************************************************************\n' >"$LOG_FILE" if [ -f "/etc/os-release" ]; then cat "/etc/os-release" >>"$LOG_FILE" fi cat /proc/version >>"$LOG_FILE" printf -- '*********************************************************************************************************\n' >>"$LOG_FILE" printf -- "Detected %s \n" "$PRETTY_NAME" printf -- "Request details : PACKAGE NAME= %s , VERSION= %s \n" "$PACKAGE_NAME" "$PACKAGE_VERSION" |& tee -a "$LOG_FILE" } # Print the usage message function printHelp(){ cat <