Skip to content

Commit 922f902

Browse files
committed
style: oscap-ssh: shellcheck
1 parent 712ae85 commit 922f902

File tree

1 file changed

+56
-55
lines changed

1 file changed

+56
-55
lines changed

Diff for: utils/oscap-ssh

+56-55
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,31 @@ function usage()
9696

9797
# $1, $2, ... SSH options (pass them as separate arguments)
9898
function ssh_execute_with_options {
99-
ssh -o ControlPath="$CONTROL_SOCKET" $SSH_ADDITIONAL_OPTIONS "$@" -p "$SSH_PORT" "$SSH_HOST"
99+
ssh -o ControlPath="${CONTROL_SOCKET}" ${SSH_ADDITIONAL_OPTIONS} "$@" -p "${SSH_PORT}" "${SSH_HOST}"
100100
}
101101

102102
# $1: The SSH command.
103103
# $2: More of additional options (optional, pass one space-separated string)
104104
function ssh_execute_with_command_and_options {
105-
ssh -o ControlPath="$CONTROL_SOCKET" $SSH_ADDITIONAL_OPTIONS $2 -p "$SSH_PORT" "$SSH_HOST" "$1"
105+
ssh -o ControlPath="${CONTROL_SOCKET}" ${SSH_ADDITIONAL_OPTIONS} $2 -p "${SSH_PORT}" "${SSH_HOST}" "$1"
106106
}
107107

108108
# $1: Local filename to copy
109109
# $2: Remote destination
110110
function scp_copy_to_temp_dir {
111-
scp -o ControlPath="$CONTROL_SOCKET" -P "$SSH_PORT" $SSH_ADDITIONAL_OPTIONS "$1" "$SSH_HOST:$REMOTE_TEMP_DIR/$2"
111+
scp -o ControlPath="${CONTROL_SOCKET}" -P "${SSH_PORT}" ${SSH_ADDITIONAL_OPTIONS} "$1" "${SSH_HOST}:${REMOTE_TEMP_DIR}/$2"
112112
}
113113

114114
# $1: Local directory name to copy
115115
# $2: Remote destination
116116
function scp_copy_dir_to_temp_dir {
117-
scp -r -o ControlPath="$CONTROL_SOCKET" -P "$SSH_PORT" $SSH_ADDITIONAL_OPTIONS "$1" "$SSH_HOST:$REMOTE_TEMP_DIR/$2"
117+
scp -r -o ControlPath="${CONTROL_SOCKET}" -P "${SSH_PORT}" ${SSH_ADDITIONAL_OPTIONS} "$1" "${SSH_HOST}:${REMOTE_TEMP_DIR}/$2"
118118
}
119119

120120
# $1: Remote filename to get
121121
# $2: Local destination
122122
function scp_retreive_from_temp_dir {
123-
scp -o ControlPath="$CONTROL_SOCKET" -P "$SSH_PORT" $SSH_ADDITIONAL_OPTIONS "$SSH_HOST:$REMOTE_TEMP_DIR/$1" "$2"
123+
scp -o ControlPath="${CONTROL_SOCKET}" -P "${SSH_PORT}" ${SSH_ADDITIONAL_OPTIONS} "${SSH_HOST}:${REMOTE_TEMP_DIR}/$1" "$2"
124124
}
125125

126126
# $@: Elements to be quoted if needed
@@ -192,9 +192,9 @@ shift 2
192192
check_oscap_arguments "$@"
193193

194194
CONTROL_SOCKET_DIR=$(mktemp -d)
195-
CONTROL_SOCKET="$CONTROL_SOCKET_DIR/ssh_socket"
195+
CONTROL_SOCKET="${CONTROL_SOCKET_DIR}/ssh_socket"
196196

197-
echo "Connecting to '$SSH_HOST' on port '$SSH_PORT'..."
197+
echo "Connecting to '${SSH_HOST}' on port '${SSH_PORT}'..."
198198
ssh_execute_with_options -M -f -N -o ServerAliveInterval=60 || die "Failed to connect!"
199199
echo "Connected!"
200200

@@ -221,39 +221,39 @@ for (( i=0; i < $#-1; i++ )); do
221221
case "${oscap_args[i]}" in
222222
("--tailoring-file")
223223
LOCAL_TAILORING_PATH=${oscap_args[j]}
224-
oscap_args[j]="$REMOTE_TEMP_DIR/tailoring.xml"
224+
oscap_args[j]="${REMOTE_TEMP_DIR}/tailoring.xml"
225225
;;
226226
("--local-files")
227227
LOCAL_LOCAL_FILES_PATH=${oscap_args[j]}
228-
oscap_args[j]="$REMOTE_TEMP_DIR/local_files"
228+
oscap_args[j]="${REMOTE_TEMP_DIR}/local_files"
229229
;;
230230
("--cpe")
231231
LOCAL_CPE_PATH=${oscap_args[j]}
232-
oscap_args[j]="$REMOTE_TEMP_DIR/cpe.xml"
232+
oscap_args[j]="${REMOTE_TEMP_DIR}/cpe.xml"
233233
;;
234234
("--variables")
235235
LOCAL_VARIABLES_PATH=${oscap_args[j]}
236-
oscap_args[j]="$REMOTE_TEMP_DIR/variables.xml"
236+
oscap_args[j]="${REMOTE_TEMP_DIR}/variables.xml"
237237
;;
238238
("--directives")
239239
LOCAL_DIRECTIVES_PATH=${oscap_args[j]}
240-
oscap_args[j]="$REMOTE_TEMP_DIR/directives.xml"
240+
oscap_args[j]="${REMOTE_TEMP_DIR}/directives.xml"
241241
;;
242242
("--results")
243243
TARGET_RESULTS=${oscap_args[j]}
244-
oscap_args[j]="$REMOTE_TEMP_DIR/results.xml"
244+
oscap_args[j]="${REMOTE_TEMP_DIR}/results.xml"
245245
;;
246246
("--results-arf")
247247
TARGET_RESULTS_ARF=${oscap_args[j]}
248-
oscap_args[j]="$REMOTE_TEMP_DIR/results-arf.xml"
248+
oscap_args[j]="${REMOTE_TEMP_DIR}/results-arf.xml"
249249
;;
250250
("--report")
251251
TARGET_REPORT=${oscap_args[j]}
252-
oscap_args[j]="$REMOTE_TEMP_DIR/report.html"
252+
oscap_args[j]="${REMOTE_TEMP_DIR}/report.html"
253253
;;
254254
("--syschar")
255255
TARGET_SYSCHAR=${oscap_args[j]}
256-
oscap_args[j]="$REMOTE_TEMP_DIR/syschar.xml"
256+
oscap_args[j]="${REMOTE_TEMP_DIR}/syschar.xml"
257257
;;
258258
("--oval-results")
259259
OVAL_RESULTS="yes"
@@ -266,70 +266,71 @@ done
266266
if [ "$1" != "--v" ] && [ "$1" != "--version" ] && [ "$1" != "-h" ] && [ "$1" != "--help" ]; then
267267
# Last argument should be the content path
268268
LOCAL_CONTENT_PATH="${oscap_args[-1]}"
269-
oscap_args[-1]="$REMOTE_TEMP_DIR/input.xml"
269+
oscap_args[-1]="${REMOTE_TEMP_DIR}/input.xml"
270270
fi
271271

272-
[ "$LOCAL_CONTENT_PATH" == "" ] || [ -f "$LOCAL_CONTENT_PATH" ] || die "Expected the last argument to be an input file, '$LOCAL_CONTENT_PATH' isn't a valid file path or the file doesn't exist!"
273-
[ "$LOCAL_TAILORING_PATH" == "" ] || [ -f "$LOCAL_TAILORING_PATH" ] || die "Tailoring file path '$LOCAL_TAILORING_PATH' isn't a valid file path or the file doesn't exist!"
274-
[ "$LOCAL_LOCAL_FILES_PATH" == "" ] || [ -d "$LOCAL_LOCAL_FILES_PATH" ] || die "Directory '$LOCAL_LOCAL_FILES_PATH' isn't a valid directory path or the directory doesn't exist!"
275-
[ "$LOCAL_CPE_PATH" == "" ] || [ -f "$LOCAL_CPE_PATH" ] || die "CPE file path '$LOCAL_CPE_PATH' isn't a valid file path or the file doesn't exist!"
276-
[ "$LOCAL_VARIABLES_PATH" == "" ] || [ -f "$LOCAL_VARIABLES_PATH" ] || die "OVAL variables file path '$LOCAL_VARIABLES_PATH' isn't a valid file path or the file doesn't exist!"
277-
[ "$LOCAL_DIRECTIVES_PATH" == "" ] || [ -f "$LOCAL_DIRECTIVES_PATH" ] || die "OVAL directives file path '$LOCAL_DIRECTIVES_PATH' isn't a valid file path or the file doesn't exist!"
272+
[ "${LOCAL_CONTENT_PATH}" == "" ] || [ -f "${LOCAL_CONTENT_PATH}" ] || die "Expected the last argument to be an input file, '${LOCAL_CONTENT_PATH}' isn't a valid file path or the file doesn't exist!"
273+
[ "${LOCAL_TAILORING_PATH}" == "" ] || [ -f "${LOCAL_TAILORING_PATH}" ] || die "Tailoring file path '${LOCAL_TAILORING_PATH}' isn't a valid file path or the file doesn't exist!"
274+
[ "${LOCAL_LOCAL_FILES_PATH}" == "" ] || [ -d "${LOCAL_LOCAL_FILES_PATH}" ] || die "Directory '${LOCAL_LOCAL_FILES_PATH}' isn't a valid directory path or the directory doesn't exist!"
275+
[ "${LOCAL_CPE_PATH}" == "" ] || [ -f "${LOCAL_CPE_PATH}" ] || die "CPE file path '${LOCAL_CPE_PATH}' isn't a valid file path or the file doesn't exist!"
276+
[ "${LOCAL_VARIABLES_PATH}" == "" ] || [ -f "${LOCAL_VARIABLES_PATH}" ] || die "OVAL variables file path '${LOCAL_VARIABLES_PATH}' isn't a valid file path or the file doesn't exist!"
277+
[ "${LOCAL_DIRECTIVES_PATH}" == "" ] || [ -f "${LOCAL_DIRECTIVES_PATH}" ] || die "OVAL directives file path '${LOCAL_DIRECTIVES_PATH}' isn't a valid file path or the file doesn't exist!"
278278

279-
if [ "$LOCAL_CONTENT_PATH" != "" ]; then
280-
echo "Copying input file '$LOCAL_CONTENT_PATH' to remote working directory '$REMOTE_TEMP_DIR'..."
281-
scp_copy_to_temp_dir "$LOCAL_CONTENT_PATH" input.xml || die "Failed to copy input file to remote temporary directory!"
279+
if [ "${LOCAL_CONTENT_PATH}" != "" ]; then
280+
echo "Copying input file '${LOCAL_CONTENT_PATH}' to remote working directory '${REMOTE_TEMP_DIR}'..."
281+
scp_copy_to_temp_dir "${LOCAL_CONTENT_PATH}" input.xml || die "Failed to copy input file to remote temporary directory!"
282282
fi
283-
if [ "$LOCAL_TAILORING_PATH" != "" ]; then
284-
echo "Copying tailoring file '$LOCAL_TAILORING_PATH' to remote working directory '$REMOTE_TEMP_DIR'..."
285-
scp_copy_to_temp_dir "$LOCAL_TAILORING_PATH" tailoring.xml || die "Failed to copy tailoring file to remote temporary directory!"
283+
if [ "${LOCAL_TAILORING_PATH}" != "" ]; then
284+
echo "Copying tailoring file '${LOCAL_TAILORING_PATH}' to remote working directory '${REMOTE_TEMP_DIR}'..."
285+
scp_copy_to_temp_dir "${LOCAL_TAILORING_PATH}" tailoring.xml || die "Failed to copy tailoring file to remote temporary directory!"
286286
fi
287-
if [ "$LOCAL_LOCAL_FILES_PATH" != "" ]; then
288-
echo "Copying directory '$LOCAL_LOCAL_FILES_PATH' to remote working directory '$REMOTE_TEMP_DIR'..."
289-
scp_copy_dir_to_temp_dir "$LOCAL_LOCAL_FILES_PATH" local_files || die "Failed to copy directory $LOCAL_LOCAL_FILES_PATH to remote temporary directory!"
287+
if [ "${LOCAL_LOCAL_FILES_PATH}" != "" ]; then
288+
echo "Copying directory '${LOCAL_LOCAL_FILES_PATH}' to remote working directory '${REMOTE_TEMP_DIR}'..."
289+
scp_copy_dir_to_temp_dir "${LOCAL_LOCAL_FILES_PATH}" local_files || die "Failed to copy directory ${LOCAL_LOCAL_FILES_PATH} to remote temporary directory!"
290290
fi
291-
if [ "$LOCAL_CPE_PATH" != "" ]; then
292-
echo "Copying CPE file '$LOCAL_CPE_PATH' to remote working directory '$REMOTE_TEMP_DIR'..."
293-
scp_copy_to_temp_dir "$LOCAL_CPE_PATH" cpe.xml || die "Failed to copy CPE file to remote temporary directory!"
291+
if [ "${LOCAL_CPE_PATH}" != "" ]; then
292+
echo "Copying CPE file '${LOCAL_CPE_PATH}' to remote working directory '${REMOTE_TEMP_DIR}'..."
293+
scp_copy_to_temp_dir "${LOCAL_CPE_PATH}" cpe.xml || die "Failed to copy CPE file to remote temporary directory!"
294294
fi
295-
if [ "$LOCAL_VARIABLES_PATH" != "" ]; then
296-
echo "Copying OVAL variables file '$LOCAL_VARIABLES_PATH' to remote working directory '$REMOTE_TEMP_DIR'..."
297-
scp_copy_to_temp_dir "$LOCAL_VARIABLES_PATH" variables.xml || die "Failed to copy OVAL variables file to remote temporary directory!"
295+
if [ "${LOCAL_VARIABLES_PATH}" != "" ]; then
296+
echo "Copying OVAL variables file '${LOCAL_VARIABLES_PATH}' to remote working directory '${REMOTE_TEMP_DIR}'..."
297+
scp_copy_to_temp_dir "${LOCAL_VARIABLES_PATH}" variables.xml || die "Failed to copy OVAL variables file to remote temporary directory!"
298298
fi
299-
if [ "$LOCAL_DIRECTIVES_PATH" != "" ]; then
300-
echo "Copying OVAL directives file '$LOCAL_DIRECTIVES_PATH' to remote working directory '$REMOTE_TEMP_DIR'..."
301-
scp_copy_to_temp_dir "$LOCAL_DIRECTIVES_PATH" directives.xml || die "Failed to copy OVAL directives file to remote temporary directory!"
299+
if [ "${LOCAL_DIRECTIVES_PATH}" != "" ]; then
300+
echo "Copying OVAL directives file '${LOCAL_DIRECTIVES_PATH}' to remote working directory '${REMOTE_TEMP_DIR}'..."
301+
scp_copy_to_temp_dir "${LOCAL_DIRECTIVES_PATH}" directives.xml || die "Failed to copy OVAL directives file to remote temporary directory!"
302302
fi
303303

304304
echo "Starting the evaluation..."
305305
# changing directory because of --oval-results support. oval results files are
306306
# dumped into PWD, and we can't be sure by the file names - we need controlled
307307
# environment
308-
ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR || exit 1; umask 022; $(command_array_to_string "${OSCAP_SUDO[@]}" scap "${oscap_args[@]}")" "$SSH_TTY_ALLOCATION_OPTION"
308+
full_command="$(command_array_to_string "${OSCAP_SUDO[@]}" scap "${oscap_args[@]}")"
309+
ssh_execute_with_command_and_options "cd ${REMOTE_TEMP_DIR} || exit 1; umask 022; ${full_command}" "${SSH_TTY_ALLOCATION_OPTION}"
309310
OSCAP_EXIT_CODE=$?
310-
echo "oscap exit code: $OSCAP_EXIT_CODE"
311+
echo "oscap exit code: ${OSCAP_EXIT_CODE}"
311312

312313
echo "Copying back requested files..."
313-
if [ "$TARGET_RESULTS" != "" ]; then
314-
scp_retreive_from_temp_dir results.xml "$TARGET_RESULTS" || die "Failed to copy the results file back to local machine!"
314+
if [ "${TARGET_RESULTS}" != "" ]; then
315+
scp_retreive_from_temp_dir results.xml "${TARGET_RESULTS}" || die "Failed to copy the results file back to local machine!"
315316
fi
316-
if [ "$TARGET_RESULTS_ARF" != "" ]; then
317-
scp_retreive_from_temp_dir results-arf.xml "$TARGET_RESULTS_ARF" || die "Failed to copy the ARF file back to local machine!"
317+
if [ "${TARGET_RESULTS_ARF}" != "" ]; then
318+
scp_retreive_from_temp_dir results-arf.xml "${TARGET_RESULTS_ARF}" || die "Failed to copy the ARF file back to local machine!"
318319
fi
319-
if [ "$TARGET_REPORT" != "" ]; then
320-
scp_retreive_from_temp_dir report.html "$TARGET_REPORT" || die "Failed to copy the HTML report back to local machine!"
320+
if [ "${TARGET_REPORT}" != "" ]; then
321+
scp_retreive_from_temp_dir report.html "${TARGET_REPORT}" || die "Failed to copy the HTML report back to local machine!"
321322
fi
322-
if [ "$TARGET_SYSCHAR" != "" ]; then
323-
scp_retreive_from_temp_dir syschar.xml "$TARGET_SYSCHAR" || die "Failed to copy the OVAL syschar file back to local machine!"
323+
if [ "${TARGET_SYSCHAR}" != "" ]; then
324+
scp_retreive_from_temp_dir syschar.xml "${TARGET_SYSCHAR}" || die "Failed to copy the OVAL syschar file back to local machine!"
324325
fi
325-
if [ "$OVAL_RESULTS" == "yes" ]; then
326+
if [ "${OVAL_RESULTS}" == "yes" ]; then
326327
scp_retreive_from_temp_dir '*.result.xml' "./" || die "Failed to copy OVAL result files back to local machine!"
327328
fi
328329

329330
echo "Removing remote temporary directory..."
330-
ssh_execute_with_command_and_options "rm -r $REMOTE_TEMP_DIR" || die "Failed to remove remote temporary directory!"
331+
ssh_execute_with_command_and_options "rm -r ${REMOTE_TEMP_DIR}" || die "Failed to remove remote temporary directory!"
331332
echo "Disconnecting ssh and removing control ssh socket directory..."
332333
ssh_execute_with_options -O exit || die "Failed to disconnect!"
333-
rm -r "$CONTROL_SOCKET_DIR" || die "Failed to remove local control SSH socket directory!"
334+
rm -r "${CONTROL_SOCKET_DIR}" || die "Failed to remove local control SSH socket directory!"
334335

335-
exit $OSCAP_EXIT_CODE
336+
exit "${OSCAP_EXIT_CODE}"

0 commit comments

Comments
 (0)