satyaortiz-gagne commited on
Commit
df0fcce
·
1 Parent(s): ca1cc8e

Add scripts/datalad.sh

Browse files
.gitattributes CHANGED
@@ -8,3 +8,5 @@
8
  *.h annex.largefiles=nothing
9
  *.py annex.largefiles=nothing
10
  *.sh annex.largefiles=nothing
 
 
 
8
  *.h annex.largefiles=nothing
9
  *.py annex.largefiles=nothing
10
  *.sh annex.largefiles=nothing
11
+
12
+ scripts/* annex.largefiles=nothing
.gitignore CHANGED
@@ -1 +1,2 @@
1
  .nfs*
 
 
1
  .nfs*
2
+ /.tmp/
scripts/datalad.sh ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ source scripts/utils.sh echo -n
4
+
5
+ function install_datalad {
6
+ init_venv --name venv --tmp .tmp/
7
+ exit_on_error_code "Failed to init venv"
8
+
9
+ datalad --version >/dev/null 2>&1 || python3 -m pip install -r scripts/requirements_datalad.txt
10
+ exit_on_error_code "Failed to install datalad requirements: pip install"
11
+ }
12
+
13
+ datalad --version >/dev/null 2>&1 || install_datalad
14
+ exit_on_error_code "Failed to install datalad requirements: pip install"
15
+ datalad "$@"
scripts/get_utils.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ wget -O scripts/utils.sh https://raw.githubusercontent.com/satyaog/datasets_utils/095f79be167b721fbff34e45146dba519c44c305/utils.sh
scripts/requirements_datalad.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ datalad==0.11.8
scripts/utils.sh ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ function exit_on_error_code {
4
+ local _ERR=$?
5
+ if [[ ${_ERR} -ne 0 ]]
6
+ then
7
+ >&2 echo "$(tput setaf 1)ERROR$(tput sgr0): $1: ${_ERR}"
8
+ exit ${_ERR}
9
+ fi
10
+ }
11
+
12
+ function test_enhanced_getopt {
13
+ ! getopt --test > /dev/null
14
+ if [[ ${PIPESTATUS[0]} -ne 4 ]]
15
+ then
16
+ >&2 echo "enhanced getopt is not available in this environment"
17
+ exit 1
18
+ fi
19
+ }
20
+
21
+ function enhanced_getopt {
22
+ local _NAME=$0
23
+ while [[ $# -gt 0 ]]
24
+ do
25
+ local _arg="$1"; shift
26
+ case "${_arg}" in
27
+ --options) local _OPTIONS="$1"; shift ;;
28
+ --longoptions) local _LONGOPTIONS="$1"; shift ;;
29
+ --name) local _NAME="$1"; shift ;;
30
+ --) break ;;
31
+ -h | --help | *)
32
+ if [[ "${_arg}" != "-h" ]] && [[ "${_arg}" != "--help" ]]
33
+ then
34
+ >&2 echo "Unknown option [${_arg}]"
35
+ fi
36
+ >&2 echo "Options for $(basename "$0") are:"
37
+ >&2 echo "--options OPTIONS The short (one-character) options to be recognized"
38
+ >&2 echo "--longoptions LONGOPTIONS The long (multi-character) options to be recognized"
39
+ >&2 echo "--name NAME name that will be used by the getopt routines when it reports errors"
40
+ exit 1
41
+ ;;
42
+ esac
43
+ done
44
+
45
+ local _PARSED=`getopt --options="${_OPTIONS}" --longoptions="${_LONGOPTIONS}" --name="${_NAME}" -- "$@"`
46
+ if [[ ${PIPESTATUS[0]} -ne 0 ]]
47
+ then
48
+ exit 2
49
+ fi
50
+
51
+ echo "${_PARSED}"
52
+ }
53
+
54
+ function init_conda_env {
55
+ while [[ $# -gt 0 ]]
56
+ do
57
+ local _arg="$1"; shift
58
+ case "${_arg}" in
59
+ --name) local _NAME="$1"; shift
60
+ echo "name = [${_NAME}]"
61
+ ;;
62
+ --tmp) local _TMPDIR="$1"; shift
63
+ echo "tmp = [${_TMPDIR}]"
64
+ ;;
65
+ -h | --help | *)
66
+ if [[ "${_arg}" != "-h" ]] && [[ "${_arg}" != "--help" ]]
67
+ then
68
+ >&2 echo "Unknown option [${_arg}]"
69
+ fi
70
+ >&2 echo "Options for $(basename "$0") are:"
71
+ >&2 echo "--name NAME conda env prefix name"
72
+ >&2 echo "--tmp DIR tmp dir to hold the conda prefix"
73
+ exit 1
74
+ ;;
75
+ esac
76
+ done
77
+
78
+ # Configure conda for bash shell
79
+ eval "$(conda shell.bash hook)"
80
+
81
+ if [[ ! -d "${_TMPDIR}/env/${_NAME}/" ]]
82
+ then
83
+ conda create --prefix "${_TMPDIR}/env/${_NAME}/" --yes --no-default-packages || \
84
+ exit_on_error_code "Failed to create ${_NAME} conda env"
85
+ fi
86
+
87
+ conda activate "${_TMPDIR}/env/${_NAME}/" && \
88
+ exit_on_error_code "Failed to activate ${_NAME} conda env"
89
+ }
90
+
91
+ function init_venv {
92
+ while [[ $# -gt 0 ]]
93
+ do
94
+ local _arg="$1"; shift
95
+ case "${_arg}" in
96
+ --name) local _NAME="$1"; shift
97
+ echo "name = [${_NAME}]"
98
+ ;;
99
+ --tmp) local _TMPDIR="$1"; shift
100
+ echo "tmp = [${_TMPDIR}]"
101
+ ;;
102
+ -h | --help | *)
103
+ if [[ "${_arg}" != "-h" ]] && [[ "${_arg}" != "--help" ]]
104
+ then
105
+ >&2 echo "Unknown option [${_arg}]"
106
+ fi
107
+ >&2 echo "Options for $(basename "$0") are:"
108
+ >&2 echo "--name NAME venv prefix name"
109
+ >&2 echo "--tmp DIR tmp dir to hold the virtualenv prefix"
110
+ exit 1
111
+ ;;
112
+ esac
113
+ done
114
+
115
+ if [[ ! -d "${_TMPDIR}/venv/${_NAME}/" ]]
116
+ then
117
+ mkdir -p "${_TMPDIR}/venv/${_NAME}/" && \
118
+ virtualenv --no-download "${_TMPDIR}/venv/${_NAME}/" || \
119
+ exit_on_error_code "Failed to create ${_NAME} venv"
120
+ fi
121
+
122
+ source "${_TMPDIR}/venv/${_NAME}/bin/activate" || \
123
+ exit_on_error_code "Failed to activate ${_NAME} venv"
124
+ python3 -m pip install --no-index --upgrade pip
125
+ }
126
+
127
+ function unshare_mount {
128
+ if [[ ${EUID} -ne 0 ]]
129
+ then
130
+ unshare -rm ./"${BASH_SOURCE[0]}" unshare_mount "$@" <&0
131
+ exit $?
132
+ fi
133
+
134
+ if [[ -z ${_SRC} ]]
135
+ then
136
+ local _SRC=${PWD}
137
+ fi
138
+ while [[ $# -gt 0 ]]
139
+ do
140
+ local _arg="$1"; shift
141
+ case "${_arg}" in
142
+ --src) local _SRC="$1"; shift
143
+ echo "src = [${_SRC}]"
144
+ ;;
145
+ --dir) local _DIR="$1"; shift
146
+ echo "dir = [${_DIR}]"
147
+ ;;
148
+ --cd) local _CD=1
149
+ echo "cd = [${_CD}]"
150
+ ;;
151
+ --) break ;;
152
+ -h | --help | *)
153
+ if [[ "${_arg}" != "-h" ]] && [[ "${_arg}" != "--help" ]]
154
+ then
155
+ >&2 echo "Unknown option [${_arg}]"
156
+ fi
157
+ >&2 echo "Options for $(basename "$0") are:"
158
+ >&2 echo "[--dir DIR] mount location"
159
+ >&2 echo "[--src DIR] source dir (optional)"
160
+ exit 1
161
+ ;;
162
+ esac
163
+ done
164
+
165
+ mkdir -p ${_SRC}
166
+ mkdir -p ${_DIR}
167
+
168
+ local _SRC=$(cd "${_SRC}" && pwd -P)
169
+ local _DIR=$(cd "${_DIR}" && pwd -P)
170
+
171
+ mount -o bind ${_SRC} ${_DIR}
172
+ exit_on_error_code "Could not mount directory"
173
+
174
+ if [[ ! ${_CD} -eq 0 ]]
175
+ then
176
+ cd ${_DIR}
177
+ fi
178
+
179
+ unshare -U ${SHELL} -s "$@" <&0
180
+ }
181
+
182
+ # function unshare_mount {
183
+ # if [[ ${EUID} -ne 0 ]]
184
+ # then
185
+ # unshare -rm ./"${BASH_SOURCE[0]}" unshare_mount "$@" <&0
186
+ # exit $?
187
+ # fi
188
+ #
189
+ # if [[ -z ${_SRC} ]]
190
+ # then
191
+ # local _SRC=${PWD}
192
+ # fi
193
+ # if [[ -z ${_DIR} ]]
194
+ # then
195
+ # local _DIR=${_PWD}
196
+ # fi
197
+ # while [[ $# -gt 0 ]]
198
+ # do
199
+ # local _arg="$1"; shift
200
+ # case "${_arg}" in
201
+ # --src) local _SRC="$1"; shift
202
+ # echo "src = [${_SRC}]"
203
+ # ;;
204
+ # --upper) local _UPPER="$1"; shift
205
+ # echo "upper = [${_UPPER}]"
206
+ # ;;
207
+ # --dir) local _DIR="$1"; shift
208
+ # echo "dir = [${_DIR}]"
209
+ # ;;
210
+ # --wd) local _WD="$1"; shift
211
+ # echo "wd = [${_WD}]"
212
+ # ;;
213
+ # --cd) local _CD=1
214
+ # echo "cd = [${_CD}]"
215
+ # ;;
216
+ # --) break ;;
217
+ # -h | --help | *)
218
+ # if [[ "${_arg}" != "-h" ]] && [[ "${_arg}" != "--help" ]]
219
+ # then
220
+ # >&2 echo "Unknown option [${_arg}]"
221
+ # fi
222
+ # >&2 echo "Options for $(basename "$0") are:"
223
+ # >&2 echo "[--upper DIR] upper mount overlay"
224
+ # >&2 echo "[--wd DIR] overlay working directory"
225
+ # >&2 echo "[--src DIR] lower mount overlay (optional)"
226
+ # >&2 echo "[--dir DIR] mount location (optional)"
227
+ # exit 1
228
+ # ;;
229
+ # esac
230
+ # done
231
+ #
232
+ # mkdir -p ${_SRC}
233
+ # mkdir -p ${_UPPER}
234
+ # mkdir -p ${_WD}
235
+ # mkdir -p ${_DIR}
236
+ #
237
+ # local _SRC=$(cd "${_SRC}" && pwd -P) || echo "${_SRC}"
238
+ # local _UPPER=$(cd "${_UPPER}" && pwd -P)
239
+ # local _WD=$(cd "${_WD}" && pwd -P)
240
+ # local _DIR=$(cd "${_DIR}" && pwd -P)
241
+ #
242
+ # mount -t overlay overlay -o lowerdir="${_SRC}",upperdir="${_UPPER}",workdir="${_WD}" "${_DIR}"
243
+ # exit_on_error_code "Could not mount overlay"
244
+ #
245
+ # if [[ ! ${_CD} -eq 0 ]]
246
+ # then
247
+ # cd ${_DIR}
248
+ # fi
249
+ #
250
+ # unshare -U ${SHELL} -s "$@" <&0
251
+ # }
252
+
253
+ if [[ ! -z "$@" ]]
254
+ then
255
+ "$@"
256
+ fi