Gopichand Paturi | 24226c4 | 2024-05-16 14:51:22 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Gopichand Paturi | ac291d4 | 2025-03-25 14:11:00 -0500 | [diff] [blame^] | 3 | #CONSTANTS |
| 4 | declare -rx HEADER_EXTENSION="$DREPORT_INCLUDE/gendumpheader" |
| 5 | |
Gopichand Paturi | 24226c4 | 2024-05-16 14:51:22 -0500 | [diff] [blame] | 6 | # @brief Packaging the dump, applying the header |
| 7 | # and transferring to dump location. |
| 8 | function custom_package() |
| 9 | { |
Gopichand Paturi | ac291d4 | 2025-03-25 14:11:00 -0500 | [diff] [blame^] | 10 | 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 Paturi | 24226c4 | 2024-05-16 14:51:22 -0500 | [diff] [blame] | 19 | # 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 Paturi | ac291d4 | 2025-03-25 14:11:00 -0500 | [diff] [blame^] | 29 | cat "$name_dir.bin" | tee -a "$FILE" > /dev/null |
Gopichand Paturi | 24226c4 | 2024-05-16 14:51:22 -0500 | [diff] [blame] | 30 | #remove the temporary name specific directory |
Gopichand Paturi | ac291d4 | 2025-03-25 14:11:00 -0500 | [diff] [blame^] | 31 | rm -rf "$name_dir" "$name_dir.bin" |
| 32 | mv $FILE "$name_dir" |
Gopichand Paturi | 24226c4 | 2024-05-16 14:51:22 -0500 | [diff] [blame] | 33 | |
| 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 Paturi | ac291d4 | 2025-03-25 14:11:00 -0500 | [diff] [blame^] | 43 | rm "$name_dir" |
Gopichand Paturi | 24226c4 | 2024-05-16 14:51:22 -0500 | [diff] [blame] | 44 | return "$INTERNAL_FAILURE" |
| 45 | fi |
| 46 | |
| 47 | #Remove the temporary copy of the file |
Gopichand Paturi | ac291d4 | 2025-03-25 14:11:00 -0500 | [diff] [blame^] | 48 | rm -rf "$name_dir" |
Gopichand Paturi | 24226c4 | 2024-05-16 14:51:22 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | # Executing function |
| 52 | custom_package |