-
Notifications
You must be signed in to change notification settings - Fork 0
/
datalad
executable file
·68 lines (51 loc) · 2.02 KB
/
datalad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
real_path=$(realpath $0)
if test $# -eq 1 -a "X$1" = "X-h" ; then
cat <<USAGE
You are running the bash script:
$real_path
This is a wrapper script to invoke datalad from an apptainer container.
The script will work with any program in the configured container.
For this script to work, the container must be called 'datalad.sif'
and be installed in the same directory as the script, or the container's
full path can be specified by the environment variable DATALAD_SIF.
The program invoked by the script is determined by the basename of the
script. To make it invoke 'git-annex', for instance, a symbolic link or
a hard link can be made to the script using the new name 'git-annex'.
Once properly configured, this makes the invoked command completely
transparent, except in the case where a single '-h' is provided, and
then you read this text right here.
100% by pierre.rioux@mcgill.ca
USAGE
exit 1
fi
this_loc=$(dirname $real_path)
this_exec=$(basename $0)
datalad_image=${DATALAD_SIF:-$this_loc/datalad.sif}
if ! test -f "$datalad_image" ; then
cat <<ERROR
Error: cannot find apptainer image file 'datalad.sif'.
Install it alongside this wrapper script as
$this_loc/datalad.sif
or specify it with a full path in the environment variable 'DATALAD_SIF'
ERROR
exit 2
fi
if test -z "$(type -p apptainer)" ; then
echo "Error: apptainer is not installed."
exit 2
fi
git_root=$(git rev-parse --show-toplevel 2>/dev/null)
if test -z "$git_root" ; then
git_root=$(pwd -P)
fi
bind_root=$(dirname "$git_root")
# Append new bindpath
test -n "$APPTAINER_BINDPATH" && APPTAINER_BINDPATH="$APPTAINER_BINDPATH,"
export APPTAINER_BINDPATH="$APPTAINER_BINDPATH$bind_root"
# This env variable is only needed for the datalad container
# that includes the ebrains module. Otherwise it will be ignored.
export APPTAINERENV_KG_AUTH_TOKEN="$KG_AUTH_TOKEN"
# Execute datalad or git-annex or any other exec inside the container
# while providing all the other arguments
exec apptainer -s exec --cleanenv "$datalad_image" "$this_exec" "$@"