Skip to content

Commit f68d96d

Browse files
committed
shellcheck
1 parent b45d1e0 commit f68d96d

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

pipe_condor.sh

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
2+
# shellcheck disable=SC2155
23

34
# default values
5+
# shellcheck disable=SC2076
46
if [ -z "$PIPE_CONDOR_STATUS" ]; then
57
export PIPE_CONDOR_STATUS=enable
68
elif [[ ! " enable disable " =~ " $PIPE_CONDOR_STATUS " ]]; then
@@ -10,8 +12,8 @@ fi
1012
if [ -z "$PIPE_CONDOR_DIR" ]; then
1113
export PIPE_CONDOR_DIR=~/nobackup/pipes
1214
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"
1517
# ensure the pipe dir is bound
1618
export APPTAINER_BIND=${APPTAINER_BIND}${APPTAINER_BIND:+,}${PIPE_CONDOR_DIR}
1719

@@ -20,23 +22,23 @@ export APPTAINER_BIND=${APPTAINER_BIND}${APPTAINER_BIND:+,}${PIPE_CONDOR_DIR}
2022
# execute command sent to host pipe; send output to container pipe; store exit code
2123
listenhost(){
2224
# stop when host pipe is removed
23-
while [ -e $1 ]; do
25+
while [ -e "$1" ]; do
2426
# "|| true" is necessary to stop "Interrupted system call"
2527
# must be *inside* eval to ensure EOF once command finishes
2628
# now replaced with assignment of exit code to local variable (which also returns true)
2729
tmpexit=0
28-
eval "$(cat $1) || tmpexit="'$?' >& $2
29-
echo $tmpexit > $3
30+
eval "$(cat "$1") || tmpexit="'$?' >& "$2"
31+
echo "$tmpexit" > "$3"
3032
done
3133
}
3234
export -f listenhost
3335

3436
# creates randomly named pipe and prints the name
3537
makepipe(){
36-
PREFIX=$1
38+
PREFIX="$1"
3739
PIPETMP=${PIPE_CONDOR_DIR}/${PREFIX}_$(uuidgen)
38-
mkfifo $PIPETMP
39-
echo $PIPETMP
40+
mkfifo "$PIPETMP"
41+
echo "$PIPETMP"
4042
}
4143
export -f makepipe
4244

@@ -52,14 +54,14 @@ export -f startpipe
5254

5355
# sends function to host, then listens for output, and provides exit code from function
5456
call_host(){
55-
if [ "$FUNCNAME" = "call_host" ]; then
57+
if [ "${FUNCNAME[0]}" = "call_host" ]; then
5658
FUNCTMP=
5759
else
58-
FUNCTMP=$FUNCNAME
60+
FUNCTMP="${FUNCNAME[0]}"
5961
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")"
6365
}
6466
export -f call_host
6567

@@ -80,27 +82,29 @@ export APPTAINERENV_APPTAINER_ORIG=$APPTAINER_ORIG
8082
apptainer(){
8183
if [ "$PIPE_CONDOR_STATUS" = "disable" ]; then
8284
(
85+
# shellcheck disable=SC2030
8386
export APPTAINERENV_PIPE_CONDOR_STATUS=disable
8487
$APPTAINER_ORIG "$@"
8588
)
8689
else
8790
# in subshell to contain exports
8891
(
92+
# shellcheck disable=SC2031
8993
export APPTAINERENV_PIPE_CONDOR_STATUS=enable
9094
# only start pipes on host
9195
# i.e. don't create more pipes/listeners for nested containers
9296
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" &
9599
LISTENER=$!
96100
fi
97101
# actually run apptainer
98102
$APPTAINER_ORIG "$@"
99103
# avoid dangling cat process after exiting container
100104
# (again, only on host)
101105
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"
104108
fi
105109
)
106110
fi
@@ -112,7 +116,8 @@ if [ -z "$APPTAINER_CONTAINER" ]; then
112116
export APPTAINERENV_HOSTFNS=$(compgen -c | grep ^condor_)
113117
# in container: replace with call_host versions
114118
elif [ "$PIPE_CONDOR_STATUS" = "enable" ]; then
119+
# shellcheck disable=SC2153
115120
for HOSTFN in $HOSTFNS; do
116-
copy_function call_host $HOSTFN
121+
copy_function call_host "$HOSTFN"
117122
done
118123
fi

0 commit comments

Comments
 (0)