ramoops: avoid deleting root
Add checking that the optional_path is provided so that root
cannot be deleted. Also, fix all the shellcheck errors and
reformat with beautysh.
Fixes openbmc/phosphor-debug-collector#24.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I1fd4d0693443e54045b29efb3b92da770eb2933a
diff --git a/.shellcheck-ignore b/.shellcheck-ignore
index 5a6e350..004cf65 100644
--- a/.shellcheck-ignore
+++ b/.shellcheck-ignore
@@ -29,7 +29,6 @@
tools/dreport.d/plugins.d/obmcconsole
tools/dreport.d/plugins.d/osrelease
tools/dreport.d/plugins.d/pldmflightrecorder
-tools/dreport.d/plugins.d/ramoops
tools/dreport.d/plugins.d/timedate
tools/dreport.d/plugins.d/top
tools/dreport.d/plugins.d/uptime
diff --git a/tools/dreport.d/plugins.d/ramoops b/tools/dreport.d/plugins.d/ramoops
index 66324f0..7506202 100644
--- a/tools/dreport.d/plugins.d/ramoops
+++ b/tools/dreport.d/plugins.d/ramoops
@@ -4,16 +4,19 @@
# @brief: Move the ramoops data file to the dreport packaging.
#
-. $DREPORT_INCLUDE/functions
+# shellcheck source=tools/dreport.d/include.d/functions
+. "$DREPORT_INCLUDE/functions"
desc="Ramoops file"
-for path in ${optional_path}/*
-do
- if [ -f $path ]; then
- # Remove the file from path after successful copy
- if add_copy_file "$path" "$desc"; then
- rm "$path"
+if [ -n "${optional_path}" ]; then
+ for path in "${optional_path}"/*
+ do
+ if [ -f "$path" ]; then
+ # Remove the file from path after successful copy
+ if add_copy_file "$path" "$desc"; then
+ rm "$path"
+ fi
fi
- fi
-done
+ done
+fi