blob: 7e85110e67f815cf97bba7d5449409e72cbf6007 [file] [log] [blame]
Gopichand Paturi24226c42024-05-16 14:51:22 -05001#!/bin/bash
2
Gopichand Paturiac291d42025-03-25 14:11:00 -05003#CONSTANTS
4declare -rx HEADER_EXTENSION="$DREPORT_INCLUDE/gendumpheader"
5
Gopichand Paturi24226c42024-05-16 14:51:22 -05006# @brief Packaging the dump, applying the header
7# and transferring to dump location.
8function custom_package()
9{
Gopichand Paturiac291d42025-03-25 14:11:00 -050010 FILE="/tmp/dumpheader_${dump_id}_${EPOCHTIME}"
11 echo "performing dump compression $name_dir"
12 if [ "$dump_type" = "$TYPE_FAULTDATA" ]; then
13 rm -rf $name_dir/dreport.log
14 rm -rf $name_dir/summary.log
15 tar -cf "$name_dir.bin" -C "$(dirname "$name_dir")" "$(basename "$name_dir")"
16 else
17 tar cf - -C "$(dirname "$name_dir")" "$(basename "$name_dir")" | zstd > "$name_dir.bin"
18 fi
Gopichand Paturi24226c42024-05-16 14:51:22 -050019 # shellcheck disable=SC2181 # need output from `tar` in above if cond.
20 if [ $? -ne 0 ]; then
21 echo "$($TIME_STAMP)" "Could not create the compressed tar file"
22 rm -r "$name_dir.bin"
23 return "$INTERNAL_FAILURE"
24 fi
25
26 echo "Adding Dump Header :"$HEADER_EXTENSION
27 ("$HEADER_EXTENSION")
28
Gopichand Paturiac291d42025-03-25 14:11:00 -050029 cat "$name_dir.bin" | tee -a "$FILE" > /dev/null
Gopichand Paturi24226c42024-05-16 14:51:22 -050030 #remove the temporary name specific directory
Gopichand Paturiac291d42025-03-25 14:11:00 -050031 rm -rf "$name_dir" "$name_dir.bin"
32 mv $FILE "$name_dir"
Gopichand Paturi24226c42024-05-16 14:51:22 -050033
34 echo "$($TIME_STAMP)" "Report is available in $dump_dir"
35 if [ "$TMP_DIR" == "$dump_dir" ] || [ "$TMP_DIR/" == "$dump_dir" ]; then
36 return "$SUCCESS"
37 fi
38
39 #copy the compressed tar file into the destination
40 cp "$name_dir" "$dump_dir"
41 if [ $? -ne 0 ]; then
42 echo "Failed to copy the $name_dir to $dump_dir"
Gopichand Paturiac291d42025-03-25 14:11:00 -050043 rm "$name_dir"
Gopichand Paturi24226c42024-05-16 14:51:22 -050044 return "$INTERNAL_FAILURE"
45 fi
46
47 #Remove the temporary copy of the file
Gopichand Paturiac291d42025-03-25 14:11:00 -050048 rm -rf "$name_dir"
Gopichand Paturi24226c42024-05-16 14:51:22 -050049}
50
51# Executing function
52custom_package