1
1
#! /bin/bash
2
+ # shellcheck disable=SC2155
2
3
3
4
# default values
5
+ # shellcheck disable=SC2076
4
6
if [ -z " $PIPE_CONDOR_STATUS " ]; then
5
7
export PIPE_CONDOR_STATUS=enable
6
8
elif [[ ! " enable disable " =~ " $PIPE_CONDOR_STATUS " ]]; then
10
12
if [ -z " $PIPE_CONDOR_DIR " ]; then
11
13
export PIPE_CONDOR_DIR=~ /nobackup/pipes
12
14
fi
13
- export PIPE_CONDOR_DIR=$( readlink -f $PIPE_CONDOR_DIR )
14
- mkdir -p $PIPE_CONDOR_DIR
15
+ export PIPE_CONDOR_DIR=$( readlink -f " $PIPE_CONDOR_DIR " )
16
+ mkdir -p " $PIPE_CONDOR_DIR "
15
17
# ensure the pipe dir is bound
16
18
export APPTAINER_BIND=${APPTAINER_BIND}${APPTAINER_BIND: +,}${PIPE_CONDOR_DIR}
17
19
@@ -20,23 +22,23 @@ export APPTAINER_BIND=${APPTAINER_BIND}${APPTAINER_BIND:+,}${PIPE_CONDOR_DIR}
20
22
# execute command sent to host pipe; send output to container pipe; store exit code
21
23
listenhost (){
22
24
# stop when host pipe is removed
23
- while [ -e $1 ]; do
25
+ while [ -e " $1 " ]; do
24
26
# "|| true" is necessary to stop "Interrupted system call"
25
27
# must be *inside* eval to ensure EOF once command finishes
26
28
# now replaced with assignment of exit code to local variable (which also returns true)
27
29
tmpexit=0
28
- eval " $( cat $1 ) || tmpexit=" ' $?' >& $2
29
- echo $tmpexit > $3
30
+ eval " $( cat " $1 " ) || tmpexit=" ' $?' >& " $2 "
31
+ echo " $tmpexit " > " $3 "
30
32
done
31
33
}
32
34
export -f listenhost
33
35
34
36
# creates randomly named pipe and prints the name
35
37
makepipe (){
36
- PREFIX=$1
38
+ PREFIX=" $1 "
37
39
PIPETMP=${PIPE_CONDOR_DIR} /${PREFIX} _$( uuidgen)
38
- mkfifo $PIPETMP
39
- echo $PIPETMP
40
+ mkfifo " $PIPETMP "
41
+ echo " $PIPETMP "
40
42
}
41
43
export -f makepipe
42
44
@@ -52,14 +54,14 @@ export -f startpipe
52
54
53
55
# sends function to host, then listens for output, and provides exit code from function
54
56
call_host (){
55
- if [ " $FUNCNAME " = " call_host" ]; then
57
+ if [ " ${ FUNCNAME[0]} " = " call_host" ]; then
56
58
FUNCTMP=
57
59
else
58
- FUNCTMP=$ FUNCNAME
60
+ FUNCTMP=" ${ FUNCNAME[0]} "
59
61
fi
60
- echo " cd $PWD ; $FUNCTMP $@ " > $HOSTPIPE
61
- cat < $CONTPIPE
62
- return $( cat < $EXITPIPE )
62
+ echo " cd $PWD ; $FUNCTMP $* " > " $HOSTPIPE "
63
+ cat < " $CONTPIPE "
64
+ return " $( cat < " $EXITPIPE " ) "
63
65
}
64
66
export -f call_host
65
67
@@ -80,27 +82,29 @@ export APPTAINERENV_APPTAINER_ORIG=$APPTAINER_ORIG
80
82
apptainer (){
81
83
if [ " $PIPE_CONDOR_STATUS " = " disable" ]; then
82
84
(
85
+ # shellcheck disable=SC2030
83
86
export APPTAINERENV_PIPE_CONDOR_STATUS=disable
84
87
$APPTAINER_ORIG " $@ "
85
88
)
86
89
else
87
90
# in subshell to contain exports
88
91
(
92
+ # shellcheck disable=SC2031
89
93
export APPTAINERENV_PIPE_CONDOR_STATUS=enable
90
94
# only start pipes on host
91
95
# i.e. don't create more pipes/listeners for nested containers
92
96
if [ -z " $APPTAINER_CONTAINER " ]; then
93
- eval $( startpipe)
94
- listenhost $APPTAINERENV_HOSTPIPE $APPTAINERENV_CONTPIPE $APPTAINERENV_EXITPIPE &
97
+ eval " $( startpipe) "
98
+ listenhost " $APPTAINERENV_HOSTPIPE " " $APPTAINERENV_CONTPIPE " " $APPTAINERENV_EXITPIPE " &
95
99
LISTENER=$!
96
100
fi
97
101
# actually run apptainer
98
102
$APPTAINER_ORIG " $@ "
99
103
# avoid dangling cat process after exiting container
100
104
# (again, only on host)
101
105
if [ -z " $APPTAINER_CONTAINER " ]; then
102
- pkill -P $LISTENER
103
- rm -f $APPTAINERENV_HOSTPIPE $APPTAINERENV_CONTPIPE $APPTAINERENV_EXITPIPE
106
+ pkill -P " $LISTENER "
107
+ rm -f " $APPTAINERENV_HOSTPIPE " " $APPTAINERENV_CONTPIPE " " $APPTAINERENV_EXITPIPE "
104
108
fi
105
109
)
106
110
fi
@@ -112,7 +116,8 @@ if [ -z "$APPTAINER_CONTAINER" ]; then
112
116
export APPTAINERENV_HOSTFNS=$( compgen -c | grep ^condor_)
113
117
# in container: replace with call_host versions
114
118
elif [ " $PIPE_CONDOR_STATUS " = " enable" ]; then
119
+ # shellcheck disable=SC2153
115
120
for HOSTFN in $HOSTFNS ; do
116
- copy_function call_host $HOSTFN
121
+ copy_function call_host " $HOSTFN "
117
122
done
118
123
fi
0 commit comments