#! /bin/bash R_VERSION=4.0.5 PACKAGES="mlr3filters stringi" # install sysdeps for all packages for w in $PACKAGES; do ### dynamic start export PACKAGE=$w export R_LIBS_USER=/root/user_lib mkdir -p /root/user_lib export R_VERSION=$(R --version | grep -Eo '[0-9.]+' | head -n 1) export R_VERSION_MINOR=$(echo "$R_VERSION" | cut -d. -f1,2) export ARCH=$(arch) DIST_FAM=$(grep 'ID_LIKE=' /etc/os-release | cut -d'=' -f2 | tr -d '"') if [[ $DIST_FAM == "debian" ]]; then export CODENAME=$(grep 'VERSION_CODENAME=' /etc/os-release | cut -d'=' -f2 | tr -d '"') elif [[ $DIST_FAM =~ ^(rhel) ]]; then if [[ $(grep 'PLATFORM_ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"') == "platform:el9" ]]; then export CODENAME=rhel9 elif [[ $(grep 'PLATFORM_ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"') == "platform:el8" ]]; then export CODENAME=rhel8 fi fi git clone https://github.com/cran/"${PACKAGE}".git cd "${PACKAGE}" # also installs system dependencies # FIXME: auto-detection does not work on arm-based systems export PKG_SYSREQS_PLATFORM=redhat-9 export PKG_SYSREQS=TRUE export PKG_SYSREQS_VERBOSE=TRUE R -q -e 'options(repos = c(CRAN="https://stat.ethz.ch/CRAN/")); pak::local_install_dev_deps()' cd .. done # build binaries from tags for w in $PACKAGES; do # this runs in parallel # run() { export PACKAGE=$w export R_LIBS_USER=/root/user_lib export R_VERSION=$(R --version | grep -Eo '[0-9.]+' | head -n 1) export R_VERSION_MINOR=$(echo "$R_VERSION" | cut -d. -f1,2) export ARCH=$(arch) DIST_FAM=$(grep 'ID_LIKE=' /etc/os-release | cut -d'=' -f2 | tr -d '"') if [[ $DIST_FAM == "debian" ]]; then export CODENAME=$(grep 'VERSION_CODENAME=' /etc/os-release | cut -d'=' -f2 | tr -d '"') elif [[ $DIST_FAM =~ ^(fedora) ]]; then if [[ $(grep 'PLATFORM_ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"') == "platform:el9" ]]; then export CODENAME=rhel9 elif [[ $(grep 'PLATFORM_ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"') == "platform:el8" ]]; then export CODENAME=rhel8 fi fi # example CRAN dir structure: https://cran.r-project.org/src/contrib mkdir -p /root/__linux__/"${CODENAME}"/"${R_VERSION_MINOR}"/latest/src/contrib/Archive mkdir -p /root/src/contrib/Archive cd "${PACKAGE}" # NB: we start with the latest tag as we make the greedy assumption that the latest release has all deps of the previous ones export TAGS=$(git tag -l --sort=-v:refname) for i in $TAGS; do git checkout -q -f $i # the tag might differ from the actual version TAG=$(grep "Version" DESCRIPTION | grep -Po "([0-9]+(\.[0-9]+)+)") # don't install syslibs again export PKG_SYSREQS=FALSE export PKG_SYSREQS_VERBOSE=FALSE # build source EXISTS=$(find /root/src/contrib/ | grep -P "${PACKAGE}_${TAG}") if [[ -n $EXISTS ]]; then printf "[Skip] ${PACKAGE} '${TAG}' (source), already exists.\n" # continue else printf "[Build] ${PACKAGE} '${TAG}' (source)\n" fi OUTPUT=$(R -q -e 'options(repos = c(CRAN="https://stat.ethz.ch/CRAN/")); pkgbuild::build(binary = FALSE, vignettes = FALSE, dest_path = "/root/src/contrib")') if [[ $(printf "$OUTPUT" | grep "Error") != "" ]]; then printf "[Error] ${PACKAGE} '${TAG}' (binary)\n" printf $OUTPUT >/root/__linux__/"${CODENAME}"/"${R_VERSION_MINOR}"/latest/src/contrib/"${PACKAGE}"_"${TAG}"_error continue else # build binary EXISTS=$(find /root/__linux__/"${CODENAME}"/"${R_VERSION_MINOR}"/latest/src/contrib/ | grep -P "${PACKAGE}_${TAG}") if [[ -n $EXISTS ]]; then printf "[Skip] ${PACKAGE} '${TAG}' (binary), already exists.\n" continue else printf "[Build] ${PACKAGE} '${TAG}' (binary)\n" fi R -q -e 'options(repos = c(CRAN="https://stat.ethz.ch/CRAN/")); pak::local_install_dev_deps()' R -q -e 'options(repos = c(CRAN="https://stat.ethz.ch/CRAN/")); pkgbuild::build(binary = TRUE, vignettes = FALSE, dest_path = sprintf("/root/__linux__/%s/%s/latest/src/contrib", Sys.getenv("CODENAME"), Sys.getenv("R_VERSION_MINOR")))' # remove _aarch64-unknown-linux-gnu part in filename rsync -a /root/__linux__/"${CODENAME}"/"${R_VERSION_MINOR}"/latest/src/contrib/"${PACKAGE}"_"${TAG}"*.tar.gz /root/__linux__/"${CODENAME}"/"${R_VERSION_MINOR}"/latest/src/contrib/"${PACKAGE}"_"${TAG}".tar.gz fi # create archive dir for package mkdir -p /root/__linux__/"${CODENAME}"/"${R_VERSION_MINOR}"/latest/src/contrib/Archive/"${PACKAGE}" # list all files in dir all_versions=$(ls /root/__linux__/"${CODENAME}"/"${R_VERSION_MINOR}"/latest/src/contrib/"${PACKAGE}"*.tar.gz) # Find the latest version latest_version=$(ls /root/__linux__/"${CODENAME}"/"${R_VERSION_MINOR}"/latest/src/contrib/"${PACKAGE}"*.tar.gz | sort -V | tail -n 1) # Move all other versions to the Archived directory for file in $all_versions; do if [ "$file" != "$latest_version" ]; then rsync -a "$file" /root/__linux__/"${CODENAME}"/"${R_VERSION_MINOR}"/latest/src/contrib/Archive/"${PACKAGE}"/ fi done # list all files in dir all_versions=$(ls /root/src/contrib/"${PACKAGE}"*.tar.gz) # Find the latest version latest_version=$(ls /root/src/contrib/"${PACKAGE}"*.tar.gz | sort -V | tail -n 1) # create archive dir for package mkdir -p /root/src/contrib/Archive/"${PACKAGE}" # Move all other versions to the Archived directory for file in $all_versions; do if [ "$file" != "$latest_version" ]; then rsync -a "$file" /root/src/contrib/Archive/"${PACKAGE}"/ fi done done cd .. rm -rf /root/"${PACKAGE}" # } # run & done # clean lefover files with wroning naming find /root/__linux__/rhel9/4.0/latest/src/contrib -type f -name '*aarch64-unknown-linux*' -delete find /root/src/contrib/ -type f -name '*aarch64-unknown-linux*' -delete # src R -q -e "cranlike::add_PACKAGES(list.files('/root/src/contrib/', pattern='tar.gz'), '/root/src/contrib/')" R -q -e "cranlike::package_versions('/root/src/contrib/')" # bin R -q -e "cranlike::add_PACKAGES(list.files('/root/__linux__/${CODENAME}/${R_VERSION_MINOR}/latest/src/contrib/', pattern='tar.gz'), '/root/__linux__/${CODENAME}/${R_VERSION_MINOR}/latest/src/contrib/')" R -q -e "cranlike::package_versions('/root/__linux__/${CODENAME}/${R_VERSION_MINOR}/latest/src/contrib/')"