Skip to content

Commit df3bbe9

Browse files
committed
fix: apply fixes according to shellcheck
1 parent 25f363b commit df3bbe9

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

LFC/LFC.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ create_file_if_output_not_empty() {
223223
write_log() {
224224
# Writes a log message to a log file.
225225
local message="$1"
226-
local timestamp=$(date +"%Y-%m-%d %H:%M:%S")
226+
local timestamp
227+
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
227228
echo "[$timestamp] - $message" >> "$LOGFILE"
228229
}
229230

@@ -247,7 +248,7 @@ check_if_value_in_blacklist() {
247248
copy_configuration_files() {
248249
# Copy configuration files from a list of configuration files.
249250
for file in "${SYSTEM_FILES[@]}"; do
250-
if [ -f "$file" -a -s "$file" ]; then
251+
if [ -f "$file" ] && [ -s "$file" ]; then
251252
# Get the directory path of the file
252253
dir_path=$(dirname "$file")
253254

@@ -290,7 +291,7 @@ copy_configuration_files() {
290291

291292
copy_user_configuration_files() {
292293
# Copy user configuration files while maintaining directory structure
293-
while IFS=: read -r user _ _ _ _ home _; do
294+
while IFS=: read -r _ _ _ _ _ home _; do
294295
if [ -d "$home" ]; then
295296

296297
# Loops through list of user config files
@@ -315,7 +316,8 @@ copy_important_logs() {
315316
if [ -d "$file" ]; then
316317

317318
# If it's a directory, copy its contents to the target directory.
318-
local target_dir="$OUTPUT_DIR$file"
319+
local target_dir
320+
target_dir="$OUTPUT_DIR$file"
319321
if [ ! -d "$target_dir" ]; then
320322
mkdir -p "$target_dir"
321323
fi
@@ -335,7 +337,9 @@ copy_important_logs() {
335337

336338
traverse_procfs() {
337339
# Traverse /proc and copy files from each process directory
338-
for pid in $(ls /proc | grep -E '^[0-9]+$'); do
340+
for pid_dir in /proc/[0-9]*; do
341+
if [ -d "$pid_dir" ]; then # Ensure it's a directory
342+
pid=$(basename "$pid_dir")
339343
process_dir="/proc/$pid"
340344

341345
# Create corresponding process directory in the destination directory
@@ -373,6 +377,7 @@ traverse_procfs() {
373377
#cp -LR "$artifact_path" "$OUTPUT_DIR$artifact_path"
374378
fi
375379
done
380+
fi
376381
done
377382

378383
# Iterate over the important files and copy them while maintaining directory structure
@@ -486,9 +491,11 @@ generate_bodyfile() {
486491
local bodyfile_path="$FILE_ANALYSIS_DIR/bodyfile.txt"
487492

488493
# Add header comment to bodyfile
489-
echo "# Bodyfile generated on $(date)" > "$bodyfile_path"
490-
echo "# Format: MD5|name|inode|mode_as_string|UID|GID|size|atime|mtime|ctime|crtime" >> "$bodyfile_path"
491-
echo "# Times are in Unix epoch format" >> "$bodyfile_path"
494+
{
495+
echo "# Bodyfile generated on $(date)"
496+
echo "# Format: MD5|name|inode|mode_as_string|UID|GID|size|atime|mtime|ctime|crtime"
497+
echo "# Times are in Unix epoch format"
498+
} >> "$bodyfile_path"
492499

493500
# Generate bodyfile using find with stat information
494501
# Exclude /proc, /sys, and other virtual filesystems to avoid errors and reduce noise

0 commit comments

Comments
 (0)