harbor run -t openthoughts/tasktrove-exp-rpt-stack-bash-withtests-v2-stack-bash-withtests-9461harbor download openthoughts/tasktrove-exp-rpt-stack-bash-withtests-v2-stack-bash-withtests-9461Task Description: Implement R Package Installation Script
Functionality to be Built: Create a Bash script that downloads a specified R package tarball file from a list of URLs, verifies its integrity using an MD5 checksum, and installs the package into the R library directory. The script should handle both Linux and MacOS platforms, ensure proper staging areas for downloads without permission issues, and clean up temporary files after installation.
Expected Inputs:
grasp2db_1.1.0.tar.gz).Expected Outputs:
R CMD INSTALL, resulting in a successful installation message. If none of the URLs are reachable or the checksum fails, the script should print an error message indicating the failure and exit with a non-zero status.File Locations and Naming:
install_grasp2db.sh./app/ directory.Ensure that the script correctly creates a staging area in the installation path ($PREFIX/share/$PKG_NAME-$PKG_VERSION-$PKG_BUILDNUM), downloads the tarball to this location, and cleans up all temporary files and directories after the installation is complete.
The following test script will be used to verify your solution:
#!/bin/bash
FN="grasp2db_1.1.0.tar.gz"
URLS=(
"https://bioconductor.org/packages/3.14/data/annotation/src/contrib/grasp2db_1.1.0.tar.gz"
"https://bioarchive.galaxyproject.org/grasp2db_1.1.0.tar.gz"
"https://depot.galaxyproject.org/software/bioconductor-grasp2db/bioconductor-grasp2db_1.1.0_src_all.tar.gz"
)
MD5="3fc90fc7c99e7da51dcbb687fd2d5515"
# Use a staging area in the conda dir rather than temp dirs, both to avoid
# permission issues as well as to have things downloaded in a predictable
# manner.
STAGING=$PREFIX/share/$PKG_NAME-$PKG_VERSION-$PKG_BUILDNUM
mkdir -p $STAGING
TARBALL=$STAGING/$FN
SUCCESS=0
for URL in ${URLS[@]}; do
curl $URL > $TARBALL
[[ $? == 0 ]] || continue
# Platform-specific md5sum checks.
if [[ $(uname -s) == "Linux" ]]; then
if md5sum -c <<<"$MD5 $TARBALL"; then
SUCCESS=1
break
fi
else if [[ $(uname -s) == "Darwin" ]]; then
if [[ $(md5 $TARBALL | cut -f4 -d " ") == "$MD5" ]]; then
SUCCESS=1
break
fi
fi
fi
done
if [[ $SUCCESS != 1 ]]; then
echo "ERROR: post-link.sh was unable to download any of the following URLs with the md5sum $MD5:"
printf '%s\n' "${URLS[@]}"
exit 1
fi
# Install and clean up
R CMD INSTALL --library=$PREFIX/lib/R/library $TARBALL
rm $TARBALL
rmdir $STAGING