harbor run -t openthoughts/tasktrove-mix-h2-language-balanced-v2-mix-h2-lang-balanced-1503harbor download openthoughts/tasktrove-mix-h2-language-balanced-v2-mix-h2-lang-balanced-1503You need to create a Bash script that successfully installs the GRASP2DB R package from specified URLs, ensuring that the downloaded file matches a given MD5 checksum. Your script should be designed to work in a specified environment and handle potential errors effectively.
The script should define the following constants:
grasp2db_1.1.0.tar.gzThe script must create a staging directory in which to download the tarball:
$PREFIX/share/$PKG_NAME-$PKG_VERSION-$PKG_BUILDNUM.It should attempt to download the tarball from each URL in the array. If a download is successful, it must check the MD5 checksum of the downloaded file. The platform (Linux or macOS) should determine how the checksum is verified.
If a valid file is downloaded (i.e., checksum matches), the script should:
R CMD INSTALL --library=$PREFIX/lib/R/library $TARBALL.If no valid download occurs after checking all URLs, the script should output an error message indicating failure and exit with a non-zero status.
PREFIX: The root installation directory.PKG_NAME: The name of the package.PKG_VERSION: The version of the package.PKG_BUILDNUM: The build number of the package.Your script should be located at /app/ and named install_grasp2db.sh. Ensure the script has executable permissions set (chmod +x) prior to running the verifier.
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.13/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"
"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