Commit 004cafd 1 parent 992016d commit 004cafd Copy full SHA for 004cafd
File tree 5 files changed +35
-51
lines changed
5 files changed +35
-51
lines changed Original file line number Diff line number Diff line change @@ -223,20 +223,7 @@ if [ "${#tpids[@]}" -ne "${#t1s[@]}" ]
223
223
fi
224
224
225
225
# check that SUBJECTS_DIR exists
226
- if [[ -z " ${sd} " ]]
227
- then
228
- echo " ERROR: No subject directory defined via --sd. This is required!"
229
- exit 1
230
- elif [[ ! -d " ${sd} " ]]
231
- then
232
- echo " INFO: The subject directory did not exist, creating it now."
233
- if ! mkdir -p " $sd " ; then echo " ERROR: directory creation failed" ; exit 1; fi
234
- elif [[ " $( stat -c " %u:%g" " $sd " ) " == " 0:0" ]] && [[ " $( id -u) " != " 0" ]] && [[ " $( stat -c " %a" " $sd " | tail -c 2) " -lt 6 ]]
235
- then
236
- echo " ERROR: The subject directory ($sd ) is owned by root and is not writable. FastSurfer cannot write results! "
237
- echo " This can happen if the directory is created by docker. Make sure to create the directory before invoking docker!"
238
- exit 1
239
- fi
226
+ check_create_subjects_dir_properties " $sd "
240
227
241
228
if [[ -z " $LF " ]] ; then LF=" $sd /$tid /scripts/long_fastsurfer.log" ; fi
242
229
# make sure the directory for the logfile exists, create automatically if the directory is not in $sd
Original file line number Diff line number Diff line change @@ -18,6 +18,37 @@ if [ "${PIPESTATUS[0]}" -ne 0 ] ; then
18
18
fi
19
19
export timecmd
20
20
21
+ function check_create_subjects_dir_properties()
22
+ {
23
+ # 1: subjects_dir
24
+ if [[ -z " $1 " ]]
25
+ then
26
+ echo " ERROR: No subject directory defined via --sd. This is required!"
27
+ exit 1
28
+ elif [[ ! -d " $1 " ]]
29
+ then
30
+ echo " INFO: The subject directory did not exist, creating it now."
31
+ if [[ " $( id -u) " == 0 ]] ; then echo " WARNING: Creating as root!" ; fi
32
+ if ! mkdir -p " $1 " ; then echo " ERROR: directory creation failed" ; exit 1; fi
33
+ else
34
+ if [[ " $( stat --version | head -n 1) " =~ GNU[[:space:]]coreutils ]] ; then # linux
35
+ user_group=$( stat -c " %u:%g" " $1 " )
36
+ world_access=$( stat -c " %a" " $1 " | tail -c 2)
37
+ elif [[ " $( stat -- 2>&1 | tail -n 1) " =~ ^usage:[[:space:]]stat.* -f[[:space:]]format ]] ; then # macOS
38
+ user_group=$( stat -f " %u:%g" " $1 " )
39
+ world_access=$( stat -f " %p" " $1 " | tail -c 2)
40
+ else echo " ERROR: Cannot detect stat interface!" ; exit 1
41
+ fi
42
+ if [[ " $user_group " == " 0:0" ]] && [[ " $( id -u) " != " 0" ]] && [[ " $world_access " -lt 6 ]]
43
+ then
44
+ echo " ERROR: The subject directory ($1 ) is owned by root and is not writable."
45
+ echo " FastSurfer cannot write results! This can happen if the directory is created"
46
+ echo " by docker. Make sure to create the directory before invoking docker!"
47
+ exit 1
48
+ fi
49
+ fi
50
+ }
51
+
21
52
function RunIt()
22
53
{
23
54
# parameters
Original file line number Diff line number Diff line change @@ -220,25 +220,7 @@ then
220
220
fi
221
221
222
222
# check that SUBJECTS_DIR exists
223
- if [[ -z " $SUBJECTS_DIR " ]]
224
- then
225
- echo " ERROR: No subject directory defined via --sd. This is required!"
226
- exit 1;
227
- fi
228
- if [[ ! -d " ${sd} " ]]
229
- then
230
- echo " INFO: The subject directory did not exist, creating it now."
231
- if ! mkdir -p " $SUBJECTS_DIR " ; then echo " ERROR: directory creation failed" ; exit 1; fi
232
- fi
233
- if [[ " $( stat -c " %u:%g" " $SUBJECTS_DIR " ) " == " 0:0" ]] && [[ " $( id -u) " != " 0" ]] && \
234
- [[ " $( stat -c " %a" " $SUBJECTS_DIR " | tail -c 2) " -lt 6 ]]
235
- then
236
- echo " ERROR: The subject directory ($SUBJECTS_DIR ) is owned by root and is not writable."
237
- echo " FastSurfer cannot write results! This can happen if the directory is created by"
238
- echo " docker. Make sure to create the directory before invoking docker!"
239
- exit 1;
240
- fi
241
-
223
+ check_create_subjects_dir_properties " $SUBJECTS_DIR "
242
224
243
225
# ################################# SETUP and LOGFILE ##############################
244
226
Original file line number Diff line number Diff line change @@ -563,24 +563,7 @@ if [[ "$legacy_parallel_hemi" == 1 ]] ; then
563
563
fi
564
564
fi
565
565
566
- if [[ -z " ${sd} " ]]
567
- then
568
- echo " ERROR: No subject directory defined via --sd. This is required!"
569
- exit 1
570
- fi
571
- if [[ ! -d " ${sd} " ]]
572
- then
573
- echo " INFO: The subject directory did not exist, creating it now." | tee -a " $tmpLF "
574
- if ! mkdir -p " $sd " ; then echo " ERROR: Subject directory creation failed" ; exit 1 ; fi
575
- fi
576
- if [[ " $( stat -c " %u:%g" " $sd " ) " == " 0:0" ]] && [[ " $( id -u) " != " 0" ]] && \
577
- [[ " $( stat -c " %a" " $sd " | tail -c 2) " -lt 6 ]]
578
- then
579
- echo " ERROR: The subject directory ($sd ) is owned by root and is not writable."
580
- echo " FastSurfer cannot write results! This can happen if the directory is created"
581
- echo " by docker. Make sure to create the directory before invoking docker!"
582
- exit 1
583
- fi
566
+ check_create_subjects_dir_properties " $sd "
584
567
585
568
if [[ -z " $subject " ]]
586
569
then
Original file line number Diff line number Diff line change 383
383
fi
384
384
done
385
385
debugf " $newline \n"
386
+ # the following stat command is not compatible with macOS, but srun_fastsurfer is not expected to be
386
387
shell=$( stat -c %N " /proc/$$ /exe" | cut -d" >" -f2 | tail -c +3 | head -c -2)
387
388
debug " Running in shell $shell : $( $shell --version 2> /dev/null | head -n 1) "
388
389
debug " "
You can’t perform that action at this time.
0 commit comments