Skip to content

Instantly share code, notes, and snippets.

@toniher
Last active March 24, 2023 15:35
Show Gist options
  • Save toniher/65ccf76a8903bf432435d490b2025fab to your computer and use it in GitHub Desktop.
Save toniher/65ccf76a8903bf432435d490b2025fab to your computer and use it in GitHub Desktop.
Simple script for predownloading Singularity images in order to be convenient to be used by Nextflow. Useful for issues like this: https://github.com/nextflow-io/nextflow/issues/1210
#!/usr/bin/env bash
CONFILE=${1:-nextflow.config}
OUTDIR=${2:-./singularity}
if [ ! -e $CONFILE ]; then
echo "$CONFILE does not exist"
exit
fi
TMPFILE=`mktemp`
CURDIR=$(pwd)
mkdir -p $OUTDIR
cat ${CONFILE}|grep 'container'|perl -lane 'if ( $_=~/container\s*\=\s*\"(\S+)\"/ ) { $_=~/container\s*\=\s*\"(\S+)\"/; print $1 unless ( $1=~/^\s*$/ or $1=~/\.sif/ or $1=~/\.img/ ) ; }' > $TMPFILE
cd ${OUTDIR}
while IFS= read -r line; do
name=$line
name=${name/:/-}
name=${name//\//-}
echo $name
singularity pull ${name}.img docker://$line
done < $TMPFILE
cd $CURDIR
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment