-
Notifications
You must be signed in to change notification settings - Fork 1
/
singularity_build.sh
executable file
·281 lines (230 loc) · 7.37 KB
/
singularity_build.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/bash
# Singularity Builder
# Singularity: Application containers for Linux http://singularityware.github.io
Shelp (){
echo "Singularity Builder: build, install, and update Singularity software.
Support for Debian/Ubuntu, Centos/Fedora
USAGE: ./singularity_builder.sh <command> [options] ...
COMMANDS:
all setup, build, install [sudo]
setup install dependencies for your distribution [sudo]
build configure and make the installation, with optional --prefix and --sysconfdir
install make, and make install [sudo]
update update the installation [sudo]
OPTIONS
--prefix/-p install to specified prefix.
--devel/-d do specified commands for development version
--sysconfdir specify system config directory fot singularity.conf
Examples:
# Install dependencies, setup, build + install
sudo ./singularity_build.sh all
# Build and make, specify install to /my/path
sudo ./singularity_build.sh build --prefix=/my/path
# If you already have the needed dependencies, just install
sudo ./singularity_build.sh install
# Update to the latest release
sudo ./singularity_build.sh update
Singularity: Application containers for Linux
For additional help, see http://singularityware.github.io"
}
if [ "$#" -lt 1 ]; then
Shelp
exit 0
fi
setup () {
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
if [ -f /etc/debian_version ]; then
apt-get -y update &&
apt-get install -y apt-utils &&
apt-get install -y git \
build-essential \
libtool \
autotools-dev \
automake \
autoconf \
debootstrap \
yum \
python3-pip
elif [ -f /etc/redhat-release ]; then
rhdist=$(cat /etc/redhat-release | awk '{print $1;}')
case "$rhdist" in
"CentOS")
yum -y update &&
yum -y group install 'Development Tools' &&
yum -y install git \
libtool \
automake make \
autoconf \
debootstrap \
python3-pip
;;
"Fedora")
dnf -y update &&
dnf -y group install 'Development Tools' &&
dnf -y install git \
libtool \
automake \
autoconf \
debootstrap \
python3-pip
;;
esac
fi
echo "Successfully installed dependencies for Singularity"
}
Sremove () {
if ! SINGULARITY_PATH=`singularity_which "singularity"`; then
echo "No Singularity Installations found."
else
SINGULARITY_INSTALL_PREFIX="${SINGULARITY_PATH/"/bin/singularity"/}"
echo "Found singularity at " $SINGULARITY_INSTALL_PREFIX
rm -rf $SINGULARITY_INSTALL_PREFIX/libexec/singularity
rm -rf $SINGULARITY_INSTALL_PREFIX/etc/singularity
rm -rf $SINGULARITY_INSTALL_PREFIX/include/singularity
rm -rf $SINGULARITY_INSTALL_PREFIX/lib/singularity
rm -rf $SINGULARITY_INSTALL_PREFIX/var/lib/singularity/
rm $SINGULARITY_INSTALL_PREFIX/bin/singularity
rm $SINGULARITY_INSTALL_PREFIX/bin/run-singularity
rm $SINGULARITY_INSTALL_PREFIX/etc/bash_completion.d/singularity
fi
}
Sclone () {
if [ "$BUILDER_DEVELOPMENT" = "True" ]; then
cd /tmp && git clone -b development https://github.com/singularityware/singularity.git
echo "Cloned development branch of singularity to $PWD"
else
cd /tmp && git clone https://github.com/singularityware/singularity.git
echo "Cloned master branch of singularity to $PWD"
fi
}
Smake () {
if [ -z ${BUILDER_SYSCONFIG_DIR+x} ]; then
cd /tmp/singularity && ./autogen.sh && ./configure --prefix=$BUILDER_INSTALL_PREFIX && make
else
cd /tmp/singularity && ./autogen.sh && ./configure \
--prefix=$BUILDER_INSTALL_PREFIX
--sysconfdir=$BUILDER_SYSCONFIG_DIR && make
fi
echo "Singularity is configured at /tmp/singularity and will install to $BUILDER_INSTALL_PREFIX"
}
Sinstall () {
Smake && make install
}
# Commands
BUILDER_RUN_SETUP=False # setup
BUILDER_RUN_BUILD=False # Sclone
BUILDER_CLONE=False # Sclone Smake
BUILDER_RUN_UPDATE=False # remove Sinstall
BUILDER_RUN_INSTALL=False # remove Sinstall
BUILDER_RUN_ALL=False # remove S
# Options
BUILDER_INSTALL_PREFIX=/usr/local
BUILDER_DEVELOPMENT=False
# Step 1: Collect input arguments
while true; do
case ${1:-} in
-h|--help|help)
Shelp
exit 0
;;
"setup")
if [ "$(id -u)" != "0" ]; then
echo "Please run as root (sudo)"
exit 1
else
BUILDER_RUN_SETUP=True
fi
shift
;;
"build")
BUILDER_CLONE=True
shift
;;
-d|--dev|--devel|dev|devel)
BUILDER_DEVELOPMENT=True
export BUILDER_DEVELOPMENT
shift
;;
--sysconfdir)
shift
BUILDER_SYSCONFIG_DIR="${1:-}"
export BUILDER_SYSCONFIG_DIR
shift
;;
-p|--prefix|prefix)
shift
BUILDER_INSTALL_PREFIX="${1:-}"
export BUILDER_INSTALL_PREFIX
shift
;;
"install")
shift
if [ "$(id -u)" != "0" ]; then
echo "Please run as root (sudo)."
exit 1
else
BUILDER_RUN_INSTALL=True
fi
;;
"update")
shift
if [ "$(id -u)" != "0" ]; then
echo "Please run as root (sudo)."
exit 1
else
BUILDER_CLONE=True
BUILDER_REMOVE=True
BUILDER_RUN_UPDATE=True
fi
;;
"all")
shift
if [ "$(id -u)" != "0" ]; then
echo "Please run as root (sudo)."
exit 1
else
BUILDER_RUN_SETUP=True
BUILDER_CLONE=True
BUILDER_RUN_INSTALL=True
fi
;;
-*)
echo "Unknown option: ${1:-}"
exit 1
;;
*)
break
;;
esac
done
if [ $BUILDER_CLONE = "True" ]; then
Sclone
fi
# Install and build are redundant
if [ $BUILDER_RUN_INSTALL = "True" ]; then
BUILDER_RUN_BUILD=False
fi
if [ $BUILDER_RUN_UPDATE = "True" ]; then
Sremove
Sclone
Sinstall
echo "Finished update of Singularity"
exit 0
fi
if [ $BUILDER_RUN_ALL = "True" ]; then
setup
Sclone
Sinstall
echo "Finished setup, clone, and build, and install for Singularity"
exit 0
fi
if [ $BUILDER_RUN_SETUP = "True" ]; then
setup
fi
if [ $BUILDER_RUN_BUILD = "True" ]; then
Smake
fi
if [ $BUILDER_RUN_INSTALL = "True" ]; then
Sinstall
fi
exit 0