forked from Dfam-consortium/TETools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdfam-tetools.sh
executable file
·134 lines (114 loc) · 2.9 KB
/
dfam-tetools.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/sh
# Dfam TE Tools container wrapper script.
# See https://github.com/Dfam-consortium/TETools for more information
# about the Dfam TE Tools container.
set -eu
workdir="$(pwd)"
# find_command name1 name2 name3 ...
# Prints the full name (as reported by command -v) for the first
# name that can be found. Exits with status 1 if no command matches
find_command() (
for attempt; do
if found="$(command -v "$attempt" 2>/dev/null)"; then
printf "%s\n" "$found"
return 0
fi
done
return 1
)
die() {
printf "%s\n" "$*" >&2
exit 1
}
usage() {
printf "%s\n" "Usage: dfam-tetools.sh [-h|--help]
[--container=/path/to/dfam-tetools.sif | --container=dfam/tetools:tag]
[--docker | --singularity]
[-- command [arg1 [arg2 [...]]]]
--container Choose a specific container to use (a .sif file or a docker image ID or tag)
--docker Run the container via docker
--singularity Run the container via singularity
command A command to run in the container instead of an interactive shell
If neither --docker nor --singularity is specified and both
programs are available, singularity is preferred."
}
## Parse command-line arguments ##
container="dfam/tetools:1.2"
use_docker=0
use_singularity=0
while [ $# -ge 1 ]; do
opt="$1"
shift
case "$opt" in
--)
break
;;
--*=*)
# Normalize "--x=y" format to "--x" "y" and try again
set -- "${opt%%=*}" "${opt#*=}" "$@"
;;
--container)
container="$1"
shift
;;
-h|--help)
usage >&2
exit 0
;;
--trf_prgm)
echo "Notice: Since Dfam TE Tools 1.2, TRF is included in the container.
The --trf_prgm parameter was ignored." >&2
shift
;;
--docker)
use_docker=1
;;
--singularity)
use_singularity=1
;;
*)
die "Unrecognized argument: $opt
A command to run in the container must be preceded by a --"
;;
esac
done
## Check argument validity ##
# Ensure exactly one of docker or singularity is used
case $(( use_docker + use_singularity )) in
0) if command -v singularity >/dev/null 2>&1; then
use_singularity=1
elif command -v docker >/dev/null 2>&1; then
use_docker=1
else
die "Error: This script requires singularity or docker to be installed and available in PATH."
fi;;
1) ;;
*) die "Only one of --docker or --singularity can be specified.";;
esac
# Ensure the container name makes sense
if [ "$use_singularity" = 1 ] && ! [ -e "$container" ]; then
# If a file named "$container" does not exist,
# we assume that "container" is a docker image reference.
# Singularity uses docker:// syntax for these
container="docker://$container"
fi
## Run the container ##
if [ "$use_docker" = 1 ]; then
docker run -it --rm \
--init \
--mount type=bind,source="$workdir",target=/work \
--user "$(id -u):$(id -g)" \
--workdir "/work" \
--env "HOME=/work" \
"$container" \
"$@"
elif [ "$use_singularity" = 1 ]; then
if [ $# -eq 0 ]; then
set -- "/bin/bash"
fi
export LANG=C
singularity exec \
"$container" \
"$@"
fi
# vi: noet ts=8 sw=0 sts=-1