-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbioconductor
executable file
·149 lines (134 loc) · 5.03 KB
/
bioconductor
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
show_help() {
echo "Usage: bioconductor.sh [-v version] [-e envtype] [-p port] [-w password] [-d dockerhome] [-l] [-h]"
echo " -v version Specify the Bioconductor version (e.g., 'devel', 'RELEASE_X_Y', 'X.Y')."
echo " -e envtype Specify the environment type ('rstudio', 'bash', or 'R'). Default is 'rstudio'."
echo " -p port Specify the port number. Default is 8787."
echo " -w password Specify the RStudio password. Default is 'bioc'."
echo " -d dockerhome Specify the Docker home directory. Default is '$HOME/dockerhome'."
echo " -l List all available Bioconductor Docker versions."
echo " -h Show this help message."
echo ""
echo "The \$DOCKER_RPKGS environment variable is optional and used to specify the R packages directory on the host machine."
echo "If not set, the default is '\$HOME/.docker-\$version-packages'."
echo "This directory is mounted into the Docker container at /usr/local/lib/R/host-site-library."
echo "This allows R packages installed in the container to be persisted on the host machine and shared across multiple containers or sessions."
}
list_versions() {
echo "Fetching available versions from Docker Hub..."
curl -s https://registry.hub.docker.com/v2/repositories/bioconductor/bioconductor_docker/tags?page_size=100 | jq -r '.results[].name'
}
version=""
envtype="rstudio"
port=8787
password="bioc"
DOCKER_HOME="$HOME/dockerhome"
while getopts ":v:e:p:w:d:lh" opt; do
case ${opt} in
v )
version=$OPTARG
;;
e )
envtype=$OPTARG
;;
p )
port=$OPTARG
;;
w )
password=$OPTARG
;;
d )
DOCKER_HOME=$OPTARG
;;
l )
list_versions
exit 0
;;
h )
show_help
exit 0
;;
\? )
show_help
exit 1
;;
esac
done
if [ -z "$version" ]; then
echo "Error: Version is required. Use the '-v' flag to specify a version. Use the '-l' flag to list available versions or the '-h' flag for examples."
exit 1
fi
GVER=$(echo "$version" | grep -E "^[3-4]\.[0-9]{1,2}.*")
if [[ -z "${version// }" || ($version != RELEASE_* && $version != devel* && -z "${GVER// }") ]]; then
echo "Enter either 'devel*', 'X.Y', or 'RELEASE_X_Y' version"
exit 1
fi
if [ -z "${envtype// }" ]; then
echo "Empty 'envtype' using default: rstudio"
envtype="rstudio"
elif [ "$envtype" == "shell" ]; then
envtype="bash"
fi
if [[ "$envtype" != "rstudio" && "$envtype" != "bash" && "$envtype" != "R" ]]; then
echo "Enter either 'rstudio', 'bash', or 'R' environment type"
exit 2
fi
biocdocker=bioconductor/bioconductor_docker:"$version"
docker pull $biocdocker
DOCKER_RPKGS="$HOME/.docker-$version-packages"
R_LIBS='/usr/local/lib/R/host-site-library:/usr/local/lib/R/site-library:/usr/local/lib/R/library'
mkdir -p "$DOCKER_RPKGS"
mkdir -p "$DOCKER_HOME"
if [ ! -f "$DOCKER_HOME/.Renviron" ]; then
echo "R_LIBS=$R_LIBS" > $DOCKER_HOME/.Renviron
fi
TOKEN_EXP='GITHUB_[P|T].*'
GPAT=$(grep "$TOKEN_EXP" ~/.Renviron)
GRENV=$(grep "$TOKEN_EXP" $DOCKER_HOME/.Renviron)
if [ ! -z "${GPAT// }" ] && [ -z "${GRENV// }" ]; then
echo $GPAT >> $DOCKER_HOME/.Renviron
fi
HLIBUSER=$(grep "R_LIBS_USER" ~/.Renviron)
if [ -z "${HLIBENV// }" ]; then
echo "R_LIBS_USER=/usr/local/lib/R/host-site-library" >> $DOCKER_HOME/.Renviron
fi
copy_config() {
for arg in "$@"; do
FILE="$HOME/$arg"
if [ -e ${FILE} ] && [ ! -e $DOCKER_HOME/$arg ]; then
cat $FILE > $DOCKER_HOME/$arg
fi
done
}
copy_config .Rprofile .gitconfig .inputrc
echo ""
echo "=================================================="
echo "Installed packages will go in host directory: $DOCKER_RPKGS"
echo "RStudio home directory will be mounted on host directory: $DOCKER_HOME"
echo "=================================================="
echo ""
if [ "$envtype" == "rstudio" ]; then
echo "=================================================="
echo "Open RStudio running Bioconductor version $version at http://localhost:$port"
echo "Login with username: rstudio and password: $password"
echo "=================================================="
docker run -e PASSWORD=$password \
-v $DOCKER_HOME:/home/rstudio \
-v $DOCKER_RPKGS:/usr/local/lib/R/host-site-library \
-e USERID=$UID \
-p $port:8787 \
$biocdocker \
bash -c 'chown -R rstudio /home/rstudio; chown -R rstudio /usr/local/lib/R/host-site-library; /init'
elif [ "$envtype" == "bash" ]; then
docker run -ti --user rstudio \
-v $DOCKER_HOME:/home/rstudio \
-v $DOCKER_RPKGS:/usr/local/lib/R/host-site-library \
-w /home/rstudio \
$biocdocker bash
elif [ "$envtype" == "R" ]; then
docker run -ti --user rstudio \
-v $DOCKER_HOME:/home/rstudio \
-v $DOCKER_RPKGS:/usr/local/lib/R/host-site-library \
-w /home/rstudio \
$biocdocker R
fi